[lld] r248382 - Print more information about undefined symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 07:37:01 PDT 2015


Author: rafael
Date: Wed Sep 23 09:37:01 2015
New Revision: 248382

URL: http://llvm.org/viewvc/llvm-project?rev=248382&view=rev
Log:
Print more information about undefined symbols.

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/undef.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248382&r1=248381&r2=248382&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Sep 23 09:37:01 2015
@@ -288,6 +288,27 @@ void Writer<ELFT>::scanRelocs(const Inpu
   }
 }
 
+template <class ELFT>
+static void undefError(const SymbolTable &S, const SymbolBody &Sym) {
+  typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
+  typedef typename ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
+
+  const Elf_Sym &SymE = cast<ELFSymbolBody<ELFT>>(Sym).Sym;
+  ELFFileBase *SymFile = nullptr;
+
+  for (const std::unique_ptr<ObjectFileBase> &F : S.getObjectFiles()) {
+    const auto &File = cast<ObjectFile<ELFT>>(*F);
+    Elf_Sym_Range Syms = File.getObj()->symbols(File.getSymbolTable());
+    if (&SymE > Syms.begin() && &SymE < Syms.end())
+      SymFile = F.get();
+  }
+  if (SymFile)
+    error(Twine("undefined symbol: ") + Sym.getName() + " in " +
+          SymFile->getName());
+  else
+    error(Twine("undefined symbol: ") + Sym.getName());
+}
+
 // Create output section objects and add them to OutputSections.
 template <class ELFT> void Writer<ELFT>::createSections() {
   SmallDenseMap<SectionKey<ELFT::Is64Bits>, OutputSection<ELFT> *> Map;
@@ -331,7 +352,7 @@ template <class ELFT> void Writer<ELFT>:
     StringRef Name = P.first;
     SymbolBody *Body = P.second->Body;
     if (Body->isStrongUndefined())
-      error(Twine("undefined symbol: ") + Name);
+      undefError<ELFT>(Symtab, *Body);
 
     if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
       CommonSymbols.push_back(C);

Modified: lld/trunk/test/elf2/undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/undef.s?rev=248382&r1=248381&r2=248382&view=diff
==============================================================================
--- lld/trunk/test/elf2/undef.s (original)
+++ lld/trunk/test/elf2/undef.s Wed Sep 23 09:37:01 2015
@@ -1,6 +1,6 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 # RUN: not lld -flavor gnu2 %t -o %t2 2>&1 | FileCheck %s
-# CHECK: undefined symbol: foo
+# CHECK: undefined symbol: foo in {{.*}}
 # REQUIRES: x86
 
   .globl _start;




More information about the llvm-commits mailing list