Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objcopy] Add support for large indexes
Because of -ffunction-sections (and maybe other use cases I'm not aware of?) it can occur that we need more than 0xfeff sections but ELF dosn't support that many sections. To solve this problem SHN_XINDEX exists and with it come a whole host of changes for section indexes everywhere. This change adds support for those cases which should allow llvm-objcopy to copy binaries that have an arbitrary number of sections. Differential Revision: https://reviews.llvm.org/D42516 llvm-svn: 326940
- Loading branch information
1 parent
80ec0c3
commit 0a151bd
Showing
7 changed files
with
289 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RUN: unzip -p %p/Inputs/many-sections.o.zip > %t | ||
RUN: llvm-objcopy -R=.text -R=s0 -R=s1 -R=s2 -R=s3 -R=s4 -R=s5 -R=s6 %t %t2 | ||
RUN: llvm-readobj -sections %t2 | FileCheck --check-prefix=SECS %s | ||
|
||
SECS-NOT: Name: .symtab_shndx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
RUN: unzip -p %p/Inputs/many-sections.o.zip > %t | ||
RUN: llvm-objcopy %t %t2 | ||
RUN: llvm-readobj -file-headers %t2 | FileCheck --check-prefix=EHDR %s | ||
RUN: llvm-readobj -sections %t2 | FileCheck --check-prefix=SECS %s | ||
RUN: llvm-readobj -symbols %t2 | grep "Symbol {" | wc -l | FileCheck --check-prefix=SYMS %s | ||
|
||
EHDR: Format: ELF64-x86-64 | ||
EHDR-NEXT: Arch: x86_64 | ||
EHDR-NEXT: AddressSize: 64bit | ||
EHDR-NEXT: LoadName: | ||
EHDR-NEXT: ElfHeader { | ||
EHDR-NEXT: Ident { | ||
EHDR-NEXT: Magic: (7F 45 4C 46) | ||
EHDR-NEXT: Class: 64-bit (0x2) | ||
EHDR-NEXT: DataEncoding: LittleEndian (0x1) | ||
EHDR-NEXT: FileVersion: 1 | ||
EHDR-NEXT: OS/ABI: SystemV (0x0) | ||
EHDR-NEXT: ABIVersion: 0 | ||
EHDR-NEXT: Unused: (00 00 00 00 00 00 00) | ||
EHDR-NEXT: } | ||
EHDR-NEXT: Type: Relocatable (0x1) | ||
EHDR-NEXT: Machine: EM_X86_64 (0x3E) | ||
EHDR-NEXT: Version: 1 | ||
EHDR-NEXT: Entry: 0x0 | ||
EHDR-NEXT: ProgramHeaderOffset: 0x40 | ||
EHDR-NEXT: SectionHeaderOffset: | ||
EHDR-NEXT: Flags [ (0x0) | ||
EHDR-NEXT: ] | ||
EHDR-NEXT: HeaderSize: 64 | ||
EHDR-NEXT: ProgramHeaderEntrySize: 56 | ||
EHDR-NEXT: ProgramHeaderCount: 0 | ||
EHDR-NEXT: SectionHeaderEntrySize: 64 | ||
EHDR-NEXT: SectionHeaderCount: 0 | ||
EHDR-NEXT: StringTableSectionIndex: 65535 | ||
EHDR-NEXT: } | ||
|
||
SECS: Index: 65285 | ||
SECS-NEXT: Name: .symtab | ||
SECS-NEXT: Type: SHT_SYMTAB | ||
SECS: Name: .symtab_shndx | ||
SECS-NEXT: Type: SHT_SYMTAB_SHNDX | ||
SECS-NEXT: Flags [ (0x0) | ||
SECS-NEXT: ] | ||
SECS-NEXT: Address: 0x0 | ||
SECS-NEXT: Offset: | ||
# There should be #syms * EntrySize bytes. | ||
SECS-NEXT: Size: 261136 | ||
SECS-NEXT: Link: 65285 | ||
SECS-NEXT: Info: | ||
SECS-NEXT: AddressAlignment: 4 | ||
SECS-NEXT: EntrySize: 4 | ||
SECS: Index: 65287 | ||
SYMS: 65284 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RUN: unzip -p %p/Inputs/many-sections.o.zip > %t | ||
RUN: llvm-objcopy -R=.symtab_shndxr %t %t2 | ||
RUN: llvm-readobj -sections %t2 | FileCheck %s | ||
|
||
CHECK: Name: .symtab_shndx ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This test makes sure that sections added at the end that don't have symbols | ||
# defined in them don't trigger the creation of a large index table. | ||
|
||
RUN: unzip -p %p/Inputs/many-sections.o.zip > %t.0 | ||
RUN: cat %p/Inputs/alloc-symtab.o > %t | ||
RUN: llvm-objcopy -R=.text -R=s0 -R=s1 -R=s2 -R=s3 -R=s4 -R=s5 -R=s6 %t.0 %t2 | ||
RUN: llvm-objcopy -add-section=.s0=%t -add-section=.s1=%t -add-section=.s2=%t %t2 %t2 | ||
RUN: llvm-readobj -sections %t2 | FileCheck --check-prefix=SECS %s | ||
|
||
SECS-NOT: Name: .symtab_shndx |
Oops, something went wrong.