xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/dynsym-valid-refs.test (revision 68616584c3a5ce9352b37d24e408b171928f6840)
1*68616584SIgor Kudrin# RUN: yaml2obj %s -o %t
2*68616584SIgor Kudrin# RUN: llvm-objcopy %t %t2
3*68616584SIgor Kudrin# RUN: llvm-readobj --dyn-syms %t2 | FileCheck %s
4*68616584SIgor Kudrin
5*68616584SIgor Kudrin## This checks that section references in the dynamic symbol table are not
6*68616584SIgor Kudrin## corrupted after processing a file where the sequence of section headers does
7*68616584SIgor Kudrin## not follow the order of their offsets. The tool avoids updating loadable
8*68616584SIgor Kudrin## sections, so, the content of the dynamic symbol table stays intact and the
9*68616584SIgor Kudrin## used section indices are preserved. In this test, the section 'dummy' comes
10*68616584SIgor Kudrin## first while having the offset after all other sections. If the section
11*68616584SIgor Kudrin## headers were sorted by their offsets by the tool, what it did before, the
12*68616584SIgor Kudrin## index of the '.text' section would change from '2' to '1', which resulted
13*68616584SIgor Kudrin## in an incorrect reference in the corresponding dynamic symbol 'foo'.
14*68616584SIgor Kudrin
15*68616584SIgor Kudrin# CHECK:      Name: foo
16*68616584SIgor Kudrin# CHECK-NEXT: Value:
17*68616584SIgor Kudrin# CHECK-NEXT: Size:
18*68616584SIgor Kudrin# CHECK-NEXT: Binding:
19*68616584SIgor Kudrin# CHECK-NEXT: Type:
20*68616584SIgor Kudrin# CHECK-NEXT: Other:
21*68616584SIgor Kudrin# CHECK-NEXT: Section: .text
22*68616584SIgor Kudrin
23*68616584SIgor Kudrin!ELF
24*68616584SIgor KudrinFileHeader:
25*68616584SIgor Kudrin  Class:           ELFCLASS64
26*68616584SIgor Kudrin  Data:            ELFDATA2LSB
27*68616584SIgor Kudrin  Type:            ET_DYN
28*68616584SIgor Kudrin  Machine:         EM_X86_64
29*68616584SIgor KudrinProgramHeaders:
30*68616584SIgor Kudrin  - Type:            PT_LOAD
31*68616584SIgor Kudrin    Flags:           [ PF_X, PF_R ]
32*68616584SIgor Kudrin    FirstSec:        .text
33*68616584SIgor Kudrin    LastSec:         .text
34*68616584SIgor Kudrin    Align:           0x1000
35*68616584SIgor KudrinSections:
36*68616584SIgor Kudrin  - Name:            .text
37*68616584SIgor Kudrin    Type:            SHT_PROGBITS
38*68616584SIgor Kudrin    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
39*68616584SIgor Kudrin    AddressAlign:    0x4
40*68616584SIgor Kudrin    Offset:          0x1000
41*68616584SIgor Kudrin    Content:         0000000000000000
42*68616584SIgor Kudrin  - Name:            .dynsym
43*68616584SIgor Kudrin    Type:            SHT_DYNSYM
44*68616584SIgor Kudrin    Flags:           [ SHF_ALLOC ]
45*68616584SIgor Kudrin    Link:            .dynstr
46*68616584SIgor Kudrin  - Name:            .dynstr
47*68616584SIgor Kudrin    Type:            SHT_STRTAB
48*68616584SIgor Kudrin    Flags:           [ SHF_ALLOC ]
49*68616584SIgor Kudrin  - Name:            dummy
50*68616584SIgor Kudrin    Type:            SHT_PROGBITS
51*68616584SIgor Kudrin    Flags:           [ SHF_ALLOC ]
52*68616584SIgor Kudrin    Offset:          0x1100
53*68616584SIgor Kudrin  - Type:            SectionHeaderTable
54*68616584SIgor Kudrin    Sections:
55*68616584SIgor Kudrin## 'dummy' comes before '.text' in the section header table despite its offset
56*68616584SIgor Kudrin## is larger.
57*68616584SIgor Kudrin      - Name:            dummy
58*68616584SIgor Kudrin      - Name:            .text
59*68616584SIgor Kudrin      - Name:            .dynsym
60*68616584SIgor Kudrin      - Name:            .dynstr
61*68616584SIgor Kudrin      - Name:            .shstrtab
62*68616584SIgor Kudrin      - Name:            .strtab
63*68616584SIgor KudrinDynamicSymbols:
64*68616584SIgor Kudrin  - Name:            foo
65*68616584SIgor Kudrin    Type:            STT_FUNC
66*68616584SIgor Kudrin    Section:         .text
67*68616584SIgor Kudrin    Binding:         STB_GLOBAL
68*68616584SIgor Kudrin    Value:           0x0
69*68616584SIgor Kudrin    Size:            0x8
70