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