Skip to content

Commit fe44a53

Browse files
committedJul 16, 2019
[COFF] Implement /safeseh:no and check @feat.00 flags by default
Summary: Fixes PR41828. Before this, LLD always emitted SafeSEH chunks and defined __safe_se_handler_table & size. Now, /safeseh:no leaves those undefined. Additionally, we were checking for the safeseh @feat.00 flag in two places: once to emit errors, and once during safeseh table construction. The error was set up to be off by default, but safeseh is supposed to be on by default. I combined the two checks, so now LLD emits an error if an input object lacks @feat.00 and safeseh is enabled. This caused the majority of 32-bit LLD tests to fail, since many test input object files lack @feat.00 symbols. I explicitly added -safeseh:no to those tests to preserve behavior. Finally, LLD no longer sets IMAGE_DLL_CHARACTERISTICS_NO_SEH if any input file wasn't compiled for safeseh. Reviewers: mstorsjo, ruiu, thakis Reviewed By: ruiu, thakis Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63570 llvm-svn: 366238
1 parent 35c9659 commit fe44a53

32 files changed

+118
-74
lines changed
 

Diff for: ‎lld/COFF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct Configuration {
132132
GuardCFLevel guardCF = GuardCFLevel::Off;
133133

134134
// Used for SafeSEH.
135+
bool safeSEH = false;
135136
Symbol *sehTable = nullptr;
136137
Symbol *sehCount = nullptr;
137138

Diff for: ‎lld/COFF/Driver.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
15561556
}
15571557
config->wordsize = config->is64() ? 8 : 4;
15581558

1559+
// Handle /safeseh, x86 only, on by default, except for mingw.
1560+
if (config->machine == I386 &&
1561+
args.hasFlag(OPT_safeseh, OPT_safeseh_no, !config->mingw))
1562+
config->safeSEH = true;
1563+
15591564
// Handle /functionpadmin
15601565
for (auto *arg : args.filtered(OPT_functionpadmin, OPT_functionpadmin_opt))
15611566
parseFunctionPadMin(arg, config->machine);
@@ -1795,15 +1800,6 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
17951800
if (errorCount())
17961801
return;
17971802

