Skip to content

Commit f8340c8

Browse files
committed
[LLD] [MinGW] Add more options for disabling flags in the executable
In e72403f, we added the flag "--no-dynamicbase" for disabling the dynamicbase flag which we set by default. At the time, ld.bfd didn't have any corresponding option (as ld.bfd defaulted to not setting the flag). Almost at the same time, corresponding options were added to ld.bfd for disabling it (while it was being enabled by default), with a different name, "--disable-dynamicbase". Thus add the "--disable-dynamicbase" option. Make this default one advertised in the help listing, but keep the "--no-dynamicbase" form as an alias. Also improve checking for the last option set if there are multiple ones on the same command line. Also add corresponding disable options for a lot of other flags that we set by default, also added in ld.bfd in the same commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb Differential Revision: https://reviews.llvm.org/D107930
1 parent 1f87c7c commit f8340c8

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

lld/MinGW/Driver.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,19 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly,
308308
add("-kill-at");
309309
if (args.hasArg(OPT_appcontainer))
310310
add("-appcontainer");
311-
if (args.hasArg(OPT_no_seh))
311+
if (args.hasFlag(OPT_no_seh, OPT_disable_no_seh, false))
312312
add("-noseh");
313313

314314
if (args.getLastArgValue(OPT_m) != "thumb2pe" &&
315315
args.getLastArgValue(OPT_m) != "arm64pe" &&
316-
args.hasArg(OPT_no_dynamicbase))
316+
args.hasFlag(OPT_disable_dynamicbase, OPT_dynamicbase, false))
317317
add("-dynamicbase:no");
318+
if (args.hasFlag(OPT_disable_high_entropy_va, OPT_high_entropy_va, false))
319+
add("-highentropyva:no");
320+
if (args.hasFlag(OPT_disable_nxcompat, OPT_nxcompat, false))
321+
add("-nxcompat:no");
322+
if (args.hasFlag(OPT_disable_tsaware, OPT_tsaware, false))
323+
add("-tsaware:no");
318324

319325
if (args.hasFlag(OPT_no_insert_timestamp, OPT_insert_timestamp, false))
320326
add("-timestamp:0");

lld/MinGW/Options.td

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ multiclass B<string name, string help1, string help2> {
2626
def no_ # NAME: Flag<["--", "-"], "no-" # name>, HelpText<help2>;
2727
}
2828

