-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-objcopy] Add --gap-fill and --pad-to options #65815
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
quic-akaryaki
merged 15 commits into
llvm:main
from
quic-akaryaki:gap-fill-pad-to-binary
Dec 14, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
21ba98f
[llvm-objcopy] Add --gap-fill and --pad-to options
quic-akaryaki c713cec
Address PR feedback.
quic-akaryaki 29ff70e
Addressing more feedback.
quic-akaryaki 473cd4b
Merge branch 'llvm:main' into gap-fill-pad-to-binary
quic-akaryaki 3452fc8
Another round of review fixes.
quic-akaryaki 6ba8666
Fill a missing word in a test comment.
quic-akaryaki 9ff99db
Merge branch 'llvm:main' into gap-fill-pad-to-binary
quic-akaryaki 8c689d2
Some more aesthetics.
quic-akaryaki 3a2cf9f
Merge remote-tracking branch 'fork/main' into HEAD
quic-akaryaki bd194c2
Merge branch 'llvm:main' into gap-fill-pad-to-binary
quic-akaryaki 7670531
Lastest review.
quic-akaryaki 3fd26d9
Format.
quic-akaryaki 9d5783c
Failing test fixed.
quic-akaryaki 3f1cd7d
Remove remaining AddressAlign from the test and undo reportWarning.
quic-akaryaki ed98938
Remove thes.
quic-akaryaki 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# RUN: yaml2obj --docnum=1 %s -o %t | ||
|
||
# RUN: not llvm-objcopy --gap-fill 1 %t 2>&1 | FileCheck %s --check-prefix=NOT-BINARY | ||
# NOT-BINARY: error: '--gap-fill' is only supported for binary output | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill= %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT | ||
# BAD-FORMAT: error: --gap-fill: bad number: | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill=x %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT | ||
# BAD-INPUT: error: --gap-fill: bad number: x | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill=0x %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT2 | ||
# BAD-INPUT2: error: --gap-fill: bad number: 0x | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill=0x1G %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT3 | ||
# BAD-INPUT3: error: --gap-fill: bad number: 0x1G | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill=ff %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT4 | ||
# BAD-INPUT4: error: --gap-fill: bad number: ff | ||
|
||
# RUN: not llvm-objcopy -O binary --gap-fill=0x1122 %t %t-val16 2>&1 | FileCheck %s --check-prefix=TRUNCATED-ERR | ||
# TRUNCATED-ERR: error: gap-fill value 0x1122 is out of range (0 to 0xff) | ||
|
||
## Test no gap fill with all allocatable output sections. | ||
# RUN: llvm-objcopy -O binary %t %t-default | ||
# RUN: od -v -Ax -t x1 %t-default | FileCheck %s --check-prefix=DEFAULT --match-full-lines | ||
# DEFAULT: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba 00 a1 b2 | ||
# DEFAULT-NEXT: 000010 c3 d4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
# DEFAULT-NEXT: 000080 00 00 89 ab cd ef | ||
# DEFAULT-NEXT: 000086 | ||
|
||
## Test gap fill with all allocatable output sections. | ||
# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t %t-filled | ||
# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=FULL --match-full-lines | ||
# FULL: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2 | ||
# FULL-NEXT: 000010 c3 d4 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000020 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000030 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000040 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000050 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000060 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000070 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# FULL-NEXT: 000080 e9 e9 89 ab cd ef | ||
# FULL-NEXT: 000086 | ||
|
||
## Test gap fill with a decimal value. | ||
# RUN: llvm-objcopy -O binary --gap-fill=99 %t %t-filled-decimal | ||
# RUN: od -v -Ax -t x1 %t-filled-decimal | FileCheck %s --check-prefix=DEC --match-full-lines | ||
# DEC: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba 63 a1 b2 | ||
# DEC-NEXT: 000010 c3 d4 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000020 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000030 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000040 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000050 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000060 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000070 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 | ||
# DEC-NEXT: 000080 63 63 89 ab cd ef | ||
# DEC-NEXT: 000086 | ||
|
||
## Test gap fill with the last section removed, should be truncated. | ||
# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.foo %t %t-filled | ||
# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-LAST-SECTION --match-full-lines | ||
# REMOVE-LAST-SECTION: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2 | ||
# REMOVE-LAST-SECTION-NEXT: 000010 c3 d4 | ||
# REMOVE-LAST-SECTION-NEXT: 000012 | ||
|
||
## Test gap fill with the middle section removed, should be filled. | ||
# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.gap2 %t %t-filled | ||
# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-MIDDLE-SECTION --match-full-lines | ||
# REMOVE-MIDDLE-SECTION: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000010 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000020 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000030 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000040 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000050 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000060 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000070 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000080 e9 e9 89 ab cd ef | ||
# REMOVE-MIDDLE-SECTION-NEXT: 000086 | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .space1 | ||
Type: Fill | ||
Pattern: 'ABCD' | ||
Size: 0x2 | ||
- Name: .nogap | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x0102 | ||
Size: 0x6 | ||
Content: 'EEFF11223344' | ||
- Name: .gap1 | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
Address: 0x0108 | ||
Content: 'AABBCCDDFEDCBA' | ||
- Name: .space2 | ||
Type: Fill | ||
Pattern: 'DC' | ||
Size: 1 | ||
- Name: .gap2 | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x0110 | ||
Content: 'A1B2C3D4' | ||
- Name: .space3 | ||
Type: Fill | ||
Pattern: 'FE' | ||
Size: 0x1 | ||
- Name: .nobit_tbss | ||
Type: SHT_NOBITS | ||
Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] | ||
Address: 0x0180 | ||
Size: 0x0018 | ||
- Name: .space4 | ||
Type: Fill | ||
Pattern: '01234567' | ||
Size: 0x4 | ||
- Name: .foo | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_WRITE, SHF_ALLOC ] | ||
Address: 0x0184 | ||
Content: '89ABCDEF' | ||
- Name: .nobit_bss | ||
Type: SHT_NOBITS | ||
Flags: [ SHF_WRITE, SHF_ALLOC ] | ||
Address: 0x018A | ||
Size: 0x0008 | ||
- Name: .comment | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_MERGE, SHF_STRINGS ] | ||
EntSize: 0x0001 | ||
Content: 4743433A | ||
|
||
## In this test, output sections are defined out of order with respect to their | ||
## load addresses. Verify that gaps are still correctly filled. | ||
|
||
# RUN: yaml2obj --docnum=2 %s -o %t.2 | ||
# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t.2 %t.2.filled | ||
# RUN: od -v -Ax -t x1 %t.2.filled | FileCheck --match-full-lines %s | ||
# CHECK: 000000 aa bb cc dd e9 e9 e9 e9 11 22 33 44 | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .bss | ||
Type: SHT_NOBITS | ||
Flags: [ SHF_ALLOC, SHF_WRITE ] | ||
Address: 0x0104 | ||
Size: 4 | ||
- Name: .section1 | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_WRITE ] | ||
Address: 0x0108 | ||
Content: '11223344' | ||
- Name: .section3 | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_WRITE ] | ||
Address: 0x0100 | ||
Content: 'AABBCCDD' |
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.