Index: lld/COFF/Config.h =================================================================== --- lld/COFF/Config.h +++ lld/COFF/Config.h @@ -194,6 +194,7 @@ bool WarnMissingOrderSymbol = true; bool WarnLocallyDefinedImported = true; bool Incremental = true; + bool IntegrityCheck = false; bool KillAt = false; bool Repro = false; }; Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -1196,6 +1196,8 @@ Args.hasFlag(OPT_incremental, OPT_incremental_no, !Config->DoGC && !Config->DoICF && !Args.hasArg(OPT_order) && !Args.hasArg(OPT_profile)); + Config->IntegrityCheck = + Args.hasFlag(OPT_integritycheck, OPT_integritycheck_no, false); Config->NxCompat = Args.hasFlag(OPT_nxcompat, OPT_nxcompat_no, true); Config->TerminalServerAware = !Config->DLL && Args.hasFlag(OPT_tsaware, OPT_tsaware_no, true); Index: lld/COFF/Options.td =================================================================== --- lld/COFF/Options.td +++ lld/COFF/Options.td @@ -117,7 +117,10 @@ "Disable 64-bit ASLR">; defm incremental : B<"incremental", "Keep original import library if contents are unchanged", - "Replace import library file even if contents are unchanged">; + "Overwrite import library even if contents are unchanged">; +defm integritycheck : B<"integritycheck", + "Set FORCE_INTEGRITY bit in PE header", + "No effect (default)">; defm largeaddressaware : B<"largeaddressaware", "Enable large addresses (default on 64-bit)", "Disable large addresses (default on 32-bit)">; Index: lld/COFF/Writer.cpp =================================================================== --- lld/COFF/Writer.cpp +++ lld/COFF/Writer.cpp @@ -859,6 +859,8 @@ PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION; if (Config->GuardCF != GuardCFLevel::Off) PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_GUARD_CF; + if (Config->IntegrityCheck) + PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY; if (SetNoSEHCharacteristic) PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_SEH; if (Config->TerminalServerAware) Index: lld/test/COFF/options.test =================================================================== --- lld/test/COFF/options.test +++ lld/test/COFF/options.test @@ -30,6 +30,16 @@ # RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOENT %s NOENT-NOT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA +# RUN: lld-link /out:%t.exe /entry:main /integritycheck %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=INT %s +INT: IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY + +# RUN: lld-link /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOINT %s +# RUN: lld-link /out:%t.exe /integritycheck:no /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOINT %s +NOINT-NOT: IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY + # RUN: lld-link /out:%t.exe /entry:main %t.obj # RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NXCOMPAT %s # RUN: lld-link /out:%t.exe /entry:main /nxcompat %t.obj