forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
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 --only-keep/-j and --keep
This change adds support for the --only-keep option and the -j alias as well. A common use case for these being used together is to dump a specific section's data. Additionally the --keep option is added (GNU objcopy doesn't have this) to avoid removing a bunch of things. This allows people to err on the side of stripping aggressively and then to keep the specific bits that they need for their application. Differential Revision: https://reviews.llvm.org/D39021 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319467 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
0ba92ff
commit fad0b06
Showing
14 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
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,19 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -strip-non-alloc -keep=.test %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 3 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .shstrtab |
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,23 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -only-keep=.test %t %t2 | ||
# RUN: llvm-objcopy -j=.test %t %t3 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
# RUN: diff %t2 %t3 | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 5 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .symtab | ||
# CHECK: Name: .strtab | ||
# CHECK: Name: .shstrtab |
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,28 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -O binary -j .text %t %t2 | ||
# RUN: llvm-objcopy -O binary -only-keep .text %t %t3 | ||
# RUN: od -t x1 %t2 | FileCheck %s | ||
# RUN: wc -c %t2 | FileCheck %s --check-prefix=SIZE | ||
# RUN: diff %t2 %t3 | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
AddressAlign: 0x0000000000001000 | ||
Content: "DEADBEEF" | ||
ProgramHeaders: | ||
- Type: PT_LOAD | ||
Flags: [ PF_X, PF_R ] | ||
Sections: | ||
- Section: .text | ||
|
||
#CHECK: 0000000 de ad be ef | ||
|
||
#SIZE: 4 |
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,21 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -R=.test -keep=.test %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 5 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .symtab | ||
# CHECK: Name: .strtab | ||
# CHECK: Name: .shstrtab |
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,21 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -R=.test -only-keep=.test %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 5 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .symtab | ||
# CHECK: Name: .strtab | ||
# CHECK: Name: .shstrtab |
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,27 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -strip-non-alloc -keep=.test -keep=.test3 %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
- Name: .test2 | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
- Name: .test3 | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
|
||
# CHECK: SectionHeaderCount: 4 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .test3 | ||
# CHECK: Name: .shstrtab |
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,27 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -keep=.test2 -only-keep=.test %t %t2 | ||
# RUN: llvm-objcopy -j=.test -keep=.test2 %t %t3 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
# RUN: diff %t2 %t3 | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
- Name: .test2 | ||
Type: SHT_PROGBITS | ||
- Name: .test3 | ||
Type: SHT_PROGBITS | ||
|
||
# CHECK: SectionHeaderCount: 6 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .test2 | ||
# CHECK: Name: .symtab | ||
# CHECK: Name: .strtab | ||
# CHECK: Name: .shstrtab |
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,28 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -j .test1 -j .test2 %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test1 | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
- Name: .test2 | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
- Name: .test3 | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 6 | ||
|
||
# CHECK: Name: .test1 | ||
# CHECK: Name: .test2 | ||
# CHECK: Name: .symtab | ||
# CHECK: Name: .strtab | ||
# CHECK: Name: .shstrtab |
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,21 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -R .symtab -R .strtab -only-keep=.test %t %t2 | ||
# RUN: llvm-objcopy -j=.test -R .strtab -R .symtab %t %t3 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
# RUN: diff %t2 %t3 | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 3 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .shstrtab |
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,19 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -strip-non-alloc -only-keep=.test %t %t2 | ||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
|
||
# CHECK: SectionHeaderCount: 3 | ||
|
||
# CHECK: Name: .test | ||
# CHECK: Name: .shstrtab |
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,13 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -strip-sections -keep=.shstrtab %t %t2 | ||
# RUN: od -Ax -t c %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
|
||
# CHECK: \0 . s h s t r t a b \0 |
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,20 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy -strip-sections -only-keep=.test %t %t2 | ||
# RUN: od -Ax -t x1 %t2 | FileCheck %s | ||
# RUN: od -Ax -t c %t2 | FileCheck %s -check-prefix=TEXT | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .test | ||
Type: SHT_PROGBITS | ||
Flags: [ ] | ||
Content: "DEADBEEF" | ||
|
||
# CHECK: de ad be ef | ||
|
||
# TEXT-NOT: t e s t |
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