diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-09-23 14:37:01 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-09-23 14:37:01 +0000 |
commit | 6173f848b965edac09579a6132888bc24e9041e8 (patch) | |
tree | c441347ec22ba336e4fc7d3fa30b7bfacfd64741 | |
parent | 8e5560d894717779061245f7efd725d845ea3b56 (diff) | |
download | bcm5719-llvm-6173f848b965edac09579a6132888bc24e9041e8.tar.gz bcm5719-llvm-6173f848b965edac09579a6132888bc24e9041e8.zip |
Print more information about undefined symbols.
llvm-svn: 248382
-rw-r--r-- | lld/ELF/Writer.cpp | 23 | ||||
-rw-r--r-- | lld/test/elf2/undef.s | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 765e5391635..57180df8993 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -288,6 +288,27 @@ void Writer<ELFT>::scanRelocs(const InputSection<ELFT> &C) { } } +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>::createSections() { 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); diff --git a/lld/test/elf2/undef.s b/lld/test/elf2/undef.s index 2196c1d5967..9e27bc082e6 100644 --- a/lld/test/elf2/undef.s +++ b/lld/test/elf2/undef.s @@ -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; |