| # RUN: yaml2obj %s -o %t | |
| # RUN: llvm-objcopy %t %t2 | |
| # RUN: llvm-readobj --dyn-syms %t2 | FileCheck %s | |
| ## This checks that section references in the dynamic symbol table are not | |
| ## corrupted after processing a file where the sequence of section headers does | |
| ## not follow the order of their offsets. The tool avoids updating loadable | |
| ## sections, so, the content of the dynamic symbol table stays intact and the | |
| ## used section indices are preserved. In this test, the section 'dummy' comes | |
| ## first while having the offset after all other sections. If the section | |
| ## headers were sorted by their offsets by the tool, what it did before, the | |
| ## index of the '.text' section would change from '2' to '1', which resulted | |
| ## in an incorrect reference in the corresponding dynamic symbol 'foo'. | |
| # CHECK: Name: foo | |
| # CHECK-NEXT: Value: | |
| # CHECK-NEXT: Size: | |
| # CHECK-NEXT: Binding: | |
| # CHECK-NEXT: Type: | |
| # CHECK-NEXT: Other: | |
| # CHECK-NEXT: Section: .text | |
| !ELF | |
| FileHeader: | |
| Class: ELFCLASS64 | |
| Data: ELFDATA2LSB | |
| Type: ET_DYN | |
| Machine: EM_X86_64 | |
| ProgramHeaders: | |
| - Type: PT_LOAD | |
| Flags: [ PF_X, PF_R ] | |
| FirstSec: .text | |
| LastSec: .text | |
| Align: 0x1000 | |
| Sections: | |
| - Name: .text | |
| Type: SHT_PROGBITS | |
| Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | |
| AddressAlign: 0x4 | |
| Offset: 0x1000 | |
| Content: 0000000000000000 | |
| - Name: .dynsym | |
| Type: SHT_DYNSYM | |
| Flags: [ SHF_ALLOC ] | |
| Link: .dynstr | |
| - Name: .dynstr | |
| Type: SHT_STRTAB | |
| Flags: [ SHF_ALLOC ] | |
| - Name: dummy | |
| Type: SHT_PROGBITS | |
| Flags: [ SHF_ALLOC ] | |
| Offset: 0x1100 | |
| - Type: SectionHeaderTable | |
| Sections: | |
| ## 'dummy' comes before '.text' in the section header table despite its offset | |
| ## is larger. | |
| - Name: dummy | |
| - Name: .text | |
| - Name: .dynsym | |
| - Name: .dynstr | |
| - Name: .shstrtab | |
| - Name: .strtab | |
| DynamicSymbols: | |
| - Name: foo | |
| Type: STT_FUNC | |
| Section: .text | |
| Binding: STB_GLOBAL | |
| Value: 0x0 | |
| Size: 0x8 |