aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-07-16 18:17:33 +0000
committerReid Kleckner <rnk@google.com>2019-07-16 18:17:33 +0000
commit44f463f6129e464f03480372b27bcd9e66fabc6a (patch)
tree995477f755923aec3311c0b348e5e2de307fec0c
parentbeb1e40a02f8be0cb2c71d551d86f84d495d41e3 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@366238 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--COFF/Config.h1
-rw-r--r--COFF/Driver.cpp14
-rw-r--r--COFF/Writer.cpp16
-rw-r--r--test/COFF/allow-unknown-debug-info.test2
-rw-r--r--test/COFF/constant.test4
-rw-r--r--test/COFF/def-export-stdcall.s4
-rw-r--r--test/COFF/delayimports32.test2
-rw-r--r--test/COFF/dllexport.s2
-rw-r--r--test/COFF/entry-drectve.test2
-rw-r--r--test/COFF/entry-inference332.test4
-rw-r--r--test/COFF/exclude-all.s2
-rw-r--r--test/COFF/export-all.s6
-rw-r--r--test/COFF/export-stdcall.s2
-rw-r--r--test/COFF/export32.test18
-rw-r--r--test/COFF/fixed.test8
-rw-r--r--test/COFF/gfids-relocations32.s2
-rw-r--r--test/COFF/hello32.test5
-rw-r--r--test/COFF/largeaddressaware.test2
-rw-r--r--test/COFF/loadcfg32.test2
-rw-r--r--test/COFF/locally-imported32.test2
-rw-r--r--test/COFF/machine.test8
-rw-r--r--test/COFF/no-ipi-stream.test2
-rw-r--r--test/COFF/order-i386.test4
-rw-r--r--test/COFF/pdb-debug-f.s2
-rw-r--r--test/COFF/pdb-lib.s2
-rw-r--r--test/COFF/pdb-safeseh.yaml2
-rw-r--r--test/COFF/pdb-unknown-subsection.s2
-rw-r--r--test/COFF/reloc-x86.test2
-rw-r--r--test/COFF/safeseh-no.s56
-rw-r--r--test/COFF/subsystem-drectve.test2
-rw-r--r--test/COFF/subsystem-inference32.test8
-rw-r--r--test/COFF/tls32.test2
32 files changed, 118 insertions, 74 deletions
diff --git a/COFF/Config.h b/COFF/Config.h
index e378b6fc7..1b0e24042 100644
--- a/COFF/Config.h
+++ b/COFF/Config.h
@@ -132,6 +132,7 @@ struct Configuration {
GuardCFLevel guardCF = GuardCFLevel::Off;
// Used for SafeSEH.
+ bool safeSEH = false;
Symbol *sehTable = nullptr;
Symbol *sehCount = nullptr;
diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp
index 6cfd83ab9..d7af50b93 100644
--- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -1556,6 +1556,11 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
}
config->wordsize = config->is64() ? 8 : 4;
+ // Handle /safeseh, x86 only, on by default, except for mingw.
+ if (config->machine == I386 &&
+ args.hasFlag(OPT_safeseh, OPT_safeseh_no, !config->mingw))
+ config->safeSEH = true;
+
// Handle /functionpadmin
for (auto *arg : args.filtered(OPT_functionpadmin, OPT_functionpadmin_opt))
parseFunctionPadMin(arg, config->machine);
@@ -1795,15 +1800,6 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
if (errorCount())
return;
- // Handle /safeseh.
- if (args.hasFlag(OPT_safeseh, OPT_safeseh_no, false)) {
- for (ObjFile *file : ObjFile::instances)
- if (!file->hasSafeSEH())
- error("/safeseh: " + file->getName() + " is not compatible with SEH");
- if (errorCount())
- return;
- }
-
if (config->mingw) {
// In MinGW, all symbols are automatically exported if no symbols
// are chosen to be exported.
diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp
index e4b35a5f8..36ef87de4 100644
--- a/COFF/Writer.cpp
+++ b/COFF/Writer.cpp
@@ -917,7 +917,7 @@ void Writer::createMiscChunks() {
}
// Create SEH table. x86-only.
- if (config->machine == I386)
+ if (config->safeSEH)
createSEHTable();
// Create /guard:cf tables if requested.
@@ -1428,23 +1428,15 @@ void Writer::openFile(StringRef path) {
}
void Writer::createSEHTable() {
- // Set the no SEH characteristic on x86 binaries unless we find exception
- // handlers.
- setNoSEHCharacteristic = true;
-
SymbolRVASet handlers;
for (ObjFile *file : ObjFile::instances) {
- // FIXME: We should error here instead of earlier unless /safeseh:no was
- // passed.
if (!file->hasSafeSEH())
- return;
-
+ error("/safeseh: " + file->getName() + " is not compatible with SEH");
markSymbolsForRVATable(file, file->getSXDataChunks(), handlers);
}
- // Remove the "no SEH" characteristic if all object files were built with
- // safeseh, we found some exception handlers, and there is a load config in
- // the object.
+ // Set the "no SEH" characteristic if there really were no handlers, or if
+ // there is no load config object to point to the table of handlers.
setNoSEHCharacteristic =
handlers.empty() || !symtab->findUnderscore("_load_config_used");
diff --git a/test/COFF/allow-unknown-debug-info.test b/test/COFF/allow-unknown-debug-info.test
index c45b98e2a..1cc9e9e0b 100644
--- a/test/COFF/allow-unknown-debug-info.test
+++ b/test/COFF/allow-unknown-debug-info.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t.obj
-# RUN: lld-link /dll /noentry /debug %t.obj 2>&1 | FileCheck %s
+# RUN: lld-link -safeseh:no /dll /noentry /debug %t.obj 2>&1 | FileCheck %s
# CHECK: ignoring section .debug$S with unrecognized magic 0x1
diff --git a/test/COFF/constant.test b/test/COFF/constant.test
index 02d6b3e2c..dc97f1cb9 100644
--- a/test/COFF/constant.test
+++ b/test/COFF/constant.test
@@ -2,5 +2,5 @@ REQUIRES: x86
RUN: mkdir -p %t
RUN: llvm-mc -triple i686-unknown-windows-msvc -filetype obj -o %t/import.o %S/Inputs/constant-import.s
RUN: llc -mtriple i686-unknown-windows-msvc -filetype obj -o %t/export.o %S/Inputs/constant-export.ll
-RUN: lld-link -machine:x86 -dll -out:%t/export.dll %t/export.o -entry:__CFConstantStringClassReference
-RUN: lld-link -machine:x86 -dll -out:%t/import.dll %t/import.o %t/export.lib
+RUN: lld-link -safeseh:no -machine:x86 -dll -out:%t/export.dll %t/export.o -entry:__CFConstantStringClassReference
+RUN: lld-link -safeseh:no -machine:x86 -dll -out:%t/import.dll %t/import.o %t/export.lib
diff --git a/test/COFF/def-export-stdcall.s b/test/COFF/def-export-stdcall.s
index 55709f958..f015e205c 100644
--- a/test/COFF/def-export-stdcall.s
+++ b/test/COFF/def-export-stdcall.s
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o %t.obj
# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall\n fastcall\n vectorcall\n _underscored" > %t.def
-# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
+# RUN: lld-link -safeseh:no -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix UNDECORATED-IMPLIB %s
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix UNDECORATED-EXPORTS %s
@@ -25,7 +25,7 @@
# RUN: echo -e "LIBRARY foo\nEXPORTS\n _stdcall@8\n @fastcall@8\n vectorcall@@8" > %t.def
-# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
+# RUN: lld-link -safeseh:no -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-IMPLIB %s
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix DECORATED-EXPORTS %s
diff --git a/test/COFF/delayimports32.test b/test/COFF/delayimports32.test
index b684d4105..0fc90200c 100644
--- a/test/COFF/delayimports32.test
+++ b/test/COFF/delayimports32.test
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
-# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
# RUN: /entry:main@0 /alternatename:___delayLoadHelper2@8=_main@0 \
# RUN: /delayload:std32.dll /out:%t.exe
# RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
diff --git a/test/COFF/dllexport.s b/test/COFF/dllexport.s
index b5b7080d1..a238b70ce 100644
--- a/test/COFF/dllexport.s
+++ b/test/COFF/dllexport.s
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o %t.obj
-# RUN: lld-link -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
+# RUN: lld-link -safeseh:no -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-IMPLIB %s
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix DECORATED-EXPORTS %s
diff --git a/test/COFF/entry-drectve.test b/test/COFF/entry-drectve.test
index e51e7cb20..0848b0a04 100644
--- a/test/COFF/entry-drectve.test
+++ b/test/COFF/entry-drectve.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /subsystem:console /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj
--- !COFF
header:
diff --git a/test/COFF/entry-inference332.test b/test/COFF/entry-inference332.test
index 75c557af4..ddeaf280a 100644
--- a/test/COFF/entry-inference332.test
+++ b/test/COFF/entry-inference332.test
@@ -1,9 +1,9 @@
# RUN: sed -e s/ENTRYNAME/_mainCRTStartup/ %s | yaml2obj > %t.obj
-# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
+# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
# RUN: FileCheck %s < %t.log
# RUN: sed -e s/ENTRYNAME/?mainCRTStartup@@YAHXZ/ %s | yaml2obj > %t.obj
-# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
+# RUN: lld-link -safeseh:no /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
# RUN: FileCheck %s < %t.log
# CHECK: Entry name inferred: _mainCRTStartup
diff --git a/test/COFF/exclude-all.s b/test/COFF/exclude-all.s
index e2c23368d..41caece2d 100644
--- a/test/COFF/exclude-all.s
+++ b/test/COFF/exclude-all.s
@@ -25,7 +25,7 @@ _dataSym:
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
#
-# RUN: lld-link -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -output-def:%t.def
+# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -output-def:%t.def
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=DLLEXPORT %s
# DLLEXPORT: Name: exportfn3
diff --git a/test/COFF/export-all.s b/test/COFF/export-all.s
index 778931936..6292ed33e 100644
--- a/test/COFF/export-all.s
+++ b/test/COFF/export-all.s
@@ -42,7 +42,7 @@ __imp__unexported:
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
#
-# RUN: lld-link -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
+# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=CHECK2 %s
# RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
@@ -69,7 +69,7 @@ __imp__unexported:
# RUN: llvm-ar rcs %T/libs/libmingwex.a %T/libs/mingwfunc.o
# RUN: echo -e ".global crtfunc\n.text\ncrtfunc:\nret\n" > %T/libs/crtfunc.s
# RUN: llvm-mc -triple=x86_64-windows-gnu %T/libs/crtfunc.s -filetype=obj -o %T/libs/crt2.o
-# 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
+# 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
# RUN: echo "EOF" >> %t.def
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-EXCLUDE %s
@@ -80,7 +80,7 @@ __imp__unexported:
# Test that libraries included with -wholearchive: are autoexported, even if
# they are in a library that otherwise normally would be excluded.
-# 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
+# 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
# RUN: echo "EOF" >> %t.def
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-WHOLEARCHIVE %s
diff --git a/test/COFF/export-stdcall.s b/test/COFF/export-stdcall.s
index 6ed3e8803..aa39eaecf 100644
--- a/test/COFF/export-stdcall.s
+++ b/test/COFF/export-stdcall.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -triple i686-windows-msvc %s -o %t.obj -filetype=obj
-# RUN: lld-link %t.obj -out:%t.dll -dll -nodefaultlib -noentry -export:foo_std=bar_std -export:foo_fast=bar_fast
+# RUN: lld-link -safeseh:no %t.obj -out:%t.dll -dll -nodefaultlib -noentry -export:foo_std=bar_std -export:foo_fast=bar_fast
# RUN: llvm-nm %t.lib | FileCheck %s
# MSVC fudges the lookup of 'bar' to allow it to find the stdcall function
diff --git a/test/COFF/export32.test b/test/COFF/export32.test
index 250c305d4..1251d43aa 100644
--- a/test/COFF/export32.test
+++ b/test/COFF/export32.test
@@ -1,9 +1,9 @@
# RUN: yaml2obj < %s > %t.obj
#
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
#
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /merge:.edata=.rdata
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /merge:.edata=.rdata
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
# RUN: llvm-readobj --file-headers --sections %t.dll | FileCheck -check-prefix=HEADER-MERGE %s
@@ -20,7 +20,7 @@
# HEADER-MERGE-NEXT: VirtualSize: 0x7E
# HEADER-MERGE-NEXT: VirtualAddress: 0x2000
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5 \
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1,@5 \
# RUN: /export:exportfn2 /export:mangled
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK2 %s
@@ -37,7 +37,7 @@
# CHECK2-NEXT: 7 0x1010 exportfn3
# CHECK2-NEXT: 8 0x1010 mangled
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK3 %s
# CHECK3: Export Table:
@@ -51,7 +51,7 @@
# CHECK3-NEXT: 5 0x1008
# CHECK3-NEXT: 6 0x1010 exportfn2
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK4 %s
# CHECK4: Export Table:
@@ -64,12 +64,12 @@
# RUN: echo "EXPORTS exportfn1 @3" > %t.def
# RUN: echo "fn2=exportfn2 @2" >> %t.def
-# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /def:%t.def
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
# RUN: echo "EXPORTS exportfn1 @ 3" > %t.def
# RUN: echo "fn2=exportfn2 @ 2" >> %t.def
-# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /def:%t.def
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
# CHECK5: Export Table:
@@ -81,14 +81,14 @@
# CHECK5-NEXT: 3 0x1008 exportfn1
# CHECK5-NEXT: 4 0x1010 exportfn3
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
# RUN: /export:exportfn1 /export:exportfn2,@5 >& %t.log
# RUN: FileCheck -check-prefix=CHECK6 %s < %t.log
# CHECK6: duplicate /export option: _exportfn2
# CHECK6-NOT: duplicate /export option: _exportfn1
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:foo=mangled
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:foo=mangled
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK7 %s
# CHECK7: Export Table:
diff --git a/test/COFF/fixed.test b/test/COFF/fixed.test
index 7a5d9e6ea..e162570df 100644
--- a/test/COFF/fixed.test
+++ b/test/COFF/fixed.test
@@ -1,21 +1,21 @@
# REQUIRES: x86
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
#
-# RUN: lld-link %t.obj /fixed %p/Inputs/std32.lib /subsystem:console \
+# RUN: lld-link -safeseh:no %t.obj /fixed %p/Inputs/std32.lib /subsystem:console \
# RUN: /entry:main@0 /debug /out:%t.fixed.exe
# RUN: llvm-readobj --file-headers %t.fixed.exe | \
# RUN: FileCheck -check-prefix=EXEFIXED %s
#
-# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
# RUN: /entry:main@0 /debug /out:%t.exe
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=EXEREL %s
#
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
#
-# RUN: lld-link %t.obj /dll /fixed /debug /out:%t.fixed.dll
+# RUN: lld-link -safeseh:no %t.obj /dll /fixed /debug /out:%t.fixed.dll
# RUN: llvm-readobj --file-headers %t.fixed.dll | FileCheck -check-prefix=DLLFIXED %s
#
-# RUN: lld-link %t.obj /dll /debug /out:%t.dll
+# RUN: lld-link -safeseh:no %t.obj /dll /debug /out:%t.dll
# RUN: llvm-readobj --file-headers %t.dll | FileCheck -check-prefix=DLLREL %s
EXEFIXED-NOT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
diff --git a/test/COFF/gfids-relocations32.s b/test/COFF/gfids-relocations32.s
index 2b0e425a1..6c51f7aca 100644
--- a/test/COFF/gfids-relocations32.s
+++ b/test/COFF/gfids-relocations32.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -triple i686-pc-win32 %s -filetype=obj -o %t.obj
-# RUN: lld-link %t.obj -guard:cf -out:%t.exe -entry:main
+# RUN: lld-link -safeseh:no %t.obj -guard:cf -out:%t.exe -entry:main
# RUN: llvm-readobj --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK
# Only f and _main should go in the table.
diff --git a/test/COFF/hello32.test b/test/COFF/hello32.test
index b53264ac6..61418d3d2 100644
--- a/test/COFF/hello32.test
+++ b/test/COFF/hello32.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
-# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
# RUN: /entry:main@0 /out:%t.exe /appcontainer
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=HEADER %s
# RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
@@ -42,10 +42,9 @@ HEADER-NEXT: MinorSubsystemVersion: 0
HEADER-NEXT: SizeOfImage: 20480
HEADER-NEXT: SizeOfHeaders: 1024
HEADER-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
-HEADER-NEXT: Characteristics [ (0x9540)
+HEADER-NEXT: Characteristics [ (0x9140)
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_APPCONTAINER (0x1000)
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
-HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_NO_SEH (0x400)
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000)
HEADER-NEXT: ]
diff --git a/test/COFF/largeaddressaware.test b/test/COFF/largeaddressaware.test
index 4c2ae56cc..ddd37131a 100644
--- a/test/COFF/largeaddressaware.test
+++ b/test/COFF/largeaddressaware.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
-# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: lld-link -safeseh:no %t.obj %p/Inputs/std32.lib /subsystem:console \
# RUN: /entry:main@0 /out:%t.exe /largeaddressaware
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=HEADER %s
diff --git a/test/COFF/loadcfg32.test b/test/COFF/loadcfg32.test
index e211c95e7..dffdab8b1 100644
--- a/test/COFF/loadcfg32.test
+++ b/test/COFF/loadcfg32.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
+# RUN: lld-link -safeseh:no /out:%t.exe %t.obj /entry:main /subsystem:console
# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
# CHECK: LoadConfigTableRVA: 0x2000
diff --git a/test/COFF/locally-imported32.test b/test/COFF/locally-imported32.test
index 789c8c8f8..993099d42 100644
--- a/test/COFF/locally-imported32.test
+++ b/test/COFF/locally-imported32.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe /entry:main %t.obj
# RUN: llvm-objdump -s %t.exe | FileCheck %s
# CHECK: Contents of section .text:
diff --git a/test/COFF/machine.test b/test/COFF/machine.test
index 2ac276f1b..921b7e393 100644
--- a/test/COFF/machine.test
+++ b/test/COFF/machine.test
@@ -1,16 +1,16 @@
# RUN: yaml2obj %p/Inputs/machine-x64.yaml > %t.obj
-# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /entry:main /subsystem:console /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
-# RUN: lld-link /entry:main /subsystem:console /machine:x64 \
+# RUN: lld-link -safeseh:no /entry:main /subsystem:console /machine:x64 \
# RUN: /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
AMD64: Machine: IMAGE_FILE_MACHINE_AMD64
# RUN: yaml2obj %p/Inputs/machine-x86.yaml > %t.obj
-# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /entry:main /subsystem:console /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=I386 %s
-# RUN: lld-link /entry:main /subsystem:console /machine:x86 \
+# RUN: lld-link -safeseh:no /entry:main /subsystem:console /machine:x86 \
# RUN: /out:%t.exe %t.obj /fixed
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=I386 %s
diff --git a/test/COFF/no-ipi-stream.test b/test/COFF/no-ipi-stream.test
index 246c35907..e9b2a31bc 100644
--- a/test/COFF/no-ipi-stream.test
+++ b/test/COFF/no-ipi-stream.test
@@ -1,4 +1,4 @@
# RUN: rm -rf %t && mkdir %t
# RUN: yaml2obj < %p/Inputs/no-ipi-stream-obj.obj.yaml > %t/no-ipi-stream-obj.obj
# RUN: llvm-pdbutil yaml2pdb %p/Inputs/no-ipi-stream-pdb.pdb.yaml -pdb=%t/no-ipi-stream-pdb.pdb
-# RUN: lld-link /dll /noentry /debug %t/no-ipi-stream-obj.obj
+# RUN: lld-link -safeseh:no /dll /noentry /debug %t/no-ipi-stream-obj.obj
diff --git a/test/COFF/order-i386.test b/test/COFF/order-i386.test
index 4cde5fa81..acd9ad2aa 100644
--- a/test/COFF/order-i386.test
+++ b/test/COFF/order-i386.test
@@ -3,12 +3,12 @@
# RUN: echo fn1 > %t.order
# RUN: echo fn2 >> %t.order
-# RUN: lld-link -entry:fn1 -subsystem:console -opt:noref %t.obj \
+# RUN: lld-link -safeseh:no -entry:fn1 -subsystem:console -opt:noref %t.obj \
# RUN: -lldmap:- -out:%t.exe -order:@%t.order | FileCheck %s
# CHECK: fn1
# CHECK: fn2
-# RUN: lld-link -entry:fn1 -subsystem:console -opt:noref %t.obj \
+# RUN: lld-link -safeseh:no -entry:fn1 -subsystem:console -opt:noref %t.obj \
# RUN: -lldmap:- -out:%t.exe | FileCheck -check-prefix=DEFAULT %s
# DEFAULT: fn2
# DEFAULT: fn1
diff --git a/test/COFF/pdb-debug-f.s b/test/COFF/pdb-debug-f.s
index 624c11929..ccc34558c 100644
--- a/test/COFF/pdb-debug-f.s
+++ b/test/COFF/pdb-debug-f.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
-# RUN: lld-link /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
+# RUN: lld-link -safeseh:no /subsystem:console /debug /nodefaultlib /entry:foo /out:%t.exe /pdb:%t.pdb %t.obj
# RUN: llvm-pdbutil dump -fpo %t.pdb | FileCheck %s
# CHECK: Old FPO Data
diff --git a/test/COFF/pdb-lib.s b/test/COFF/pdb-lib.s
index dacf5f27a..09f189206 100644
--- a/test/COFF/pdb-lib.s
+++ b/test/COFF/pdb-lib.s
@@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o foo.obj
# RUN: llc %S/Inputs/bar.ll -filetype=obj -mtriple=i686-windows-msvc -o bar.obj
# RUN: llvm-lib bar.obj -out:bar.lib
-# RUN: lld-link -debug -pdb:foo.pdb foo.obj bar.lib -out:foo.exe -entry:main
+# RUN: lld-link -safeseh:no -debug -pdb:foo.pdb foo.obj bar.lib -out:foo.exe -entry:main
# RUN: llvm-pdbutil dump -modules %t/foo.pdb | FileCheck %s
# Make sure that the PDB has module descriptors. foo.obj and bar.lib should be
diff --git a/test/COFF/pdb-safeseh.yaml b/test/COFF/pdb-safeseh.yaml
index 27948e38d..cc7ddb19a 100644
--- a/test/COFF/pdb-safeseh.yaml
+++ b/test/COFF/pdb-safeseh.yaml
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t.obj
-# RUN: lld-link -debug -entry:main -out:%t.exe -pdb:%t.pdb %t.obj
+# RUN: lld-link -safeseh:no -debug -entry:main -out:%t.exe -pdb:%t.pdb %t.obj
# RUN: llvm-pdbutil dump -globals %t.pdb | FileCheck %s
# There is an S_GDATA32 symbol record with .secrel32 and .secidx relocations in
diff --git a/test/COFF/pdb-unknown-subsection.s b/test/COFF/pdb-unknown-subsection.s
index b64ed0373..10ffa46de 100644
--- a/test/COFF/pdb-unknown-subsection.s
+++ b/test/COFF/pdb-unknown-subsection.s
@@ -3,7 +3,7 @@
# REQUIRES: x86
# RUN: llvm-mc -triple=i386-pc-win32 -filetype=obj -o %t.obj %s
-# RUN: lld-link -subsystem:console -debug -nodefaultlib -entry:foo -out:%t.exe -pdb:%t.pdb %t.obj 2>&1 | FileCheck %s --check-prefix=WARNING
+# 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
# RUN: llvm-pdbutil dump -symbols %t.pdb | FileCheck %s
# WARNING-NOT: ignoring unknown
diff --git a/test/COFF/reloc-x86.test b/test/COFF/reloc-x86.test
index bd500be16..99547d1cd 100644
--- a/test/COFF/reloc-x86.test
+++ b/test/COFF/reloc-x86.test
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /out:%t.exe /entry:main /base:0x400000 %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe /entry:main /base:0x400000 %t.obj
# RUN: llvm-objdump -d %t.exe | FileCheck %s
# CHECK: .text:
diff --git a/test/COFF/safeseh-no.s b/test/COFF/safeseh-no.s
new file mode 100644
index 000000000..2a301a3ba
--- /dev/null
+++ b/test/COFF/safeseh-no.s
@@ -0,0 +1,56 @@
+# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t.obj
+# RUN: not lld-link %t.obj -safeseh -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERROR
+# safe seh should be on by default.
+# RUN: not lld-link %t.obj -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERROR
+# RUN: lld-link %t.obj -safeseh:no -out:%t.exe -entry:main
+# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
+# -lldmingw should also turn off safeseh by default.
+# RUN: lld-link %t.obj -lldmingw -out:%t.exe -entry:main
+# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
+
+# ERROR: /safeseh: {{.*}}safeseh-no.s.tmp.obj is not compatible with SEH
+
+# CHECK: Characteristics [
+# CHECK-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH
+# CHECK: ]
+# CHECK: LoadConfig [
+# CHECK: Size: 0x48
+# CHECK: SEHandlerTable: 0x0
+# CHECK: SEHandlerCount: 0
+# CHECK: ]
+# CHECK-NOT: SEHTable
+
+
+# Explicitly mark the object as not having safeseh. LLD should error unless
+# -safeseh:no is passed.
+ .def @feat.00; .scl 3; .type 0; .endef
+ .globl @feat.00
+@feat.00 = 0
+
+ .def _main;
+ .scl 2;
+ .type 32;
+ .endef
+ .section .text,"xr",one_only,_main
+ .globl _main
+_main:
+ movl $42, %eax
+ ret
+
+# Add a handler to create an .sxdata section, which -safeseh:no should ignore.
+ .def _my_handler; .scl 3; .type 32;
+ .endef
+ .section .text,"xr",one_only,_my_handler
+_my_handler:
+ ret
+.safeseh _my_handler
+
+
+ .section .rdata,"dr"
+.globl __load_config_used
+__load_config_used:
+ .long 72
+ .fill 60, 1, 0
+ .long ___safe_se_handler_table
+ .long ___safe_se_handler_count
+
diff --git a/test/COFF/subsystem-drectve.test b/test/COFF/subsystem-drectve.test
index 45d48518a..68630eb2d 100644
--- a/test/COFF/subsystem-drectve.test
+++ b/test/COFF/subsystem-drectve.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /dll /noentry /out:%t.dll %t.obj
+# RUN: lld-link -safeseh:no /dll /noentry /out:%t.dll %t.obj
# RUN: llvm-readobj --file-headers %t.dll | FileCheck %s
# CHECK: MajorOperatingSystemVersion: 42
diff --git a/test/COFF/subsystem-inference32.test b/test/COFF/subsystem-inference32.test
index 23bcf0da6..d21355078 100644
--- a/test/COFF/subsystem-inference32.test
+++ b/test/COFF/subsystem-inference32.test
@@ -1,17 +1,17 @@
# RUN: sed -e s/ENTRYNAME/_main/ %s | yaml2obj > %t.obj
-# RUN: lld-link /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=MAIN %s
# RUN: sed s/ENTRYNAME/_wmain/ %s | yaml2obj > %t.obj
-# RUN: lld-link /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WMAIN %s
# RUN: sed s/ENTRYNAME/_WinMain@16/ %s | yaml2obj > %t.obj
-# RUN: lld-link /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
# RUN: sed s/ENTRYNAME/_wWinMain@16/ %s | yaml2obj > %t.obj
-# RUN: lld-link /out:%t.exe %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WWINMAIN %s
# MAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
diff --git a/test/COFF/tls32.test b/test/COFF/tls32.test
index f3db2615e..462cec06b 100644
--- a/test/COFF/tls32.test
+++ b/test/COFF/tls32.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj < %s > %t.obj
-# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: lld-link -safeseh:no /out:%t.exe /entry:main %t.obj
# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
# CHECK: TLSTableRVA: 0x1000