[lld] r366238 - [COFF] Implement /safeseh:no and check @feat.00 flags by default

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 11:17:33 PDT 2019


Author: rnk
Date: Tue Jul 16 11:17:33 2019
New Revision: 366238

URL: http://llvm.org/viewvc/llvm-project?rev=366238&view=rev
Log:
[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

Added:
    lld/trunk/test/COFF/safeseh-no.s
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Writer.cpp
    lld/trunk/test/COFF/allow-unknown-debug-info.test
    lld/trunk/test/COFF/constant.test
    lld/trunk/test/COFF/def-export-stdcall.s
    lld/trunk/test/COFF/delayimports32.test
    lld/trunk/test/COFF/dllexport.s
    lld/trunk/test/COFF/entry-drectve.test
    lld/trunk/test/COFF/entry-inference332.test
    lld/trunk/test/COFF/exclude-all.s
    lld/trunk/test/COFF/export-all.s
    lld/trunk/test/COFF/export-stdcall.s
    lld/trunk/test/COFF/export32.test
    lld/trunk/test/COFF/fixed.test
    lld/trunk/test/COFF/gfids-relocations32.s
    lld/trunk/test/COFF/hello32.test
    lld/trunk/test/COFF/largeaddressaware.test
    lld/trunk/test/COFF/loadcfg32.test
    lld/trunk/test/COFF/locally-imported32.test
    lld/trunk/test/COFF/machine.test
    lld/trunk/test/COFF/no-ipi-stream.test
    lld/trunk/test/COFF/order-i386.test
    lld/trunk/test/COFF/pdb-debug-f.s
    lld/trunk/test/COFF/pdb-lib.s
    lld/trunk/test/COFF/pdb-safeseh.yaml
    lld/trunk/test/COFF/pdb-unknown-subsection.s
    lld/trunk/test/COFF/reloc-x86.test
    lld/trunk/test/COFF/subsystem-drectve.test
    lld/trunk/test/COFF/subsystem-inference32.test
    lld/trunk/test/COFF/tls32.test

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Tue Jul 16 11:17:33 2019
@@ -132,6 +132,7 @@ struct Configuration {
   GuardCFLevel guardCF = GuardCFLevel::Off;
 
   // Used for SafeSEH.
+  bool safeSEH = false;
   Symbol *sehTable = nullptr;
   Symbol *sehCount = nullptr;
 

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Tue Jul 16 11:17:33 2019
@@ -1556,6 +1556,11 @@ void LinkerDriver::link(ArrayRef<const c
   }
   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 c
   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.

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Tue Jul 16 11:17:33 2019
@@ -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");
 

Modified: lld/trunk/test/COFF/allow-unknown-debug-info.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/allow-unknown-debug-info.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/allow-unknown-debug-info.test (original)
+++ lld/trunk/test/COFF/allow-unknown-debug-info.test Tue Jul 16 11:17:33 2019
@@ -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
 

Modified: lld/trunk/test/COFF/constant.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/constant.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/constant.test (original)
+++ lld/trunk/test/COFF/constant.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/def-export-stdcall.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/def-export-stdcall.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/def-export-stdcall.s (original)
+++ lld/trunk/test/COFF/def-export-stdcall.s Tue Jul 16 11:17:33 2019
@@ -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 at 8\n  @fastcall at 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
 

Modified: lld/trunk/test/COFF/delayimports32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/delayimports32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/delayimports32.test (original)
+++ lld/trunk/test/COFF/delayimports32.test Tue Jul 16 11:17:33 2019
@@ -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 at 0 /alternatename:___delayLoadHelper2 at 8=_main at 0 \
 # RUN:   /delayload:std32.dll /out:%t.exe
 # RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s

Modified: lld/trunk/test/COFF/dllexport.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/dllexport.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/dllexport.s (original)
+++ lld/trunk/test/COFF/dllexport.s Tue Jul 16 11:17:33 2019
@@ -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
 

Modified: lld/trunk/test/COFF/entry-drectve.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/entry-drectve.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/entry-drectve.test (original)
+++ lld/trunk/test/COFF/entry-drectve.test Tue Jul 16 11:17:33 2019
@@ -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:

Modified: lld/trunk/test/COFF/entry-inference332.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/entry-inference332.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/entry-inference332.test (original)
+++ lld/trunk/test/COFF/entry-inference332.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/exclude-all.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/exclude-all.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/exclude-all.s (original)
+++ lld/trunk/test/COFF/exclude-all.s Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/export-all.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export-all.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/export-all.s (original)
+++ lld/trunk/test/COFF/export-all.s Tue Jul 16 11:17:33 2019
@@ -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
 

Modified: lld/trunk/test/COFF/export-stdcall.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export-stdcall.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/export-stdcall.s (original)
+++ lld/trunk/test/COFF/export-stdcall.s Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/export32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/export32.test (original)
+++ lld/trunk/test/COFF/export32.test Tue Jul 16 11:17:33 2019
@@ -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, at 5 \
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1, at 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, at 5,noname /export:exportfn2
+# RUN: lld-link -safeseh:no /out:%t.dll /dll %t.obj /export:exportfn1, at 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, at 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:

Modified: lld/trunk/test/COFF/fixed.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/fixed.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/fixed.test (original)
+++ lld/trunk/test/COFF/fixed.test Tue Jul 16 11:17:33 2019
@@ -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 at 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 at 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

Modified: lld/trunk/test/COFF/gfids-relocations32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/gfids-relocations32.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/gfids-relocations32.s (original)
+++ lld/trunk/test/COFF/gfids-relocations32.s Tue Jul 16 11:17:33 2019
@@ -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.

Modified: lld/trunk/test/COFF/hello32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/hello32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/hello32.test (original)
+++ lld/trunk/test/COFF/hello32.test Tue Jul 16 11:17:33 2019
@@ -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 at 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:   ]

Modified: lld/trunk/test/COFF/largeaddressaware.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/largeaddressaware.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/largeaddressaware.test (original)
+++ lld/trunk/test/COFF/largeaddressaware.test Tue Jul 16 11:17:33 2019
@@ -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 at 0 /out:%t.exe /largeaddressaware
 # RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=HEADER %s
 

Modified: lld/trunk/test/COFF/loadcfg32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/loadcfg32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/loadcfg32.test (original)
+++ lld/trunk/test/COFF/loadcfg32.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/locally-imported32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/locally-imported32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/locally-imported32.test (original)
+++ lld/trunk/test/COFF/locally-imported32.test Tue Jul 16 11:17:33 2019
@@ -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:

Modified: lld/trunk/test/COFF/machine.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/machine.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/machine.test (original)
+++ lld/trunk/test/COFF/machine.test Tue Jul 16 11:17:33 2019
@@ -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
 

Modified: lld/trunk/test/COFF/no-ipi-stream.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/no-ipi-stream.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/no-ipi-stream.test (original)
+++ lld/trunk/test/COFF/no-ipi-stream.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/order-i386.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/order-i386.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/order-i386.test (original)
+++ lld/trunk/test/COFF/order-i386.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/pdb-debug-f.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-debug-f.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-debug-f.s (original)
+++ lld/trunk/test/COFF/pdb-debug-f.s Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/pdb-lib.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-lib.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-lib.s (original)
+++ lld/trunk/test/COFF/pdb-lib.s Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/pdb-safeseh.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-safeseh.yaml?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-safeseh.yaml (original)
+++ lld/trunk/test/COFF/pdb-safeseh.yaml Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/pdb-unknown-subsection.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-unknown-subsection.s?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-unknown-subsection.s (original)
+++ lld/trunk/test/COFF/pdb-unknown-subsection.s Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/reloc-x86.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/reloc-x86.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/reloc-x86.test (original)
+++ lld/trunk/test/COFF/reloc-x86.test Tue Jul 16 11:17:33 2019
@@ -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:

Added: lld/trunk/test/COFF/safeseh-no.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/safeseh-no.s?rev=366238&view=auto
==============================================================================
--- lld/trunk/test/COFF/safeseh-no.s (added)
+++ lld/trunk/test/COFF/safeseh-no.s Tue Jul 16 11:17:33 2019
@@ -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
+ at 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
+

Modified: lld/trunk/test/COFF/subsystem-drectve.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/subsystem-drectve.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/subsystem-drectve.test (original)
+++ lld/trunk/test/COFF/subsystem-drectve.test Tue Jul 16 11:17:33 2019
@@ -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

Modified: lld/trunk/test/COFF/subsystem-inference32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/subsystem-inference32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/subsystem-inference32.test (original)
+++ lld/trunk/test/COFF/subsystem-inference32.test Tue Jul 16 11:17:33 2019
@@ -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 at 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 at 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

Modified: lld/trunk/test/COFF/tls32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/tls32.test?rev=366238&r1=366237&r2=366238&view=diff
==============================================================================
--- lld/trunk/test/COFF/tls32.test (original)
+++ lld/trunk/test/COFF/tls32.test Tue Jul 16 11:17:33 2019
@@ -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




More information about the llvm-commits mailing list