[lld] [LLD][COFF] Add support for custom DOS stub (PR #122561)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 03:10:33 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:
Would be something like:
```cpp
if (bufferSize < 0x40)
Err(ctx) << "/stub: stub must be greater than or equal to 64 bytes: " << path;
if (bufferSize % 8 != 0)
Err(ctx) << "/stub: stub must be aligned to 8 bytes: " << path;
if ((bufferStart[0] != 'M' || bufferStart[1] != 'Z'))
Err(ctx) << "/stub: invalid DOS signature: " << path;
```
https://github.com/llvm/llvm-project/pull/122561
More information about the llvm-commits
mailing list