[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 03:12:15 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:

It could probably be valuable to add more value in the error messages, even if link.exe doesn't; we don't need to match link.exe bit-by-bit exact in such details anyway. (For some larger cases, we print matching LNK123 error numbers, but most of other warnings/errors are different anyway.)

If we can grep for the right error message, this is probably fine, but otherwise it'd be good to make the file e.g. 56 bytes, so that it does pass the alignment test, so we trigger specifically the error we want to test, regardless of in which order the checks are made.

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


More information about the llvm-commits mailing list