Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objcopy]Allow llvm-objcopy to be used on an ELF file with no se…
…ction headers This patch fixes https://bugs.llvm.org/show_bug.cgi?id=41293 and https://bugs.llvm.org/show_bug.cgi?id=41045. llvm-objcopy assumed that it could always read a section header string table. This isn't the case when the sections were previously all stripped, and the e_shstrndx field was set to 0. This patch fixes this. It also fixes a double space in an error message relating to this issue, and prevents llvm-objcopy from adding extra space for non-existent section headers, meaning that --strip-sections on the output of a previous --strip-sections run produces identical output, simplifying the test. Reviewed by: rupprecht, grimar Differential Revision: https://reviews.llvm.org/D59989 llvm-svn: 357475
- Loading branch information
Showing
3 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
llvm/test/tools/llvm-objcopy/ELF/copy-after-strip-sections.test
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,26 @@ | ||
# llvm-objcopy's --strip-sections removes the section headers. It should be | ||
# possible to run the tool on the output after this operation. Performing any | ||
# subsequent stripping operation, or copying the object, should produce | ||
# identical output. | ||
|
||
# RUN: yaml2obj %s -o %t.in | ||
# RUN: llvm-objcopy %t.in %t.stripped --strip-sections | ||
# RUN: llvm-objcopy %t.stripped %t.stripped2 --strip-sections | ||
# RUN: llvm-objcopy %t.stripped2 %t.out | ||
# RUN: cmp %t.stripped %t.stripped2 | ||
# RUN: cmp %t.stripped %t.out | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Content: 'facefeed' | ||
ProgramHeaders: | ||
- Type: PT_LOAD | ||
Sections: | ||
- Section: .text |
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
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