As for now, llvm-objcopy sorts section headers according to the offsets of the sections in the input file. That can corrupt section references in the dynamic symbol table because it is a loadable section and as such is not updated by the tool. Even though the section references are not required for loading the binary correctly, they are still handy for a user who analyzes the file. While the patch removes global reordering of section headers, it layouts the sections in the same way as before, i.e. according to their original offsets. All that helps the output file to resemble the input better. Note that the patch removes sorting SHT_GROUP sections to the start of the list, which was introduced in D62620 in order to ensure that they come before the group members, along with the corresponding test. The original issue was caused by the sorting of section headers, so dropping the sorting also resolves the issue. Differential Revision: https://reviews.llvm.org/D107653
70 lines
2.3 KiB
Plaintext
70 lines
2.3 KiB
Plaintext
# 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
|