29+
multiclass B_disable<string name, string help1, string help2> {
30+
def NAME: Flag<["--", "-"], name>, HelpText<help1>;
31+
def disable_ # NAME: Flag<["--", "-"], "disable-" # name>, HelpText<help2>;
32+
}
33+
2934
def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"<dir>">,
3035
HelpText<"Add a directory to the library search path">;
3136
defm allow_multiple_definition: B<"allow-multiple-definition",
@@ -42,7 +47,7 @@ def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">,
4247
HelpText<"Don't do automatic imports that require runtime fixups">;
4348
def disable_stdcall_fixup: F<"disable-stdcall-fixup">,
4449
HelpText<"Don't resolve stdcall/fastcall/vectorcall to undecorated symbols">;
45-
defm dynamicbase: B<"dynamicbase", "Enable ASLR", "Disable ASLR">;
50+
defm dynamicbase: B_disable<"dynamicbase", "Enable ASLR", "Disable ASLR">;
4651
def enable_auto_import: F<"enable-auto-import">,
4752
HelpText<"Automatically import data symbols from other DLLs where needed">;
4853
def enable_runtime_pseudo_reloc: F<"enable-runtime-pseudo-reloc">,
@@ -62,6 +67,8 @@ defm gc_sections: B<"gc-sections",
6267
"Remove unused sections",
6368
"Don't remove unused sections">;
6469
def help: F<"help">, HelpText<"Print option help">;
70+
defm high_entropy_va: B_disable<"high-entropy-va",
71+
"Set the 'high entropy VA' flag", "Don't set the 'high entropy VA' flag">;
6572
defm icf: Eq<"icf", "Identical code folding">;
6673
defm image_base: Eq<"image-base", "Base address of the program">;
6774
defm insert_timestamp: B<"insert-timestamp",
@@ -80,7 +87,10 @@ defm minor_os_version: EqLong<"minor-os-version",
8087
"Set the OS and subsystem minor version">;
8188
defm minor_subsystem_version: EqLong<"minor-subsystem-version",
8289
"Set the OS and subsystem minor version">;
83-
def no_seh: F<"no-seh">, HelpText<"Set the 'no SEH' flag in the executable">;
90+
defm no_seh: B_disable<"no-seh",
91+
"Set the 'no SEH' flag in the executable", "Don't set the 'no SEH' flag">;
92+
defm nxcompat: B_disable<"nxcompat",
93+
"Set the 'nxcompat' flag in the executable", "Don't set the 'nxcompat' flag">;
8494
def large_address_aware: Flag<["--"], "large-address-aware">,
8595
HelpText<"Enable large addresses">;
8696
def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
@@ -99,6 +109,8 @@ defm reproduce: Eq<"reproduce",
99109
"Write a tar file containing input files and command line options to reproduce link">;
100110
defm require_defined: Eq<"require-defined",
101111
"Force symbol to be added to symbol table as an undefined one">;
112+
defm tsaware: B_disable<"tsaware",
113+
"Set the 'Terminal Server aware' flag", "Don't set the 'Terminal Server aware' flag">;
102114
defm undefined: Eq<"undefined", "Include symbol in the link, if available">;
103115
defm whole_archive: B<"whole-archive",
104116
"Include all object files for following archives",
@@ -127,6 +139,7 @@ def alias_Bstatic_dn: Flag<["-"], "dn">, Alias<Bstatic>;
127139
def alias_Bstatic_non_shared: Flag<["-"], "non_shared">, Alias<Bstatic>;
128140
def alias_Bstatic_static: Flag<["-"], "static">, Alias<Bstatic>;
129141
def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
142+
def alias_no_dynamicbase: F<"no-dynamicbase">, Alias<disable_dynamicbase>;
130143
def alias_strip_s: Flag<["-"], "s">, Alias<strip_all>;
131144
def alias_strip_S: Flag<["-"], "S">, Alias<strip_debug>;
132145
def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
@@ -138,14 +151,11 @@ def: F<"disable-auto-image-base">;
138151
def: F<"enable-auto-image-base">;
139152
def: F<"end-group">;
140153
def: Flag<["--"], "full-shutdown">;
141-
def: F<"high-entropy-va">;
142154
defm: EqNoHelp<"major-image-version">;
143155
defm: EqNoHelp<"minor-image-version">;
144156
def: F<"no-undefined">;
145-
def: F<"nxcompat">;
146157
def: F<"pic-executable">;
147158
defm: EqNoHelp<"plugin">;
148159
defm: EqNoHelp<"plugin-opt">;
149160
defm: EqNoHelp<"sysroot">;
150161
def: F<"start-group">;
151-
def: F<"tsaware">;

lld/test/MinGW/driver.test

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ PDB-DEFAULT-NOT: -pdb:{{.*}}
146146
RUN: ld.lld -### -m i386pep foo.o --large-address-aware 2>&1 | FileCheck -check-prefix LARGE-ADDRESS-AWARE %s
147147
LARGE-ADDRESS-AWARE: -largeaddressaware
148148

149-
RUN: ld.lld -### -m i386pe foo.o --no-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s
149+
RUN: ld.lld -### -m i386pe foo.o --dynamicbase --no-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s
150+
RUN: ld.lld -### -m i386pe foo.o --dynamicbase --disable-dynamicbase 2>&1 | FileCheck -check-prefix DISABLE-DYNAMICBASE %s
150151
DISABLE-DYNAMICBASE: -dynamicbase:no
151-
RUN: ld.lld -### -m i386pe --dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
152+
RUN: ld.lld -### -m i386pe --disable-dynamicbase --dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
152153
RUN: ld.lld -### -m i386pep -dynamicbase foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
153154
RUN: ld.lld -### -m i386pe foo.o 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
154155
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
159160
RUN: ld.lld -### -m arm64pe foo.o --no-dynamicbase 2>&1 | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
160161
NO-DISABLE-DYNAMICBASE-NOT: -dynamicbase:no
161162

