Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objcopy] [COFF] Implement --only-keep-debug
Differential Revision: https://reviews.llvm.org/D56840 llvm-svn: 351662
- Loading branch information
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
llvm/test/tools/llvm-objcopy/COFF/Inputs/only-keep-sections.yaml
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,77 @@ | ||
--- !COFF | ||
OptionalHeader: | ||
AddressOfEntryPoint: 4144 | ||
ImageBase: 1073741824 | ||
SectionAlignment: 4096 | ||
FileAlignment: 512 | ||
MajorOperatingSystemVersion: 6 | ||
MinorOperatingSystemVersion: 0 | ||
MajorImageVersion: 0 | ||
MinorImageVersion: 0 | ||
MajorSubsystemVersion: 6 | ||
MinorSubsystemVersion: 0 | ||
Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI | ||
DLLCharacteristics: [ ] | ||
SizeOfStackReserve: 1048576 | ||
SizeOfStackCommit: 4096 | ||
SizeOfHeapReserve: 1048576 | ||
SizeOfHeapCommit: 4096 | ||
header: | ||
Machine: IMAGE_FILE_MACHINE_AMD64 | ||
Characteristics: [ ] | ||
sections: | ||
- Name: .text | ||
Characteristics: [ IMAGE_SCN_CNT_CODE ] | ||
VirtualAddress: 4096 | ||
VirtualSize: 4 | ||
SectionData: C3C3C3C3 | ||
- Name: .rdata | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA ] | ||
VirtualAddress: 8192 | ||
VirtualSize: 4 | ||
SectionData: 2A000000 | ||
- Name: .buildid | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA ] | ||
VirtualAddress: 12288 | ||
VirtualSize: 4 | ||
SectionData: 2B000000 | ||
- Name: .reloc | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE ] | ||
VirtualAddress: 16384 | ||
VirtualSize: 4 | ||
SectionData: 2C000000 | ||
- Name: .debug_discardable | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE ] | ||
VirtualAddress: 20480 | ||
VirtualSize: 4 | ||
SectionData: 2D000000 | ||
- Name: .debug_undiscardable | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA ] | ||
VirtualAddress: 24576 | ||
VirtualSize: 4 | ||
SectionData: 2E000000 | ||
- Name: .unflagged | ||
Characteristics: [ ] | ||
VirtualAddress: 28672 | ||
VirtualSize: 4 | ||
SectionData: 2F000000 | ||
symbols: | ||
- Name: main | ||
Value: 2 | ||
SectionNumber: 1 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
- Name: debug_discardable_sym | ||
Value: 0 | ||
SectionNumber: 5 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
- Name: debug_undiscardable_sym | ||
Value: 0 | ||
SectionNumber: 6 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
... |
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,58 @@ | ||
RUN: yaml2obj %p/Inputs/only-keep-sections.yaml > %t.in.exe | ||
|
||
RUN: llvm-objcopy --only-keep-debug %t.in.exe %t.out.exe | ||
RUN: llvm-readobj --sections %t.out.exe | FileCheck %s --check-prefix=SECTIONS | ||
RUN: llvm-objdump -t %t.out.exe | FileCheck %s --check-prefix=SYMBOLS | ||
|
||
Check that all non-debug/buildid sections with IMAGE_SCN_CNT_CODE | ||
or IMAGE_SCN_CNT_INITIALIZED_DATA are truncated, and no others. | ||
|
||
SECTIONS: Sections [ | ||
SECTIONS-NEXT: Section { | ||
SECTIONS-NEXT: Number: 1 | ||
SECTIONS-NEXT: Name: .text | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 0 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 2 | ||
SECTIONS-NEXT: Name: .rdata | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 0 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 3 | ||
SECTIONS-NEXT: Name: .buildid | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 512 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 4 | ||
SECTIONS-NEXT: Name: .reloc | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 0 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 5 | ||
SECTIONS-NEXT: Name: .debug_discardable | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 512 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 6 | ||
SECTIONS-NEXT: Name: .debug_undiscardable | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 512 | ||
SECTIONS: Section { | ||
SECTIONS-NEXT: Number: 7 | ||
SECTIONS-NEXT: Name: .unflagged | ||
SECTIONS-NEXT: VirtualSize: 0x4 | ||
SECTIONS-NEXT: VirtualAddress: | ||
SECTIONS-NEXT: RawDataSize: 512 | ||
|
||
SYMBOLS: SYMBOL TABLE: | ||
SYMBOLS-NEXT: main | ||
SYMBOLS-NEXT: debug_discardable_sym | ||
SYMBOLS-NEXT: debug_undiscardable_sym | ||
SYMBOLS-EMPTY: |
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
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