[lld] [LLD][COFF] Add support for custom DOS stub (PR #122561)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 03:06:18 PST 2025


================
@@ -0,0 +1,33 @@
+# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub512mz %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/stub512zz %t.obj 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
+
+## Unaligned stub (must be aligned to 8)
+# RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub516mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
+
+## Too-small stub (must be at least 64 bytes long)
----------------
kkent030315 wrote:

> Wouldn't this case also fail due to not being aligned to 8 bytes? So without seeing the implementation (or looking at an error message telling the exact reason), we don't strictly know if we're hitting the intended error, or erroring out due to some other reason.

Too-small stub (63 bytes) is not aligned to 8 bytes, yes.

For the latter, I was thinking the similar. Maybe it's better to put an exact cause for each malformed patterns. For now I followed the way how LINK.exe puts an error (they only put "invalid format" in any of the case). Should I do that?

https://github.com/llvm/llvm-project/pull/122561


More information about the llvm-commits mailing list