[PATCH] D40017: [LLD] [MinGW] Add support for --dynamicbase, --nxcompat and --tsaware

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 03:38:21 PST 2017


mstorsjo created this revision.

These are special in the sense that lld by default enables them, but GNU ld doesn't. Disable them by default in the MinGW driver and enable only if the option is specified. If enabling an option, explicitly pass the option for enabling it to the COFF driver, to decouple it from the COFF driver defaults.


https://reviews.llvm.org/D40017

Files:
  MinGW/Driver.cpp
  MinGW/Options.td
  test/MinGW/driver.test


Index: test/MinGW/driver.test
===================================================================
--- test/MinGW/driver.test
+++ test/MinGW/driver.test
@@ -92,3 +92,18 @@
 
 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 i386pep foo.o | FileCheck -check-prefix DEFAULT-DISABLE-FLAGS %s
+DEFAULT-DISABLE-FLAGS: -dynamicbase:no -nxcompat:no -tsaware:no
+
+# The extra '-' in the following check patterns is intentional, to make sure
+# that a check for e.g. "-dynamicbase" doesn't match the default
+# "-dynamicbase:no".
+RUN: ld.lld -### -m i386pep foo.o --dynamicbase | FileCheck -check-prefix DYNAMICBASE %s
+DYNAMICBASE: -dynamicbase -
+
+RUN: ld.lld -### -m i386pep foo.o --nxcompat | FileCheck -check-prefix NXCOMPAT %s
+NXCOMPAT: -nxcompat -
+
+RUN: ld.lld -### -m i386pep foo.o --tsaware | FileCheck -check-prefix TSAWARE %s
+TSAWARE: -tsaware -
Index: MinGW/Options.td
===================================================================
--- MinGW/Options.td
+++ MinGW/Options.td
@@ -6,6 +6,7 @@
 
 def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"<dir>">,
   HelpText<"Add a directory to the library search path">;
+def dynamicbase: Flag<["--"], "dynamicbase">, HelpText<"Enable ASLR">;
 def entry: S<"entry">, MetaVarName<"<entry>">,
   HelpText<"Name of entry point symbol">;
 def export_all_symbols: F<"export-all-symbols">,
@@ -17,6 +18,8 @@
     HelpText<"No longer include all object files for following archives">;
 def large_address_aware: Flag<["--"], "large-address-aware">,
     HelpText<"Enable large addresses">;
+def nxcompat: Flag<["--"], "nxcompat">,
+    HelpText<"Enable data execution prevention">;
 def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
   HelpText<"Path to file to write output">;
 def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">;
@@ -27,6 +30,8 @@
 def stack: S<"stack">;
 def strip_all: F<"strip-all">,
     HelpText<"Omit all symbol information from the output binary">;
+def tsaware: Flag<["--"], "tsaware">,
+    HelpText<"Create Terminal Server aware executable">;
 def whole_archive: F<"whole-archive">,
     HelpText<"Include all object files for following archives">;
 def verbose: F<"verbose">, HelpText<"Verbose mode">;
Index: MinGW/Driver.cpp
===================================================================
--- MinGW/Driver.cpp
+++ MinGW/Driver.cpp
@@ -156,6 +156,18 @@
     Add("-debug:dwarf");
   if (Args.hasArg(OPT_large_address_aware))
     Add("-largeaddressaware");
+  if (Args.hasArg(OPT_dynamicbase))
+    Add("-dynamicbase");
+  else
+    Add("-dynamicbase:no");
+  if (Args.hasArg(OPT_nxcompat))
+    Add("-nxcompat");
+  else
+    Add("-nxcompat:no");
+  if (Args.hasArg(OPT_tsaware))
+    Add("-tsaware");
+  else
+    Add("-tsaware:no");
 
   if (auto *A = Args.getLastArg(OPT_m)) {
     StringRef S = A->getValue();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40017.122816.patch
Type: text/x-patch
Size: 2952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171114/cafee728/attachment.bin>


More information about the llvm-commits mailing list