[PATCH] D40019: [LLD] [MinGW] Implement the --[no-]gc-sections and --icf options

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 00:21:01 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL318283: [MinGW] Implement the --[no-]gc-sections and --icf options (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D40019?vs=122970&id=122977#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40019

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


Index: lld/trunk/MinGW/Options.td
===================================================================
--- lld/trunk/MinGW/Options.td
+++ lld/trunk/MinGW/Options.td
@@ -11,14 +11,17 @@
   HelpText<"Name of entry point symbol">;
 def export_all_symbols: F<"export-all-symbols">,
     HelpText<"Export all symbols even if a def file or dllexport attributes are used">;
+def gc_sections: F<"gc-sections">, HelpText<"Remove unused sections">;
+def icf: J<"icf=">, HelpText<"Identical code folding">;
 def image_base: S<"image-base">, HelpText<"Base address of the program">;
 def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
   HelpText<"Root name of library to use">;
 def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
 def no_whole_archive: F<"no-whole-archive">,
     HelpText<"No longer include all object files for following archives">;
 def large_address_aware: Flag<["--"], "large-address-aware">,
     HelpText<"Enable large addresses">;
+def no_gc_sections: F<"no-gc-sections">, HelpText<"Don't remove unused sections">;
 def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
   HelpText<"Path to file to write output">;
 def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">;
Index: lld/trunk/MinGW/Driver.cpp
===================================================================
--- lld/trunk/MinGW/Driver.cpp
+++ lld/trunk/MinGW/Driver.cpp
@@ -161,6 +161,23 @@
 
   Add(Args.hasArg(OPT_dynamicbase) ? "-dynamicbase" : "-dynamicbase:no");
 
+  if (Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false))
+    Add("-opt:ref");
+  else
+    Add("-opt:noref");
+
+  if (auto *A = Args.getLastArg(OPT_icf)) {
+    StringRef S = A->getValue();
+    if (S == "all")
+      Add("-opt:icf");
+    else if (S == "safe" || S == "none")
+      Add("-opt:noicf");
+    else
+      error("unknown parameter: --icf=" + S);
+  } else {
+    Add("-opt:noicf");
+  }
+
   if (auto *A = Args.getLastArg(OPT_m)) {
     StringRef S = A->getValue();
     if (S == "i386pe")
Index: lld/trunk/test/MinGW/driver.test
===================================================================
--- lld/trunk/test/MinGW/driver.test
+++ lld/trunk/test/MinGW/driver.test
@@ -105,3 +105,22 @@
 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
 IMAGE-BASE: -base:0x1230000
+
+RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix NO-GC-SECTIONS %s
+RUN: ld.lld -### -m i386pep foo.o --gc-sections --no-gc-sections | FileCheck -check-prefix NO-GC-SECTIONS %s
+NO-GC-SECTIONS: -opt:noref
+
+RUN: ld.lld -### -m i386pep foo.o --gc-sections | FileCheck -check-prefix GC-SECTIONS %s
+RUN: ld.lld -### -m i386pep foo.o -gc-sections | FileCheck -check-prefix GC-SECTIONS %s
+GC-SECTIONS: -opt:ref
+
+RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix ICF-NONE %s
+RUN: ld.lld -### -m i386pep foo.o --icf=none | FileCheck -check-prefix ICF-NONE %s
+RUN: ld.lld -### -m i386pep foo.o -icf=none | FileCheck -check-prefix ICF-NONE %s
+RUN: ld.lld -### -m i386pep foo.o --icf=safe | FileCheck -check-prefix ICF-NONE %s
+RUN: ld.lld -### -m i386pep foo.o -icf=safe | FileCheck -check-prefix ICF-NONE %s
+ICF-NONE: -opt:noicf
+
+RUN: ld.lld -### -m i386pep foo.o --icf=all | FileCheck -check-prefix ICF %s
+RUN: ld.lld -### -m i386pep foo.o -icf=all | FileCheck -check-prefix ICF %s
+ICF: -opt:icf


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40019.122977.patch
Type: text/x-patch
Size: 3479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171115/507b09d1/attachment.bin>


More information about the llvm-commits mailing list