Skip to content

Commit e72403f

Browse files
committed
[LLD] [MinGW] Enable dynamicbase by default
This matches lld-link's own default. Add a new command line option --no-dynamicbase for disabling it. (Unfortunately, GNU ld doesn't yet have a matching --no-dynamicbase option, as that's the default there.) Differential Revision: https://reviews.llvm.org/D86654
1 parent c17718e commit e72403f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lld/MinGW/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly,
292292
add("-noseh");
293293

294294
if (args.getLastArgValue(OPT_m) != "thumb2pe" &&
295-
args.getLastArgValue(OPT_m) != "arm64pe" && !args.hasArg(OPT_dynamicbase))
295+
args.getLastArgValue(OPT_m) != "arm64pe" &&
296+
args.hasArg(OPT_no_dynamicbase))
296297
add("-dynamicbase:no");
297298

298299
if (args.hasFlag(OPT_no_insert_timestamp, OPT_insert_timestamp, false))

lld/MinGW/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def disable_auto_import: F<"disable-auto-import">,
3232
HelpText<"Don't automatically import data symbols from other DLLs without dllimport">;
3333
def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">,
3434
HelpText<"Don't do automatic imports that require runtime fixups">;
35-
def dynamicbase: F<"dynamicbase">, HelpText<"Enable ASLR">;
35+
defm dynamicbase: B<"dynamicbase", "Enable ASLR", "Disable ASLR">;
3636
def enable_auto_import: F<"enable-auto-import">,
3737
HelpText<"Automatically import data symbols from other DLLs where needed">;
3838
def enable_runtime_pseudo_reloc: F<"enable-runtime-pseudo-reloc">,

lld/test/MinGW/driver.test

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,18 @@ PDB-DEFAULT-NOT: -pdb:{{.*}}
136136
RUN: ld.lld -### -m i386pep foo.o --large-address-aware | FileCheck -check-prefix LARGE-ADDRESS-AWARE %s
137137
LARGE-ADDRESS-AWARE: -largeaddressaware
138138

139-
RUN: ld.lld -### -m i386pe foo.o | FileCheck -check-prefix DEFAULT-DISABLE-FLAGS %s
140-
RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix DEFAULT-DISABLE-FLAGS %s
141-
DEFAULT-DISABLE-FLAGS: -dynamicbase:no
142-
RUN: ld.lld -### -m i386pe --dynamicbase foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
143-
RUN: ld.lld -### -m i386pep -dynamicbase foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
144-
RUN: ld.lld -### -m thumb2pe foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
145-
RUN: ld.lld -### -m arm64pe foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
146-
NO-DEFAULT-DISABLE-FLAGS-NOT: -dynamicbase:no
139+
RUN: ld.lld -### -m i386pe foo.o --no-dynamicbase | FileCheck -check-prefix DISABLE-DYNAMICBASE %s
140+
DISABLE-DYNAMICBASE: -dynamicbase:no
141+
RUN: ld.lld -### -m i386pe --dynamicbase foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
142+
RUN: ld.lld -### -m i386pep -dynamicbase foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
143+
RUN: ld.lld -### -m i386pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
144+
RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
145+
RUN: ld.lld -### -m thumb2pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
146+
RUN: ld.lld -### -m arm64pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
147+
# On arm, dynamicbase can't be disabled, so --no-dynamicbase is ignored
148+
RUN: ld.lld -### -m thumb2pe foo.o --no-dynamicbase | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
149+
RUN: ld.lld -### -m arm64pe foo.o --no-dynamicbase | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
150+
NO-DISABLE-DYNAMICBASE-NOT: -dynamicbase:no
147151

148152
RUN: ld.lld -### -m i386pep foo.o --image-base 0x1230000 | FileCheck -check-prefix IMAGE-BASE %s
149153
RUN: ld.lld -### -m i386pep foo.o -image-base 0x1230000 | FileCheck -check-prefix IMAGE-BASE %s

0 commit comments

Comments
 (0)