File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -255,9 +255,13 @@ void LinkerDriver::parseStub(StringRef path) {
255255 // 1. stub must be greater than or equal to 64 bytes
256256 // 2. stub must be 8-byte aligned
257257 // 3. stub must be start with a valid dos signature 'MZ'
258- if (bufferSize < 0x40 || bufferSize % 8 != 0 ||
259- (bufferStart[0 ] != ' M' || bufferStart[1 ] != ' Z' ))
260- Err (ctx) << " /stub: invalid format for MS-DOS stub file: " << path;
258+ if (bufferSize < 0x40 )
259+ Err (ctx) << " /stub: stub must be greater than or equal to 64 bytes: "
260+ << path;
261+ if (bufferStart[0 ] != ' M' || bufferStart[1 ] != ' Z' )
262+ Err (ctx) << " /stub: invalid DOS signature: " << path;
263+ if (bufferSize % 8 != 0 )
264+ Err (ctx) << " /stub: stub must be aligned to 8 bytes: " << path;
261265 ctx.config .stub = std::move (stub);
262266}
263267
Original file line number Diff line number Diff line change 11# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj
22
3- # RUN: lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub512mz %t.obj
3+ # RUN: lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub64mz %t.obj
44# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
55
66CHECK1: Magic: MZ
@@ -22,12 +22,13 @@ CHECK1: OEMinfo: 0
2222CHECK1: AddressOfNewExeHeader: 64
2323
2424## Invalid DOS signature (must be `MZ`)
25- # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub512zz %t.obj 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
25+ # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub64zz %t.obj 2>&1 | FileCheck -check-prefix=CHECK2 %s
26+ # CHECK2: lld-link: error: /stub: invalid DOS signature: {{.*}}
2627
2728## Unaligned stub (must be aligned to 8)
28- # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub516mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
29+ # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub68mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK3 %s
30+ # CHECK3: lld-link: error: /stub: stub must be aligned to 8 bytes: {{.*}}
2931
30- ## Too-small stub (must be at least 64 bytes long)
31- # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub511mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK-INVALID %s
32-
33- # CHECK-INVALID: lld-link: error: /stub: invalid format for MS-DOS stub file: {{.*}}
32+ ## Too-small stub (must be at least 64 bytes long) && Unaligned
33+ # RUN: not lld-link /out:%t.exe /entry:main /stub:%p/Inputs/stub63mz %t.obj 2>&1 | FileCheck -check-prefix=CHECK4 %s
34+ # CHECK4: lld-link: error: /stub: stub must be greater than or equal to 64 bytes: {{.*}}
You can’t perform that action at this time.
0 commit comments