Skip to content

Commit

Permalink
[LLD] [MinGW] Enable dynamicbase by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mstorsjo committed Aug 27, 2020
1 parent c17718e commit e72403f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lld/MinGW/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly,
add("-noseh");

if (args.getLastArgValue(OPT_m) != "thumb2pe" &&
args.getLastArgValue(OPT_m) != "arm64pe" && !args.hasArg(OPT_dynamicbase))
args.getLastArgValue(OPT_m) != "arm64pe" &&
args.hasArg(OPT_no_dynamicbase))
add("-dynamicbase:no");

if (args.hasFlag(OPT_no_insert_timestamp, OPT_insert_timestamp, false))
Expand Down
2 changes: 1 addition & 1 deletion lld/MinGW/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def disable_auto_import: F<"disable-auto-import">,
HelpText<"Don't automatically import data symbols from other DLLs without dllimport">;
def disable_runtime_pseudo_reloc: F<"disable-runtime-pseudo-reloc">,
HelpText<"Don't do automatic imports that require runtime fixups">;
def dynamicbase: F<"dynamicbase">, HelpText<"Enable ASLR">;
defm dynamicbase: B<"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">,
Expand Down
20 changes: 12 additions & 8 deletions lld/test/MinGW/driver.test
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ PDB-DEFAULT-NOT: -pdb:{{.*}}
RUN: ld.lld -### -m i386pep foo.o --large-address-aware | FileCheck -check-prefix LARGE-ADDRESS-AWARE %s
LARGE-ADDRESS-AWARE: -largeaddressaware

RUN: ld.lld -### -m i386pe foo.o | FileCheck -check-prefix DEFAULT-DISABLE-FLAGS %s
RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix DEFAULT-DISABLE-FLAGS %s
DEFAULT-DISABLE-FLAGS: -dynamicbase:no
RUN: ld.lld -### -m i386pe --dynamicbase foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
RUN: ld.lld -### -m i386pep -dynamicbase foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
RUN: ld.lld -### -m thumb2pe foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
RUN: ld.lld -### -m arm64pe foo.o | FileCheck -check-prefix NO-DEFAULT-DISABLE-FLAGS %s
NO-DEFAULT-DISABLE-FLAGS-NOT: -dynamicbase:no
RUN: ld.lld -### -m i386pe foo.o --no-dynamicbase | FileCheck -check-prefix DISABLE-DYNAMICBASE %s
DISABLE-DYNAMICBASE: -dynamicbase:no
RUN: ld.lld -### -m i386pe --dynamicbase foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m i386pep -dynamicbase foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m i386pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m thumb2pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m arm64pe foo.o | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
# On arm, dynamicbase can't be disabled, so --no-dynamicbase is ignored
RUN: ld.lld -### -m thumb2pe foo.o --no-dynamicbase | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
RUN: ld.lld -### -m arm64pe foo.o --no-dynamicbase | FileCheck -check-prefix NO-DISABLE-DYNAMICBASE %s
NO-DISABLE-DYNAMICBASE-NOT: -dynamicbase:no

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

0 comments on commit e72403f

Please sign in to comment.