diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 4a3a9ef9be03..7c6b865a2e39 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -308,13 +308,19 @@ bool mingw::link(ArrayRef argsArr, bool canExitEarly, add("-kill-at"); if (args.hasArg(OPT_appcontainer)) add("-appcontainer"); - if (args.hasArg(OPT_no_seh)) + if (args.hasFlag(OPT_no_seh, OPT_disable_no_seh, false)) add("-noseh"); if (args.getLastArgValue(OPT_m) != "thumb2pe" && args.getLastArgValue(OPT_m) != "arm64pe" && - args.hasArg(OPT_no_dynamicbase)) + args.hasFlag(OPT_disable_dynamicbase, OPT_dynamicbase, false)) add("-dynamicbase:no"); + if (args.hasFlag(OPT_disable_high_entropy_va, OPT_high_entropy_va, false)) + add("-highentropyva:no"); + if (args.hasFlag(OPT_disable_nxcompat, OPT_nxcompat, false)) + add("-nxcompat:no"); + if (args.hasFlag(OPT_disable_tsaware, OPT_tsaware, false)) + add("-tsaware:no"); if (args.hasFlag(OPT_no_insert_timestamp, OPT_insert_timestamp, false)) add("-timestamp:0"); diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td index fb178a1438e5..50ac71bced85 100644 --- a/lld/MinGW/Options.td +++ b/lld/MinGW/Options.td @@ -26,6 +26,11 @@ multiclass B { def no_ # NAME: Flag<["--", "-"], "no-" # name>, HelpText; } +multiclass B_disable { + def NAME: Flag<["--", "-"], name>, HelpText; + def disable_ # NAME: Flag<["--", "-"], "disable-" # name>, HelpText; +} + def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"">, HelpText<"Add a directory to the library search path">; defm allow_multiple_definition: B<"allow-multiple-definition", @@ -42,7 +47,7 @@ def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">, HelpText<"Don't do automatic imports that require runtime fixups">; def disable_stdcall_fixup: F<"disable-stdcall-fixup">, HelpText<"Don't resolve stdcall/fastcall/vectorcall to undecorated symbols">; -defm dynamicbase: B<"dynamicbase", "Enable ASLR", "Disable ASLR">; +defm dynamicbase: B_disable<"dynamicbase", "Enable ASLR", "Disable ASLR">; def enable_auto_import: F<"enable-auto-import">, HelpText<"Automatically import data symbols from other DLLs where needed">; def enable_runtime_pseudo_reloc: F<"enable-runtime-pseudo-reloc">, @@ -62,6 +67,8 @@ defm gc_sections: B<"gc-sections", "Remove unused sections", "Don't remove unused sections">; def help: F<"help">, HelpText<"Print option help">; +defm high_entropy_va: B_disable<"high-entropy-va", + "Set the 'high entropy VA' flag", "Don't set the 'high entropy VA' flag">; defm icf: Eq<"icf", "Identical code folding">; defm image_base: Eq<"image-base", "Base address of the program">; defm insert_timestamp: B<"insert-timestamp", @@ -80,7 +87,10 @@ defm minor_os_version: EqLong<"minor-os-version", "Set the OS and subsystem minor version">; defm minor_subsystem_version: EqLong<"minor-subsystem-version", "Set the OS and subsystem minor version">; -def no_seh: F<"no-seh">, HelpText<"Set the 'no SEH' flag in the executable">; +defm no_seh: B_disable<"no-seh", + "Set the 'no SEH' flag in the executable", "Don't set the 'no SEH' flag">; +defm nxcompat: B_disable<"nxcompat", + "Set the 'nxcompat' flag in the executable", "Don't set the 'nxcompat' flag">; def large_address_aware: Flag<["--"], "large-address-aware">, HelpText<"Enable large addresses">; def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"">, @@ -99,6 +109,8 @@ defm reproduce: Eq<"reproduce", "Write a tar file containing input files and command line options to reproduce link">; defm require_defined: Eq<"require-defined", "Force symbol to be added to symbol table as an undefined one">; +defm tsaware: B_disable<"tsaware", + "Set the 'Terminal Server aware' flag", "Don't set the 'Terminal Server aware' flag">; defm undefined: Eq<"undefined", "Include symbol in the link, if available">; defm whole_archive: B<"whole-archive", "Include all object files for following archives", @@ -127,6 +139,7 @@ def alias_Bstatic_dn: Flag<["-"], "dn">, Alias; def alias_Bstatic_non_shared: Flag<["-"], "non_shared">, Alias; def alias_Bstatic_static: Flag<["-"], "static">, Alias; def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias; +def alias_no_dynamicbase: F<"no-dynamicbase">, Alias; def alias_strip_s: Flag<["-"], "s">, Alias; def alias_strip_S: Flag<["-"], "S">, Alias; def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias; @@ -138,14 +151,11 @@ def: F<"disable-auto-image-base">; def: F<"enable-auto-image-base">; def: F<"end-group">; def: Flag<["--"], "full-shutdown">; -def: F<"high-entropy-va">; defm: EqNoHelp<"major-image-version">; defm: EqNoHelp<"minor-image-version">; def: F<"no-undefined">; -def: F<"nxcompat">; def: F<"pic-executable">; defm: EqNoHelp<"plugin">; defm: EqNoHelp<"plugin-opt">; defm: EqNoHelp<"sysroot">; def: F<"start-group">; -def: F<"tsaware">; diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test index a8f4121399f2..007712861411 100644 --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -146,9 +146,10 @@ PDB-DEFAULT-NOT: -pdb:{{.*}} RUN: ld.lld -### -m i386pep foo.o --large-address-aware 2>&1 | FileCheck -check-prefix LARGE-ADDRESS-AWARE %s LARGE-ADDRESS-AWARE: -largeaddressaware -RUN: ld.lld -### -m i386pe foo.o --no-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s +RUN: ld.lld -### -m i386pe foo.o --dynamicbase --no-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s +RUN: ld.lld -### -m i386pe foo.o --dynamicbase --disable-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s DISABLE-DYNAMICBASE: -dynamicbase:no -RUN: ld.lld -### -m i386pe --dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s +RUN: ld.lld -### -m i386pe --disable-dynamicbase --dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s RUN: ld.lld -### -m i386pep -dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s RUN: ld.lld -### -m i386pe foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s RUN: ld.lld -### -m i386pep foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s @@ -159,6 +160,27 @@ RUN: ld.lld -### -m thumb2pe foo.o --no-dynamicbase 2>&1 | FileCheck -check-pref RUN: ld.lld -### -m arm64pe foo.o --no-dynamicbase 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s NO-DISABLE-DYNAMICBASE-NOT: -dynamicbase:no +RUN: ld.lld -### -m i386pe foo.o -high-entropy-va -disable-high-entropy-va 2>&1 | FileCheck -check-prefix DISABLE-HIGH-ENTROPY-VA %s +RUN: ld.lld -### -m i386pe foo.o --high-entropy-va --disable-high-entropy-va 2>&1 | FileCheck -check-prefix DISABLE-HIGH-ENTROPY-VA %s +DISABLE-HIGH-ENTROPY-VA: -highentropyva:no +RUN: ld.lld -### -m i386pe foo.o -disable-high-entropy-va -high-entropy-va 2>&1 | FileCheck -check-prefix NO-DISABLE-HIGH-ENTROPY-VA %s +RUN: ld.lld -### -m i386pe foo.o --disable-high-entropy-va --high-entropy-va 2>&1 | FileCheck -check-prefix NO-DISABLE-HIGH-ENTROPY-VA %s +NO-DISABLE-HIGH-ENTROPY-VA-NOT: -highentropyva:no + +RUN: ld.lld -### -m i386pe foo.o -nxcompat -disable-nxcompat 2>&1 | FileCheck -check-prefix DISABLE-NXCOMPAT %s +RUN: ld.lld -### -m i386pe foo.o --nxcompat --disable-nxcompat 2>&1 | FileCheck -check-prefix DISABLE-NXCOMPAT %s +DISABLE-NXCOMPAT: -nxcompat:no +RUN: ld.lld -### -m i386pe foo.o -disable-nxcompat -nxcompat 2>&1 | FileCheck -check-prefix NO-DISABLE-NXCOMPAT %s +RUN: ld.lld -### -m i386pe foo.o --disable-nxcompat --nxcompat 2>&1 | FileCheck -check-prefix NO-DISABLE-NXCOMPAT %s +NO-DISABLE-NXCOMPAT-NOT: -nxcompat:no + +RUN: ld.lld -### -m i386pe foo.o -tsaware -disable-tsaware 2>&1 | FileCheck -check-prefix DISABLE-TSAWARE %s +RUN: ld.lld -### -m i386pe foo.o --tsaware --disable-tsaware 2>&1 | FileCheck -check-prefix DISABLE-TSAWARE %s +DISABLE-TSAWARE: -tsaware:no +RUN: ld.lld -### -m i386pe foo.o -disable-tsaware -tsaware 2>&1 | FileCheck -check-prefix NO-DISABLE-TSAWARE %s +RUN: ld.lld -### -m i386pe foo.o --disable-tsaware --tsaware 2>&1 | FileCheck -check-prefix NO-DISABLE-TSAWARE %s +NO-DISABLE-TSAWARE-NOT: -tsaware:no + RUN: ld.lld -### -m i386pep foo.o --image-base 0x1230000 2>&1 | FileCheck -check-prefix IMAGE-BASE %s RUN: ld.lld -### -m i386pep foo.o -image-base 0x1230000 2>&1 | FileCheck -check-prefix IMAGE-BASE %s RUN: ld.lld -### -m i386pep foo.o --image-base=0x1230000 2>&1 | FileCheck -check-prefix IMAGE-BASE %s @@ -273,9 +295,12 @@ RUN: ld.lld -### -m i386pep foo.o --section-alignment=0x2000 2>&1 | FileCheck -c RUN: ld.lld -### -m i386pep foo.o -section-alignment=0x2000 2>&1 | FileCheck -check-prefix ALIGN %s ALIGN: -align:0x2000 -RUN: ld.lld -### -m i386pe foo.o -no-seh 2>&1 | FileCheck -check-prefix NOSEH %s -RUN: ld.lld -### -m i386pe foo.o --no-seh 2>&1 | FileCheck -check-prefix NOSEH %s +RUN: ld.lld -### -m i386pe foo.o -disable-no-seh -no-seh 2>&1 | FileCheck -check-prefix NOSEH %s +RUN: ld.lld -### -m i386pe foo.o --disable-no-seh --no-seh 2>&1 | FileCheck -check-prefix NOSEH %s +RUN: ld.lld -### -m i386pe foo.o -no-seh -disable-no-seh 2>&1 | FileCheck -check-prefix DISABLE-NOSEH %s +RUN: ld.lld -### -m i386pe foo.o --no-seh --disable-no-seh 2>&1 | FileCheck -check-prefix DISABLE-NOSEH %s NOSEH: -noseh +DISABLE-NOSEH-NOT: -noseh RUN: ld.lld -### -m i386pep foo.o --no-allow-multiple-definition --allow-multiple-definition 2>&1 | FileCheck -check-prefix ALLOW_MULTIPLE_DEFINITION %s RUN: ld.lld -### -m i386pep foo.o -no-allow-multiple-definition -allow-multiple-definition 2>&1 | FileCheck -check-prefix ALLOW_MULTIPLE_DEFINITION %s