-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Add support for custom DOS stub #122561
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
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
446d70a
[LLD][COFF] Add support for custom DOS stub
kkent030315 7cb0b00
mention that `e_lfanew` = `AddressOfNewExeHeader`
kkent030315 2fa13d6
Add comment for each tests
kkent030315 202a08d
combine checks to `CHECK-INVALID`
kkent030315 9f97f3a
Use mmap file for stub
kkent030315 a890923
fix typo in comment
kkent030315 d20afac
fix filenames
kkent030315 0d1b1cc
improve error messages
kkent030315 8ba3ea4
stub -> dosStub and parseStub -> parseDosStub
kkent030315 d715929
fix stub68mz not MZ (was ZZ accidentally)
kkent030315 94ac28f
Accept unaligned stubs
kkent030315 6a8a59b
update comments as well
kkent030315 e1e9b43
adjust comments
kkent030315 27affd6
use raw expr instead of 0x40 hexdecimal
kkent030315 8bac7cd
fix unaligned test
kkent030315 639e14f
fix dosStubSize align and coffHeaderOffset respectively
kkent030315 d241e33
fix unaligned test
kkent030315 6c2e58c
adjust comments (again)
kkent030315 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,55 @@ | ||
# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj | ||
|
||
# RUN: lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub64mz %t.obj | ||
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s | ||
|
||
CHECK1: Magic: MZ | ||
CHECK1: UsedBytesInTheLastPage: 144 | ||
CHECK1: FileSizeInPages: 3 | ||
CHECK1: NumberOfRelocationItems: 0 | ||
CHECK1: HeaderSizeInParagraphs: 4 | ||
CHECK1: MinimumExtraParagraphs: 0 | ||
CHECK1: MaximumExtraParagraphs: 65535 | ||
CHECK1: InitialRelativeSS: 0 | ||
CHECK1: InitialSP: 184 | ||
CHECK1: Checksum: 0 | ||
CHECK1: InitialIP: 0 | ||
CHECK1: InitialRelativeCS: 0 | ||
CHECK1: AddressOfRelocationTable: 64 | ||
CHECK1: OverlayNumber: 0 | ||
CHECK1: OEMid: 0 | ||
CHECK1: OEMinfo: 0 | ||
CHECK1: AddressOfNewExeHeader: 64 | ||
|
||
## Invalid DOS signature (must be `MZ`) | ||
# RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub64zz %t.obj 2>&1 | FileCheck -check-prefix=CHECK2 %s | ||
|
||
CHECK2: lld-link: error: /stub: invalid DOS signature: {{.*}} | ||
|
||
## Unlike MS linker, we accept non-8byte-aligned stubs and we add paddings ourselves | ||
# RUN: lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub68mz %t.obj | ||
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK3 %s | ||
|
||
CHECK3: Magic: MZ | ||
CHECK3: UsedBytesInTheLastPage: 144 | ||
CHECK3: FileSizeInPages: 3 | ||
CHECK3: NumberOfRelocationItems: 0 | ||
CHECK3: HeaderSizeInParagraphs: 4 | ||
CHECK3: MinimumExtraParagraphs: 0 | ||
CHECK3: MaximumExtraParagraphs: 65535 | ||
CHECK3: InitialRelativeSS: 0 | ||
CHECK3: InitialSP: 184 | ||
CHECK3: Checksum: 0 | ||
CHECK3: InitialIP: 0 | ||
CHECK3: InitialRelativeCS: 0 | ||
CHECK3: AddressOfRelocationTable: 64 | ||
CHECK3: OverlayNumber: 0 | ||
CHECK3: OEMid: 0 | ||
CHECK3: OEMinfo: 0 | ||
## 68 is unaligned and rounded up to 72 by LLD | ||
CHECK3: AddressOfNewExeHeader: 72 | ||
|
||
## Too-small stub (must be at least 64 bytes long) && Unaligned | ||
# RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub63mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK4 %s | ||
|
||
CHECK4: lld-link: error: /stub: stub must be greater than or equal to 64 bytes: {{.*}} |
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.
Since the PEMagic needs to be 8-byte aligned, I think we need to round up dosStubSize here:
alignTo(dosStubSize, 8)
.Also, we need to audit all the uses of dosStubSize. For example,
Writer::writePEChecksum()
uses dosStubSize to locate the coffHeader. It should use coffHeaderOffset instead.