[PATCH] D31011: recommend using llvm-ar when finding undefined references and empty archives

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 14:45:06 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL298124 (authored by inglorion).

Changed prior to commit:
  https://reviews.llvm.org/D31011?vs=92202&id=92208#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31011

Files:
  lld/trunk/ELF/Config.h
  lld/trunk/ELF/InputFiles.cpp
  lld/trunk/ELF/Relocations.cpp


Index: lld/trunk/ELF/InputFiles.cpp
===================================================================
--- lld/trunk/ELF/InputFiles.cpp
+++ lld/trunk/ELF/InputFiles.cpp
@@ -556,8 +556,12 @@
                MB.getBufferIdentifier() + ": failed to parse archive");
 
   // Read the symbol table to construct Lazy objects.
-  for (const Archive::Symbol &Sym : File->symbols())
+  for (const Archive::Symbol &Sym : File->symbols()) {
     Symtab<ELFT>::X->addLazyArchive(this, Sym);
+  }
+
+  if (File->symbols().begin() == File->symbols().end())
+    Config->ArchiveWithoutSymbolsSeen = true;
 }
 
 // Returns a buffer pointing to a member file containing a given symbol.
Index: lld/trunk/ELF/Relocations.cpp
===================================================================
--- lld/trunk/ELF/Relocations.cpp
+++ lld/trunk/ELF/Relocations.cpp
@@ -610,10 +610,21 @@
                     toString(Sym) + "'";
 
   if (Config->UnresolvedSymbols == UnresolvedPolicy::WarnAll ||
-      (Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal))
+      (Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal)) {
     warn(Msg);
-  else
+  } else {
     error(Msg);
+    if (Config->ArchiveWithoutSymbolsSeen) {
+      message("At least one archive listed no symbols in its index."
+              " This can happen when creating archives with a version"
+              " of ar that does not understand the object files in"
+              " the archive. For example, if you are using LLVM"
+              " bitcode objects (such as created by -flto), you may"
+              " need to use llvm-ar or GNU ar with a plugin.");
+      // Reset to false so that we print the message only once.
+      Config->ArchiveWithoutSymbolsSeen = false;
+    }
+  }
 }
 
 template <class RelTy>
Index: lld/trunk/ELF/Config.h
===================================================================
--- lld/trunk/ELF/Config.h
+++ lld/trunk/ELF/Config.h
@@ -98,6 +98,7 @@
   std::vector<SymbolVersion> VersionScriptLocals;
   std::vector<uint8_t> BuildIdVector;
   bool AllowMultipleDefinition;
+  bool ArchiveWithoutSymbolsSeen = false;
   bool AsNeeded = false;
   bool Bsymbolic;
   bool BsymbolicFunctions;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31011.92208.patch
Type: text/x-patch
Size: 2210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170317/fe5d97fd/attachment.bin>


More information about the llvm-commits mailing list