Index: COFF/Config.h =================================================================== --- COFF/Config.h +++ COFF/Config.h @@ -173,6 +173,7 @@ bool HighEntropyVA = false; bool AppContainer = false; bool MinGW = false; + bool NoSEH = false; }; extern Configuration *Config; Index: COFF/Driver.cpp =================================================================== --- COFF/Driver.cpp +++ COFF/Driver.cpp @@ -1018,6 +1018,7 @@ Config->AllowBind = Args.hasFlag(OPT_allowbind, OPT_allowbind_no, true); Config->AllowIsolation = Args.hasFlag(OPT_allowisolation, OPT_allowisolation_no, true); + Config->NoSEH = Args.hasFlag(OPT_noseh, OPT_noseh_no, false); Config->NxCompat = Args.hasFlag(OPT_nxcompat, OPT_nxcompat_no, true); Config->TerminalServerAware = Args.hasFlag(OPT_tsaware, OPT_tsaware_no, true); Config->DebugDwarf = Args.hasArg(OPT_debug_dwarf); Index: COFF/Options.td =================================================================== --- COFF/Options.td +++ COFF/Options.td @@ -104,6 +104,9 @@ defm largeaddressaware : B<"largeaddressaware", "Enable large addresses (default on 64-bit)", "Disable large addresses (default on 32-bit)">; +defm noseh : B<"noseh", + "Set the 'No structured exception handler' flag", + "Allow using structured exception handlers">; defm nxcompat : B<"nxcompat", "Enable data execution prevention (default)", "Disable data execution provention">; defm safeseh : B<"safeseh", Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -688,6 +688,8 @@ PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT; if (!Config->AllowIsolation) PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION; + if (Config->NoSEH) + PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_SEH; if (Config->TerminalServerAware) PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE; PE->NumberOfRvaAndSize = NumberfOfDataDirectory; Index: MinGW/Driver.cpp =================================================================== --- MinGW/Driver.cpp +++ MinGW/Driver.cpp @@ -154,6 +154,8 @@ Add("-debug:dwarf"); if (Args.hasArg(OPT_large_address_aware)) Add("-largeaddressaware"); + if (Args.hasArg(OPT_no_seh)) + Add("-noseh"); if (Args.getLastArgValue(OPT_m) != "thumb2pe" && Args.getLastArgValue(OPT_m) != "arm64pe" && !Args.hasArg(OPT_dynamicbase)) Index: MinGW/Options.td =================================================================== --- MinGW/Options.td +++ MinGW/Options.td @@ -22,6 +22,7 @@ def large_address_aware: Flag<["--"], "large-address-aware">, HelpText<"Enable large addresses">; def no_gc_sections: F<"no-gc-sections">, HelpText<"Don't remove unused sections">; +def no_seh: F<"no-seh">, HelpText<"Set the 'No SEH' flag">; def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"">, HelpText<"Path to file to write output">; def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">; Index: test/COFF/options.test =================================================================== --- test/COFF/options.test +++ test/COFF/options.test @@ -49,3 +49,13 @@ # RUN: lld-link /tsaware:no /out:%t.exe /entry:main %t.obj # RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOTSAWARE %s NOTSAWARE-NOT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE + +# RUN: lld-link /out:%t.exe /entry:main /noseh %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOSEH %s +NOSEH: IMAGE_DLL_CHARACTERISTICS_NO_SEH + +# RUN: lld-link /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NONOSEH %s +# RUN: lld-link /tsaware:no /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NONOSEH %s +NONOSEH-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH Index: test/MinGW/driver.test =================================================================== --- test/MinGW/driver.test +++ test/MinGW/driver.test @@ -124,3 +124,7 @@ RUN: ld.lld -### -m i386pep foo.o --icf=all | FileCheck -check-prefix ICF %s RUN: ld.lld -### -m i386pep foo.o -icf=all | FileCheck -check-prefix ICF %s ICF: -opt:icf + +RUN: ld.lld -### -m i386pep foo.o -no-seh | FileCheck -check-prefix NO-SEH %s +RUN: ld.lld -### -m i386pep foo.o --no-seh | FileCheck -check-prefix NO-SEH %s +NO-SEH: -noseh