- 
                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 all 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
    
  
  
    
              
              
        
          
          
            188 changes: 188 additions & 0 deletions
          
          188 
        
  llvm/test/tools/llvm-objcopy/COFF/strip-invalid-symidx-section.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,188 @@ | ||
| ## Test that we bail out if a section consisting of symidx is invalid. | ||
|  | ||
| ## In this case, the symbol .gfids$y is not present at all. | ||
| # RUN: yaml2obj %s --docnum=1 -o %t1.in.o | ||
| # RUN: not llvm-objcopy --strip-debug %t1.in.o %t1.out.o 2>&1 | FileCheck %s --check-prefix=ERROR-NOSYM -DFILE=%t1.out.o | ||
|  | ||
| # ERROR-NOSYM: error: '[[FILE]]': section '.gfids$y' does not have the corresponding symbol or the symbol has unexpected format | ||
|  | ||
| --- !COFF | ||
| header: | ||
| Machine: IMAGE_FILE_MACHINE_AMD64 | ||
| Characteristics: [ ] | ||
| sections: | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| - Name: '.gfids$y' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '04000000' | ||
| SizeOfRawData: 8 | ||
| 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: 4 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 0 | ||
| Number: 1 | ||
| - Name: foo | ||
| Value: 0 | ||
| SectionNumber: 0 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| ... | ||
|  | ||
| ## In this case, the symbol .giats$y has a non-zero offset. | ||
| # RUN: yaml2obj %s --docnum=2 -o %t2.in.o | ||
| # RUN: not llvm-objcopy --strip-debug %t2.in.o %t2.out.o 2>&1 | FileCheck %s --check-prefix=ERROR-OFFSET -DFILE=%t2.out.o | ||
|  | ||
| # ERROR-OFFSET: error: '[[FILE]]': section '.giats$y' does not have the corresponding symbol or the symbol has unexpected format | ||
|  | ||
| --- !COFF | ||
| header: | ||
| Machine: IMAGE_FILE_MACHINE_AMD64 | ||
| Characteristics: [ ] | ||
| sections: | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| - Name: '.giats$y' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '0600000010000000' | ||
| SizeOfRawData: 8 | ||
| 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: '.giats$y' | ||
| Value: 42 | ||
| SectionNumber: 2 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 8 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 1167279533 | ||
| Number: 5 | ||
| - Name: foo | ||
| Value: 0 | ||
| SectionNumber: 0 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| ... | ||
|  | ||
| ## In this case, the symbol .gljmp$y has a non-static storage class. | ||
| # RUN: yaml2obj %s --docnum=3 -o %t3.in.o | ||
| # RUN: not llvm-objcopy --strip-debug %t3.in.o %t3.out.o 2>&1 | FileCheck %s --check-prefix=ERROR-EXTERNAL -DFILE=%t3.out.o | ||
|  | ||
| # ERROR-EXTERNAL: error: '[[FILE]]': section '.gljmp$y' does not have the corresponding symbol or the symbol has unexpected format | ||
|  | ||
| --- !COFF | ||
| header: | ||
| Machine: IMAGE_FILE_MACHINE_AMD64 | ||
| Characteristics: [ ] | ||
| sections: | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| - Name: '.gljmp$y' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '0600000010000000' | ||
| SizeOfRawData: 8 | ||
| 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: '.gljmp$y' | ||
| Value: 0 | ||
| SectionNumber: 2 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| - Name: foo | ||
| Value: 0 | ||
| SectionNumber: 0 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| ... | ||
|  | ||
| ## In this case, .gfids$y contains a symbol index that is not present in the | ||
| ## symbol table. Generally the behavior should be the same for every section consisting | ||
| ## of .symidx directives, e.g .giats$y, .gljmp$y and .gehcont$y. | ||
| # RUN: yaml2obj %s --docnum=4 -o %t4.in.o | ||
| # RUN: not llvm-objcopy --strip-debug %t4.in.o %t4.out.o 2>&1 | FileCheck %s --check-prefix=ERROR-SYMIDX -DFILE=%t4.out.o | ||
|  | ||
| # ERROR-SYMIDX: error: '[[FILE]]': section '.gfids$y' contains a .symidx (16) that is incorrect or was stripped | ||
| --- !COFF | ||
| header: | ||
| Machine: IMAGE_FILE_MACHINE_AMD64 | ||
| Characteristics: [ ] | ||
| sections: | ||
| - Name: .text | ||
| Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
| - Name: '.gfids$y' | ||
| Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] | ||
| Alignment: 4 | ||
| SectionData: '0400000010000000' | ||
| SizeOfRawData: 8 | ||
| 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: '.gfids$y' | ||
| Value: 0 | ||
| SectionNumber: 2 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_STATIC | ||
| SectionDefinition: | ||
| Length: 8 | ||
| NumberOfRelocations: 0 | ||
| NumberOfLinenumbers: 0 | ||
| CheckSum: 1167279533 | ||
| Number: 5 | ||
| - Name: foo | ||
| Value: 0 | ||
| SectionNumber: 0 | ||
| SimpleType: IMAGE_SYM_TYPE_NULL | ||
| ComplexType: IMAGE_SYM_DTYPE_NULL | ||
| StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
| ... | 
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.