163+
RUN: ld.lld -### -m i386pe foo.o -high-entropy-va -disable-high-entropy-va 2>&1 | FileCheck -check-prefix DISABLE-HIGH-ENTROPY-VA %s
164+
RUN: ld.lld -### -m i386pe foo.o --high-entropy-va --disable-high-entropy-va 2>&1 | FileCheck -check-prefix DISABLE-HIGH-ENTROPY-VA %s
165+
DISABLE-HIGH-ENTROPY-VA: -highentropyva:no
166+
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
167+
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
168+
NO-DISABLE-HIGH-ENTROPY-VA-NOT: -highentropyva:no
169+
170+
RUN: ld.lld -### -m i386pe foo.o -nxcompat -disable-nxcompat 2>&1 | FileCheck -check-prefix DISABLE-NXCOMPAT %s
171+
RUN: ld.lld -### -m i386pe foo.o --nxcompat --disable-nxcompat 2>&1 | FileCheck -check-prefix DISABLE-NXCOMPAT %s
172+
DISABLE-NXCOMPAT: -nxcompat:no
173+
RUN: ld.lld -### -m i386pe foo.o -disable-nxcompat -nxcompat 2>&1 | FileCheck -check-prefix NO-DISABLE-NXCOMPAT %s
174+
RUN: ld.lld -### -m i386pe foo.o --disable-nxcompat --nxcompat 2>&1 | FileCheck -check-prefix NO-DISABLE-NXCOMPAT %s
175+
NO-DISABLE-NXCOMPAT-NOT: -nxcompat:no
176+
177+
RUN: ld.lld -### -m i386pe foo.o -tsaware -disable-tsaware 2>&1 | FileCheck -check-prefix DISABLE-TSAWARE %s
178+
RUN: ld.lld -### -m i386pe foo.o --tsaware --disable-tsaware 2>&1 | FileCheck -check-prefix DISABLE-TSAWARE %s
179+
DISABLE-TSAWARE: -tsaware:no
180+
RUN: ld.lld -### -m i386pe foo.o -disable-tsaware -tsaware 2>&1 | FileCheck -check-prefix NO-DISABLE-TSAWARE %s
181+
RUN: ld.lld -### -m i386pe foo.o --disable-tsaware --tsaware 2>&1 | FileCheck -check-prefix NO-DISABLE-TSAWARE %s
182+
NO-DISABLE-TSAWARE-NOT: -tsaware:no
183+
162184
RUN: ld.lld -### -m i386pep foo.o --image-base 0x1230000 2>&1 | FileCheck -check-prefix IMAGE-BASE %s
163185
RUN: ld.lld -### -m i386pep foo.o -image-base 0x1230000 2>&1 | FileCheck -check-prefix IMAGE-BASE %s
164186
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
273295
RUN: ld.lld -### -m i386pep foo.o -section-alignment=0x2000 2>&1 | FileCheck -check-prefix ALIGN %s
274296
ALIGN: -align:0x2000
275297

276-
RUN: ld.lld -### -m i386pe foo.o -no-seh 2>&1 | FileCheck -check-prefix NOSEH %s
277-
RUN: ld.lld -### -m i386pe foo.o --no-seh 2>&1 | FileCheck -check-prefix NOSEH %s
298+
RUN: ld.lld -### -m i386pe foo.o -disable-no-seh -no-seh 2>&1 | FileCheck -check-prefix NOSEH %s
299+
RUN: ld.lld -### -m i386pe foo.o --disable-no-seh --no-seh 2>&1 | FileCheck -check-prefix NOSEH %s
300+
RUN: ld.lld -### -m i386pe foo.o -no-seh -disable-no-seh 2>&1 | FileCheck -check-prefix DISABLE-NOSEH %s
301+
RUN: ld.lld -### -m i386pe foo.o --no-seh --disable-no-seh 2>&1 | FileCheck -check-prefix DISABLE-NOSEH %s
278302
NOSEH: -noseh
303+
DISABLE-NOSEH-NOT: -noseh
279304

280305
RUN: ld.lld -### -m i386pep foo.o --no-allow-multiple-definition --allow-multiple-definition 2>&1 | FileCheck -check-prefix ALLOW_MULTIPLE_DEFINITION %s
281306
RUN: ld.lld -### -m i386pep foo.o -no-allow-multiple-definition -allow-multiple-definition 2>&1 | FileCheck -check-prefix ALLOW_MULTIPLE_DEFINITION %s

0 commit comments

Comments
 (0)