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

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 02:26:36 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)
----------------
mstorsjo 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.

Also, the numbers in the file names, 511/512/516 are quite puzzling how they relate to the actual file sizes (63/64/68 bytes). Can you enlighten me, or rename them to include the actual file size in the name instead :-)

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


More information about the llvm-commits mailing list