Index: lld/trunk/COFF/Config.h =================================================================== --- lld/trunk/COFF/Config.h +++ lld/trunk/COFF/Config.h @@ -132,6 +132,7 @@ GuardCFLevel guardCF = GuardCFLevel::Off; // Used for SafeSEH. + bool safeSEH = false; Symbol *sehTable = nullptr; Symbol *sehCount = nullptr; Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -1556,6 +1556,11 @@ } 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 @@ 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. Index: lld/trunk/COFF/Writer.cpp =================================================================== --- lld/trunk/COFF/Writer.cpp +++ lld/trunk/COFF/Writer.cpp @@ -917,7 +917,7 @@ } // 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::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"); Index: lld/trunk/test/COFF/allow-unknown-debug-info.test =================================================================== --- lld/trunk/test/COFF/allow-unknown-debug-info.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/constant.test =================================================================== --- lld/trunk/test/COFF/constant.test +++ lld/trunk/test/COFF/constant.test @@ -2,5 +2,5 @@ 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 Index: lld/trunk/test/COFF/def-export-stdcall.s =================================================================== --- lld/trunk/test/COFF/def-export-stdcall.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/delayimports32.test =================================================================== --- lld/trunk/test/COFF/delayimports32.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/dllexport.s =================================================================== --- lld/trunk/test/COFF/dllexport.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/entry-drectve.test =================================================================== --- lld/trunk/test/COFF/entry-drectve.test +++ lld/trunk/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: Index: lld/trunk/test/COFF/entry-inference332.test =================================================================== --- lld/trunk/test/COFF/entry-inference332.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/exclude-all.s =================================================================== --- lld/trunk/test/COFF/exclude-all.s +++ lld/trunk/test/COFF/exclude-all.s @@ -25,7 +25,7 @@ # 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 Index: lld/trunk/test/COFF/export-all.s =================================================================== --- lld/trunk/test/COFF/export-all.s +++ lld/trunk/test/COFF/export-all.s @@ -42,7 +42,7 @@ # 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 @@ # 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 @@ # 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 Index: lld/trunk/test/COFF/export-stdcall.s =================================================================== --- lld/trunk/test/COFF/export-stdcall.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/export32.test =================================================================== --- lld/trunk/test/COFF/export32.test +++ lld/trunk/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: Index: lld/trunk/test/COFF/fixed.test =================================================================== --- lld/trunk/test/COFF/fixed.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/gfids-relocations32.s =================================================================== --- lld/trunk/test/COFF/gfids-relocations32.s +++ lld/trunk/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. Index: lld/trunk/test/COFF/hello32.test =================================================================== --- lld/trunk/test/COFF/hello32.test +++ lld/trunk/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: 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: ] Index: lld/trunk/test/COFF/largeaddressaware.test =================================================================== --- lld/trunk/test/COFF/largeaddressaware.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/loadcfg32.test =================================================================== --- lld/trunk/test/COFF/loadcfg32.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/locally-imported32.test =================================================================== --- lld/trunk/test/COFF/locally-imported32.test +++ lld/trunk/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: Index: lld/trunk/test/COFF/machine.test =================================================================== --- lld/trunk/test/COFF/machine.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/no-ipi-stream.test =================================================================== --- lld/trunk/test/COFF/no-ipi-stream.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/order-i386.test =================================================================== --- lld/trunk/test/COFF/order-i386.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/pdb-debug-f.s =================================================================== --- lld/trunk/test/COFF/pdb-debug-f.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/pdb-lib.s =================================================================== --- lld/trunk/test/COFF/pdb-lib.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/pdb-safeseh.yaml =================================================================== --- lld/trunk/test/COFF/pdb-safeseh.yaml +++ lld/trunk/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 Index: lld/trunk/test/COFF/pdb-unknown-subsection.s =================================================================== --- lld/trunk/test/COFF/pdb-unknown-subsection.s +++ lld/trunk/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 Index: lld/trunk/test/COFF/reloc-x86.test =================================================================== --- lld/trunk/test/COFF/reloc-x86.test +++ lld/trunk/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: Index: lld/trunk/test/COFF/safeseh-no.s =================================================================== --- lld/trunk/test/COFF/safeseh-no.s +++ lld/trunk/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 + Index: lld/trunk/test/COFF/subsystem-drectve.test =================================================================== --- lld/trunk/test/COFF/subsystem-drectve.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/subsystem-inference32.test =================================================================== --- lld/trunk/test/COFF/subsystem-inference32.test +++ lld/trunk/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 Index: lld/trunk/test/COFF/tls32.test =================================================================== --- lld/trunk/test/COFF/tls32.test +++ lld/trunk/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