-
Notifications
You must be signed in to change notification settings - Fork 15k
[llvm-objcopy][COFF] Update .symidx values after stripping #153322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+441
−0
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b302bd9
[objcopy][COFF] Update WinCFGuard section contents after stripping
e-kud 42350aa
ulittle32_t, skip for PE and continue instead of return
e-kud 8acb7f4
Format: forgotten ammend
e-kud 2264108
Iterate in more natural way
e-kud 874c9cc
Handle illegal symidx
e-kud 4e80fb8
Support .gehcont as well
e-kud 1a8f13c
Reduce some of the tests
e-kud 5f21fe5
More test coverage for incorrect symbols
e-kud cbb5832
Add description to the tests
e-kud 7b2e3b1
NeedUpdate should be set true if a symbol changed RawIndex
e-kud 4801398
Use iterators instead of double lookup
e-kud 2838c93
Fix comments and order of checks for a symbol
e-kud 73186e3
Make OriginalRawIndex a class member
e-kud ee60009
Same symbols indices doesn't mean sections are good
e-kud 4c0f90f
Update tests and comments
e-kud 71a638c
Format
e-kud 975184f
Check file name in errors and return lost checksum checks
e-kud f1fdc0f
Merge remote-tracking branch 'origin/main' into strip-winguards
e-kud 557fcbe
Reduce tests more
e-kud 5de611b
Merge remote-tracking branch 'origin/main' into strip-winguards
e-kud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
201 changes: 201 additions & 0 deletions
201
llvm/test/tools/llvm-objcopy/COFF/strip-update-ehcont.test
This file contains hidden or 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,201 @@ | ||
| # RUN: yaml2obj %s -o %t.in.o | ||
e-kud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # RUN: llvm-readobj -r -s -x '.gehcont$y' %t.in.o | FileCheck %s --check-prefix=ORIG | ||
e-kud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # RUN: llvm-objcopy --strip-debug %t.in.o %t.out.o | ||
| # RUN: llvm-readobj -r -s -x '.gehcont$y' %t.out.o | FileCheck %s --check-prefix=STRIP | ||
|
|
||
| # ORIG: Symbols [ | ||
| # ORIG: Name: .text | ||
| # ORIG: Name: .data | ||
| # ORIG: Name: .bss | ||
| # ORIG: Name: .text | ||
| # ORIG: Name: ?foo@@YAXXZ | ||
| # ORIG: Name: .data | ||
| # ORIG: Name: .drectve | ||
| # ORIG: Name: .debug$S | ||
| # ORIG: Name: .gehcont$y | ||
| # ORIG: Name: ?foo2@@YAXXZ | ||
| # ORIG: Name: $ehgcr_0_1 | ||
| # ORIG: Hex dump of section '.gehcont$y': | ||
| # ORIG-NEXT: 0x00000000 12000000 12000000 12000000 ............ | ||
|
|
||
| # .debug$S is going to be stripped and $ehgcr_0_1 index is decreased by 2 | ||
|
|
||
| # STRIP: Symbols [ | ||
| # STRIP: Name: .text | ||
| # STRIP: Name: .data | ||
| # STRIP: Name: .bss | ||
| # STRIP: Name: .text | ||
| # STRIP: Name: ?foo@@YAXXZ | ||
| # STRIP: Name: .data | ||
| # STRIP: Name: .drectve | ||
| # STRIP: Name: .gehcont$y | ||
| # STRIP: Name: ?foo2@@YAXXZ | ||
| # STRIP: Name: $ehgcr_0_1 | ||
| # STRIP: Hex dump of section '.gehcont$y': | ||
| # STRIP-NEXT: 0x00000000 10000000 10000000 10000000 ............ | ||
|
|
||
| --- !COFF | ||
| header: | ||
| Machine: IMAGE_FILE_MACHINE_AMD64 | ||
| Characteristics: [ ] | ||
| sections: | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '' | ||
| - Name: .data | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] | ||
| Alignment: 4 | ||
| SectionData: '' | ||
| - Name: .bss | ||
| Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] | ||
| Alignment: 4 | ||
| SectionData: '' | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 16 | ||
| SectionData: 554883EC30488D6C243048C745F0FEFFFFFFE800000000904883C4305DC366904889542410554883EC20488D6A30488D05E2FFFFFF4883C4205DC3 | ||
| SizeOfRawData: 59 | ||
| Relocations: | ||
| - VirtualAddress: 19 | ||
| SymbolName: '?foo2@@YAXXZ' | ||
| Type: IMAGE_REL_AMD64_REL32 | ||
| - Name: .data | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] | ||
| Alignment: 16 | ||
| SectionData: '000000000000000000000000000000002E48000000000000' | ||
| SizeOfRawData: 24 | ||
| - Name: .drectve | ||
| Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] | ||
| Alignment: 1 | ||
| SectionData: 202F44454641554C544C49423A6C6962636D742E6C6962202F44454641554C544C49423A6C69626972636D742E6C6962202F44454641554C544C49423A73766D6C5F646973706D742E6C6962202F44454641554C544C49423A6C69626D6D742E6C6962202F44454641554C544C49423A6F6C646E616D65732E6C6962 | ||
| SizeOfRawData: 124 | ||
| - Name: '.debug$S' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: 04000000F100000044656275672073656374696F6E20746F20626520737472697070656400 | ||
| SizeOfRawData: 37 | ||
| - Name: '.gehcont$y' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '120000001200000012000000' | ||
| SizeOfRawData: 12 | ||
| symbols: | ||
| - Name: .text | ||
| Value: 0 | ||
| SectionNumber: 1 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 0 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 0 | ||
| Number: 1 | ||
| - Name: .data | ||
| Value: 0 | ||
| SectionNumber: 2 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 0 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 0 | ||
| Number: 2 | ||
| - Name: .bss | ||
| Value: 0 | ||
| SectionNumber: 3 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 0 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 0 | ||
| Number: 3 | ||
| - Name: .text | ||
| Value: 0 | ||
| SectionNumber: 4 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 59 | ||
| NumberOfRelocations: 1 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 517419950 | ||
| Number: 4 | ||
| Selection: IMAGE_COMDAT_SELECT_NODUPLICATES | ||
| - Name: '?foo@@YAXXZ' | ||
| Value: 0 | ||
| SectionNumber: 4 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| - Name: .data | ||
| Value: 0 | ||
| SectionNumber: 5 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 24 | ||
| NumberOfRelocations: 1 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 2602060666 | ||
| Number: 5 | ||
| Selection: IMAGE_COMDAT_SELECT_ANY | ||
| - Name: .drectve | ||
| Value: 0 | ||
| SectionNumber: 6 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 124 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 1122646683 | ||
| Number: 6 | ||
| - Name: '.debug$S' | ||
| Value: 0 | ||
| SectionNumber: 7 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 37 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 820498156 | ||
| Number: 7 | ||
| - Name: '.gehcont$y' | ||
| Value: 0 | ||
| SectionNumber: 8 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 12 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 820498156 | ||
| Number: 8 | ||
| - Name: '?foo2@@YAXXZ' | ||
| Value: 0 | ||
| SectionNumber: 0 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| - Name: '$ehgcr_0_1' | ||
| Value: 23 | ||
| SectionNumber: 4 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| ... | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mstorsjo I've noticed that this approach is error-prone as if
addSymbolsinvoked twice, symbols will have duplicatedOriginalRawIndex(It doesn't happen now). Looks like we should have this variable as a class member.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this as a big concern though - we probably only ever call
addSymbolsonce. But I don't mind makingRawIndexa class member indeed, if it avoids the risk of an issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a
NextSymbolOriginalIndexsimilarly toNextSymbolUniqueId. Strictly speaking the name would beNextSymbolOriginalRawIndex. DroppedRaw. Maybe I should've droppedOriginal.