1798-
// Handle /safeseh.
1799-
if (args.hasFlag(OPT_safeseh, OPT_safeseh_no, false)) {
1800-
for (ObjFile *file : ObjFile::instances)
1801-
if (!file->hasSafeSEH())
1802-
error("/safeseh: " + file->getName() + " is not compatible with SEH");
1803-
if (errorCount())
1804-
return;
1805-
}
1806-
18071803
if (config->mingw) {
18081804
// In MinGW, all symbols are automatically exported if no symbols
18091805
// are chosen to be exported.

Diff for: ‎lld/COFF/Writer.cpp

+4-12
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void Writer::createMiscChunks() {
917917
}
918918

919919
// Create SEH table. x86-only.
920-
if (config->machine == I386)
920+
if (config->safeSEH)
921921
createSEHTable();
922922

923923
// Create /guard:cf tables if requested.
@@ -1428,23 +1428,15 @@ void Writer::openFile(StringRef path) {
14281428
}
14291429

14301430
void Writer::createSEHTable() {
1431-
// Set the no SEH characteristic on x86 binaries unless we find exception
1432-
// handlers.
1433-
setNoSEHCharacteristic = true;
1434-
14351431
SymbolRVASet handlers;
14361432
for (ObjFile *file : ObjFile::instances) {
1437-
// FIXME: We should error here instead of earlier unless /safeseh:no was
1438-
// passed.
14391433
if (!file->hasSafeSEH())
1440-
return;
1441-
1434+
error("/safeseh: " + file->getName() + " is not compatible with SEH");
14421435
markSymbolsForRVATable(file, file->getSXDataChunks(), handlers);
14431436
}
14441437

1445-
// Remove the "no SEH" characteristic if all object files were built with
1446-
// safeseh, we found some exception handlers, and there is a load config in
1447-
// the object.
1438+
// Set the "no SEH" characteristic if there really were no handlers, or if
1439+
// there is no load config object to point to the table of handlers.
14481440
setNoSEHCharacteristic =
14491441
handlers.empty() || !symtab->findUnderscore("_load_config_used");
14501442

Diff for: ‎lld/test/COFF/allow-unknown-debug-info.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj %s > %t.obj
2-
# RUN: lld-link /dll /noentry /debug %t.obj 2>&1 | FileCheck %s
2+
# RUN: lld-link -safeseh:no /dll /noentry /debug %t.obj 2>&1 | FileCheck %s
33

44
# CHECK: ignoring section .debug$S with unrecognized magic 0x1
55

Diff for: ‎lld/test/COFF/constant.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ REQUIRES: x86
22
RUN: mkdir -p %t
33
RUN: llvm-mc -triple i686-unknown-windows-msvc -filetype obj -o %t/import.o %S/Inputs/constant-import.s
44
RUN: llc -mtriple i686-unknown-windows-msvc -filetype obj -o %t/export.o %S/Inputs/constant-export.ll
5-
RUN: lld-link -machine:x86 -dll -out:%t/export.dll %t/export.o -entry:__CFConstantStringClassReference
6-
RUN: lld-link -machine:x86 -dll -out:%t/import.dll %t/import.o %t/export.lib
5+
RUN: lld-link -safeseh:no -machine:x86 -dll -out:%t/export.dll %t/export.o -entry:__CFConstantStringClassReference
6+
RUN: lld-link -safeseh:no -machine:x86 -dll -out:%t/import.dll %t/import.o %t/export.lib

Diff for: ‎lld/test/COFF/def-export-stdcall.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o %t.obj
33
# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall\n fastcall\n vectorcall\n _underscored" > %t.def
4-
# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
4+
# RUN: lld-link -safeseh:no -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
55
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix UNDECORATED-IMPLIB %s
66
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix UNDECORATED-EXPORTS %s
77

@@ -25,7 +25,7 @@
2525

2626

2727
# RUN: echo -e "LIBRARY foo\nEXPORTS\n _stdcall@8\n @fastcall@8\n vectorcall@@8" > %t.def
28-
# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
28+
# RUN: lld-link -safeseh:no -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
2929
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-IMPLIB %s
3030
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix DECORATED-EXPORTS %s
3131

Diff for: ‎lld/test/COFF/delayimports32.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
3-
# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
3+
# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
44
# RUN: /entry:main@0 /alternatename:___delayLoadHelper2@8=_main@0 \
55
# RUN: /delayload:std32.dll /out:%t.exe
66
# RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s

Diff for: ‎lld/test/COFF/dllexport.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o %t.obj
33

4-
# RUN: lld-link -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
4+
# RUN: lld-link -safeseh:no -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
55
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-IMPLIB %s
66
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix DECORATED-EXPORTS %s
77

Diff for: ‎lld/test/COFF/entry-drectve.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /subsystem:console /out:%t.exe %t.obj
2+
# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj
33

44
--- !COFF
55
header:

Diff for: ‎lld/test/COFF/entry-inference332.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# RUN: sed -e s/ENTRYNAME/_mainCRTStartup/ %s | yaml2obj > %t.obj
2-
# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
2+
# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
33
# RUN: FileCheck %s < %t.log
44

55
# RUN: sed -e s/ENTRYNAME/?mainCRTStartup@@YAHXZ/ %s | yaml2obj > %t.obj
6-
# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
6+
# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
77
# RUN: FileCheck %s < %t.log
88

99
# CHECK: Entry name inferred: _mainCRTStartup

Diff for: ‎lld/test/COFF/exclude-all.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _dataSym:
2525

2626
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
2727
#
28-
# RUN: lld-link -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -output-def:%t.def
28+
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -output-def:%t.def
2929
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=DLLEXPORT %s
3030

3131
# DLLEXPORT: Name: exportfn3

Diff for: ‎lld/test/COFF/export-all.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ __imp__unexported:
4242

4343
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
4444
#
45-
# RUN: lld-link -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
45+
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
4646
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=CHECK2 %s
4747
# RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
4848

@@ -69,7 +69,7 @@ __imp__unexported:
6969
# RUN: llvm-ar rcs %T/libs/libmingwex.a %T/libs/mingwfunc.o
7070
# RUN: echo -e ".global crtfunc\n.text\ncrtfunc:\nret\n" > %T/libs/crtfunc.s
7171
# RUN: llvm-mc -triple=x86_64-windows-gnu %T/libs/crtfunc.s -filetype=obj -o %T/libs/crt2.o
72-
# RUN: lld-link -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o %T/libs/libmingwex.a -output-def:%t.def
72+
# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o %T/libs/libmingwex.a -output-def:%t.def
7373
# RUN: echo "EOF" >> %t.def
7474
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-EXCLUDE %s
7575

@@ -80,7 +80,7 @@ __imp__unexported:
8080
# Test that libraries included with -wholearchive: are autoexported, even if
8181
# they are in a library that otherwise normally would be excluded.
8282

83-
# RUN: lld-link -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o -wholearchive:%T/libs/libmingwex.a -output-def:%t.def
83+
# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o -wholearchive:%T/libs/libmingwex.a -output-def:%t.def
8484
# RUN: echo "EOF" >> %t.def
8585
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-WHOLEARCHIVE %s
8686

Diff for: ‎lld/test/COFF/export-stdcall.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -triple i686-windows-msvc %s -o %t.obj -filetype=obj
3-
# RUN: lld-link %t.obj -out:%t.dll -dll -nodefaultlib -noentry -export:foo_std=bar_std -export:foo_fast=bar_fast
3+
# RUN: lld-link -safeseh:no %t.obj -out:%t.dll -dll -nodefaultlib -noentry -export:foo_std=bar_std -export:foo_fast=bar_fast
44
# RUN: llvm-nm %t.lib | FileCheck %s
55

66
# MSVC fudges the lookup of 'bar' to allow it to find the stdcall function

Diff for: ‎lld/test/COFF/export32.test

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# RUN: yaml2obj < %s > %t.obj
22
#
3-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
3+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
44
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
55
#
6-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /merge:.edata=.rdata
6+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /merge:.edata=.rdata
77
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
88
# RUN: llvm-readobj --file-headers --sections %t.dll | FileCheck -check-prefix=HEADER-MERGE %s
99

@@ -20,7 +20,7 @@
2020
# HEADER-MERGE-NEXT: VirtualSize: 0x7E
2121
# HEADER-MERGE-NEXT: VirtualAddress: 0x2000
2222

23-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5 \
23+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1,@5 \
2424
# RUN: /export:exportfn2 /export:mangled
2525
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK2 %s
2626

@@ -37,7 +37,7 @@
3737
# CHECK2-NEXT: 7 0x1010 exportfn3
3838
# CHECK2-NEXT: 8 0x1010 mangled
3939

40-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
40+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
4141
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK3 %s
4242

4343
# CHECK3: Export Table:
@@ -51,7 +51,7 @@
5151
# CHECK3-NEXT: 5 0x1008
5252
# CHECK3-NEXT: 6 0x1010 exportfn2
5353

54-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
54+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
5555
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK4 %s
5656

5757
# CHECK4: Export Table:
@@ -64,12 +64,12 @@
6464

6565
# RUN: echo "EXPORTS exportfn1 @3" > %t.def
6666
# RUN: echo "fn2=exportfn2 @2" >> %t.def
67-
# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
67+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /def:%t.def
6868
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
6969

7070
# RUN: echo "EXPORTS exportfn1 @ 3" > %t.def
7171
# RUN: echo "fn2=exportfn2 @ 2" >> %t.def
72-
# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
72+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /def:%t.def
7373
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
7474

7575
# CHECK5: Export Table:
@@ -81,14 +81,14 @@
8181
# CHECK5-NEXT: 3 0x1008 exportfn1
8282
# CHECK5-NEXT: 4 0x1010 exportfn3
8383

84-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
84+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
8585
# RUN: /export:exportfn1 /export:exportfn2,@5 >& %t.log
8686
# RUN: FileCheck -check-prefix=CHECK6 %s < %t.log
8787

8888
# CHECK6: duplicate /export option: _exportfn2
8989
# CHECK6-NOT: duplicate /export option: _exportfn1
9090

91-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:foo=mangled
91+
# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:foo=mangled
9292
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK7 %s
9393

9494
# CHECK7: Export Table:

Diff for: ‎lld/test/COFF/fixed.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# REQUIRES: x86
22
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
33
#
4-
# RUN: lld-link %t.obj /fixed %p/Inputs/std32.lib /subsystem:console \
4+
# RUN: lld-link -safeseh:no %t.obj /fixed %p/Inputs/std32.lib /subsystem:console \
55
# RUN: /entry:main@0 /debug /out:%t.fixed.exe
66
# RUN: llvm-readobj --file-headers %t.fixed.exe | \
77
# RUN: FileCheck -check-prefix=EXEFIXED %s
88
#
9-
# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
9+
# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
1010
# RUN: /entry:main@0 /debug /out:%t.exe
1111
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=EXEREL %s
1212
#
1313
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
1414
#
15-
# RUN: lld-link %t.obj /dll /fixed /debug /out:%t.fixed.dll
15+
# RUN: lld-link -safeseh:no %t.obj /dll /fixed /debug /out:%t.fixed.dll
1616
# RUN: llvm-readobj --file-headers %t.fixed.dll | FileCheck -check-prefix=DLLFIXED %s
1717
#
18-
# RUN: lld-link %t.obj /dll /debug /out:%t.dll
18+
# RUN: lld-link -safeseh:no %t.obj /dll /debug /out:%t.dll
1919
# RUN: llvm-readobj --file-headers %t.dll | FileCheck -check-prefix=DLLREL %s
2020

2121
EXEFIXED-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE

Diff for: ‎lld/test/COFF/gfids-relocations32.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -triple i686-pc-win32 %s -filetype=obj -o %t.obj
3-
# RUN: lld-link %t.obj -guard:cf -out:%t.exe -entry:main
3+
# RUN: lld-link -safeseh:no %t.obj -guard:cf -out:%t.exe -entry:main
44
# RUN: llvm-readobj --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK
55

66
# Only f and _main should go in the table.

Diff for: ‎lld/test/COFF/hello32.test

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
2-
# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
2+
# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
33
# RUN: /entry:main@0 /out:%t.exe /appcontainer
44
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=HEADER %s
55
# RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
@@ -42,10 +42,9 @@ HEADER-NEXT: MinorSubsystemVersion: 0
4242
HEADER-NEXT: SizeOfImage: 20480
4343
HEADER-NEXT: SizeOfHeaders: 1024
4444
HEADER-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
45-
HEADER-NEXT: Characteristics [ (0x9540)
45+
HEADER-NEXT: Characteristics [ (0x9140)
4646
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_APPCONTAINER (0x1000)
4747
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
48-
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_NO_SEH (0x400)
4948
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
5049
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000)
5150
HEADER-NEXT: ]

Diff for: ‎lld/test/COFF/largeaddressaware.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
2-
# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
2+
# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
33
# RUN: /entry:main@0 /out:%t.exe /largeaddressaware
44
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=HEADER %s
55

Diff for: ‎lld/test/COFF/loadcfg32.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
2+
# RUN: lld-link -safeseh:no /out:%t.exe %t.obj /entry:main /subsystem:console
33
# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
44

55
# CHECK: LoadConfigTableRVA: 0x2000

Diff for: ‎lld/test/COFF/locally-imported32.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /out:%t.exe /entry:main %t.obj
2+
# RUN: lld-link -safeseh:no /out:%t.exe /entry:main %t.obj
33
# RUN: llvm-objdump -s %t.exe | FileCheck %s
44

55
# CHECK: Contents of section .text:

Diff for: ‎lld/test/COFF/machine.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# RUN: yaml2obj %p/Inputs/machine-x64.yaml > %t.obj
2-
# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
2+
# RUN: lld-link -safeseh:no /entry:main /subsystem:console /out:%t.exe %t.obj
33
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
4-
# RUN: lld-link /entry:main /subsystem:console /machine:x64 \
4+
# RUN: lld-link -safeseh:no /entry:main /subsystem:console /machine:x64 \
55
# RUN: /out:%t.exe %t.obj
66
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
77

88
AMD64: Machine: IMAGE_FILE_MACHINE_AMD64
99

1010
# RUN: yaml2obj %p/Inputs/machine-x86.yaml > %t.obj
11-
# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
11+
# RUN: lld-link -safeseh:no /entry:main /subsystem:console /out:%t.exe %t.obj
1212
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=I386 %s
13-
# RUN: lld-link /entry:main /subsystem:console /machine:x86 \
13+
# RUN: lld-link -safeseh:no /entry:main /subsystem:console /machine:x86 \
1414
# RUN: /out:%t.exe %t.obj /fixed
1515
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=I386 %s
1616

Diff for: ‎lld/test/COFF/no-ipi-stream.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# RUN: rm -rf %t && mkdir %t
22
# RUN: yaml2obj < %p/Inputs/no-ipi-stream-obj.obj.yaml > %t/no-ipi-stream-obj.obj
33
# RUN: llvm-pdbutil yaml2pdb %p/Inputs/no-ipi-stream-pdb.pdb.yaml -pdb=%t/no-ipi-stream-pdb.pdb
4-
# RUN: lld-link /dll /noentry /debug %t/no-ipi-stream-obj.obj
4+
# RUN: lld-link -safeseh:no /dll /noentry /debug %t/no-ipi-stream-obj.obj

Diff for: ‎lld/test/COFF/order-i386.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# RUN: echo fn1 > %t.order
44
# RUN: echo fn2 >> %t.order
55

6-
# RUN: lld-link -entry:fn1 -subsystem:console -opt:noref %t.obj \
6+
# RUN: lld-link -safeseh:no -entry:fn1 -subsystem:console -opt:noref %t.obj \
77
# RUN: -lldmap:- -out:%t.exe -order:@%t.order | FileCheck %s
88
# CHECK: fn1
99
# CHECK: fn2
1010

11-
# RUN: lld-link -entry:fn1 -subsystem:console -opt:noref %t.obj \
11+
# RUN: lld-link -safeseh:no -entry:fn1 -subsystem:console -opt:noref %t.obj \
1212
# RUN: -lldmap:- -out:%t.exe | FileCheck -check-prefix=DEFAULT %s
1313
# DEFAULT: fn2
1414
# DEFAULT: fn1

Diff for: ‎lld/test/COFF/pdb-debug-f.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
3-
# RUN: lld-link /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
3+
# RUN: lld-link -safeseh:no /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
44
# RUN: llvm-pdbutil dump -fpo %t.pdb | FileCheck %s
55

66
# CHECK: Old FPO Data

Diff for: ‎lld/test/COFF/pdb-lib.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o foo.obj
44
# RUN: llc %S/Inputs/bar.ll -filetype=obj -mtriple=i686-windows-msvc -o bar.obj
55
# RUN: llvm-lib bar.obj -out:bar.lib
6-
# RUN: lld-link -debug -pdb:foo.pdb foo.obj bar.lib -out:foo.exe -entry:main
6+
# RUN: lld-link -safeseh:no -debug -pdb:foo.pdb foo.obj bar.lib -out:foo.exe -entry:main
77
# RUN: llvm-pdbutil dump -modules %t/foo.pdb | FileCheck %s
88

99
# Make sure that the PDB has module descriptors. foo.obj and bar.lib should be

Diff for: ‎lld/test/COFF/pdb-safeseh.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj %s -o %t.obj
2-
# RUN: lld-link -debug -entry:main -out:%t.exe -pdb:%t.pdb %t.obj
2+
# RUN: lld-link -safeseh:no -debug -entry:main -out:%t.exe -pdb:%t.pdb %t.obj
33
# RUN: llvm-pdbutil dump -globals %t.pdb | FileCheck %s
44

55
# There is an S_GDATA32 symbol record with .secrel32 and .secidx relocations in

Diff for: ‎lld/test/COFF/pdb-unknown-subsection.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# REQUIRES: x86
55
# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
6-
# RUN: lld-link -subsystem:console -debug -nodefaultlib -entry:foo -out:%t.exe -pdb:%t.pdb %t.obj 2>&1 | FileCheck %s --check-prefix=WARNING
6+
# RUN: lld-link -safeseh:no -subsystem:console -debug -nodefaultlib -entry:foo -out:%t.exe -pdb:%t.pdb %t.obj 2>&1 | FileCheck %s --check-prefix=WARNING
77
# RUN: llvm-pdbutil dump -symbols %t.pdb | FileCheck %s
88

99
# WARNING-NOT: ignoring unknown

Diff for: ‎lld/test/COFF/reloc-x86.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: yaml2obj < %s > %t.obj
3-
# RUN: lld-link /out:%t.exe /entry:main /base:0x400000 %t.obj
3+
# RUN: lld-link -safeseh:no /out:%t.exe /entry:main /base:0x400000 %t.obj
44
# RUN: llvm-objdump -d %t.exe | FileCheck %s
55

66
# CHECK: .text:

Diff for: ‎lld/test/COFF/safeseh-no.s

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t.obj
2+
# RUN: not lld-link %t.obj -safeseh -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERROR
3+
# safe seh should be on by default.
4+
# RUN: not lld-link %t.obj -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERROR
5+
# RUN: lld-link %t.obj -safeseh:no -out:%t.exe -entry:main
6+
# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
7+
# -lldmingw should also turn off safeseh by default.
8+
# RUN: lld-link %t.obj -lldmingw -out:%t.exe -entry:main
9+
# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
10+
11+
# ERROR: /safeseh: {{.*}}safeseh-no.s.tmp.obj is not compatible with SEH
12+
13+
# CHECK: Characteristics [
14+
# CHECK-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH
15+
# CHECK: ]
16+
# CHECK: LoadConfig [
17+
# CHECK: Size: 0x48
18+
# CHECK: SEHandlerTable: 0x0
19+
# CHECK: SEHandlerCount: 0
20+
# CHECK: ]
21+
# CHECK-NOT: SEHTable
22+
23+
24+
# Explicitly mark the object as not having safeseh. LLD should error unless
25+
# -safeseh:no is passed.
26+
.def @feat.00; .scl 3; .type 0; .endef
27+
.globl @feat.00
28+
@feat.00 = 0
29+
30+
.def _main;
31+
.scl 2;
32+
.type 32;
33+
.endef
34+
.section .text,"xr",one_only,_main
35+
.globl _main
36+
_main:
37+
movl $42, %eax
38+
ret
39+
40+
# Add a handler to create an .sxdata section, which -safeseh:no should ignore.
41+
.def _my_handler; .scl 3; .type 32;
42+
.endef
43+
.section .text,"xr",one_only,_my_handler
44+
_my_handler:
45+
ret
46+
.safeseh _my_handler
47+
48+
49+
.section .rdata,"dr"
50+
.globl __load_config_used
51+
__load_config_used:
52+
.long 72
53+
.fill 60, 1, 0
54+
.long ___safe_se_handler_table
55+
.long ___safe_se_handler_count
56+

Diff for: ‎lld/test/COFF/subsystem-drectve.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /dll /noentry /out:%t.dll %t.obj
2+
# RUN: lld-link -safeseh:no /dll /noentry /out:%t.dll %t.obj
33
# RUN: llvm-readobj --file-headers %t.dll | FileCheck %s
44

55
# CHECK: MajorOperatingSystemVersion: 42

Diff for: ‎lld/test/COFF/subsystem-inference32.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# RUN: sed -e s/ENTRYNAME/_main/ %s | yaml2obj > %t.obj
2-
# RUN: lld-link /out:%t.exe %t.obj
2+
# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
33
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=MAIN %s
44

55
# RUN: sed s/ENTRYNAME/_wmain/ %s | yaml2obj > %t.obj
6-
# RUN: lld-link /out:%t.exe %t.obj
6+
# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
77
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WMAIN %s
88

99
# RUN: sed s/ENTRYNAME/_WinMain@16/ %s | yaml2obj > %t.obj
10-
# RUN: lld-link /out:%t.exe %t.obj
10+
# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
1111
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
1212

1313
# RUN: sed s/ENTRYNAME/_wWinMain@16/ %s | yaml2obj > %t.obj
14-
# RUN: lld-link /out:%t.exe %t.obj
14+
# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
1515
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WWINMAIN %s
1616

1717
# MAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI

Diff for: ‎lld/test/COFF/tls32.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /out:%t.exe /entry:main %t.obj
2+
# RUN: lld-link -safeseh:no /out:%t.exe /entry:main %t.obj
33
# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
44

55
# CHECK: TLSTableRVA: 0x1000

0 commit comments

Comments
 (0)
Please sign in to comment.