[PATCH] D47565: Fix /WholeArchive bug.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 30 16:52:31 PDT 2018


ruiu created this revision.
ruiu added a reviewer: rnk.

`lld-link foo.lib /wholearchive:foo.lib` should work the same way as
`lld-link /wholearchive:foo.lib foo.lib`. Previously, /wholearchive in
the former case was ignored.


https://reviews.llvm.org/D47565

Files:
  lld/COFF/Driver.cpp
  lld/test/COFF/wholearchive.s


Index: lld/test/COFF/wholearchive.s
===================================================================
--- lld/test/COFF/wholearchive.s
+++ lld/test/COFF/wholearchive.s
@@ -10,6 +10,9 @@
 # RUN: lld-link -dll -out:%t.dll -entry:main %t.main.obj -wholearchive %t.archive.lib -implib:%t.lib
 # RUN: llvm-readobj %t.lib | FileCheck %s -check-prefix CHECK-IMPLIB
 
+# RUN: lld-link -dll -out:%t.dll -entry:main %t.main.obj %t.archive.lib -wholearchive:%t.archive.lib -implib:%t.lib
+# RUN: llvm-readobj %t.lib | FileCheck %s -check-prefix CHECK-IMPLIB
+
 # CHECK-IMPLIB: Symbol: __imp_exportfn3
 # CHECK-IMPLIB: Symbol: exportfn3
 
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1229,22 +1229,19 @@
   if (errorCount())
     return;
 
-  bool WholeArchiveFlag = Args.hasArg(OPT_wholearchive_flag);
+  DenseSet<StringRef> WholeArchive;
+  for (auto *Arg : Args.filtered(OPT_wholearchive_file))
+    WholeArchive.insert(Arg->getValue());
+
   // Create a list of input files. Files can be given as arguments
   // for /defaultlib option.
   std::vector<MemoryBufferRef> MBs;
-  for (auto *Arg : Args.filtered(OPT_INPUT, OPT_wholearchive_file)) {
-    switch (Arg->getOption().getID()) {
-    case OPT_INPUT:
-      if (Optional<StringRef> Path = findFile(Arg->getValue()))
-        enqueuePath(*Path, WholeArchiveFlag);
-      break;
-    case OPT_wholearchive_file:
-      if (Optional<StringRef> Path = findFile(Arg->getValue()))
-        enqueuePath(*Path, true);
-      break;
-    }
-  }
+
+  for (auto *Arg : Args.filtered(OPT_INPUT, OPT_wholearchive_file))
+    if (Optional<StringRef> Path = findFile(Arg->getValue()))
+      enqueuePath(*Path, Args.hasArg(OPT_wholearchive_flag) ||
+                             WholeArchive.count(Arg->getValue()));
+
   for (auto *Arg : Args.filtered(OPT_defaultlib))
     if (Optional<StringRef> Path = findLib(Arg->getValue()))
       enqueuePath(*Path, false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47565.149221.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180530/99a93892/attachment.bin>


More information about the llvm-commits mailing list