[PATCH] D37769: [LLD] [MinGW] Add support for the options --[no-]whole-archive

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 13:50:46 PDT 2017


mstorsjo created this revision.

https://reviews.llvm.org/D37769

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


Index: test/MinGW/driver.test
===================================================================
--- test/MinGW/driver.test
+++ test/MinGW/driver.test
@@ -47,3 +47,6 @@
 
 RUN: ld.lld -### -shared -m i386pe -e _DllMainCRTStartup at 12 foo.o | FileCheck -check-prefix I386-ENTRY %s
 I386-ENTRY: -entry:DllMainCRTStartup at 12
+
+RUN: ld.lld -### -shared -m i386pep foo.o --whole-archive bar.a --no-whole-archive baz.a | FileCheck -check-prefix WHOLE-ARCHIVE %s
+WHOLE-ARCHIVE: foo.o -wholearchive:bar.a baz.a
Index: MinGW/Options.td
===================================================================
--- MinGW/Options.td
+++ MinGW/Options.td
@@ -12,12 +12,16 @@
   HelpText<"Root name of library to use">;
 def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
 def mllvm: S<"mllvm">;
+def no_whole_archive: F<"no-whole-archive">,
+    HelpText<"No longer include all object files for following archives">;
 def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
   HelpText<"Path to file to write output">;
 def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">;
 def shared: F<"shared">, HelpText<"Build a shared object">;
 def subs: Separate<["--"], "subsystem">, HelpText<"Specify subsystem">;
 def stack: Separate<["--"], "stack">;
+def whole_archive: F<"whole-archive">,
+    HelpText<"Include all object files for following archives">;
 def verbose: F<"verbose">, HelpText<"Verbose mode">;
 
 // LLD specific options
Index: MinGW/Driver.cpp
===================================================================
--- MinGW/Driver.cpp
+++ MinGW/Driver.cpp
@@ -172,11 +172,24 @@
   for (auto *A : Args.filtered(OPT_L))
     SearchPaths.push_back(A->getValue());
 
-  for (auto *A : Args.filtered(OPT_INPUT, OPT_l)) {
-    if (A->getOption().getUnaliasedOption().getID() == OPT_INPUT)
-      Add(A->getValue());
-    else
-      Add(searchLibrary(A->getValue(), SearchPaths, Args.hasArg(OPT_Bstatic)));
+  StringRef Prefix = "";
+  for (auto *A : Args.filtered(OPT_INPUT, OPT_l, OPT_whole_archive,
+                               OPT_no_whole_archive)) {
+    switch (A->getOption().getID()) {
+    case OPT_INPUT:
+      Add(Prefix + StringRef(A->getValue()));
+      break;
+    case OPT_l:
+      Add(Prefix +
+          searchLibrary(A->getValue(), SearchPaths, Args.hasArg(OPT_Bstatic)));
+      break;
+    case OPT_whole_archive:
+      Prefix = "-wholearchive:";
+      break;
+    case OPT_no_whole_archive:
+      Prefix = "";
+      break;
+    }
   }
 
   if (Args.hasArg(OPT_verbose))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37769.114902.patch
Type: text/x-patch
Size: 2541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170912/252e397b/attachment.bin>


More information about the llvm-commits mailing list