[PATCH] D39353: [lld] Fix --exclude-libs broken when --whole-archive is used

Oleg Ranevskyy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 17:15:55 PDT 2017


iid_iunknown updated this revision to Diff 120515.
iid_iunknown added a comment.

Introducing getArchiveName


Repository:
  rL LLVM

https://reviews.llvm.org/D39353

Files:
  ELF/Driver.cpp
  test/ELF/exclude-libs.s


Index: test/ELF/exclude-libs.s
===================================================================
--- test/ELF/exclude-libs.s
+++ test/ELF/exclude-libs.s
@@ -22,6 +22,12 @@
 // RUN: ld.lld -shared %t.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL
 // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s
 
+// RUN: ld.lld -shared --whole-archive %t.o %t.dir/exc.a -o %t.exe --exclude-libs foo,bar,exc.a
+// RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s
+
+// RUN: ld.lld -shared --whole-archive %t.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL
+// RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s
+
 // DEFAULT: Name: fn
 // EXCLUDE-NOT: Name: fn
 
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -970,21 +970,31 @@
   return Ret;
 }
 
+static StringRef getArchiveName(InputFile *File) {
+  if (isa<ArchiveFile>(File))
+    return File->getName();
+  return File->ArchiveName;
+}
+
 // Handles the -exclude-libs option. If a static library file is specified
 // by the -exclude-libs option, all public symbols from the archive become
 // private unless otherwise specified by version scripts or something.
 // A special library name "ALL" means all archive files.
 //
 // This is not a popular option, but some programs such as bionic libc use it.
+template <class ELFT>
 static void excludeLibs(opt::InputArgList &Args, ArrayRef<InputFile *> Files) {
   DenseSet<StringRef> Libs = getExcludeLibs(Args);
   bool All = Libs.count("ALL");
 
-  for (InputFile *File : Files)
-    if (auto *F = dyn_cast<ArchiveFile>(File))
-      if (All || Libs.count(path::filename(F->getName())))
-        for (SymbolBody *Sym : F->getSymbols())
-          Sym->symbol()->VersionId = VER_NDX_LOCAL;
+  for (InputFile *File : Files) {
+    StringRef ArchiveName = getArchiveName(File);
+    if (!ArchiveName.empty() &&
+        (All || Libs.count(path::filename(ArchiveName))))
+      for (SymbolBody *SymBody : File->getSymbols())
+        if (!SymBody->isLocal())
+          SymBody->symbol()->VersionId = VER_NDX_LOCAL;
+  }
 }
 
 // Do actual linking. Note that when this function is called,
@@ -1067,7 +1077,7 @@
 
   // Handle the -exclude-libs option.
   if (Args.hasArg(OPT_exclude_libs))
-    excludeLibs(Args, Files);
+    excludeLibs<ELFT>(Args, Files);
 
   // Apply version scripts.
   Symtab->scanVersionScript();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39353.120515.patch
Type: text/x-patch
Size: 2525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171027/fa136fb2/attachment.bin>


More information about the llvm-commits mailing list