From 18f09507831557a5d4bc8a6fd4ace1ef26a37f65 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 26 Feb 2016 21:49:38 +0000 Subject: [PATCH] Report duplicated symbols in bitcode. llvm-svn: 262076 --- lld/ELF/SymbolTable.cpp | 14 +++++++++----- lld/ELF/SymbolTable.h | 2 +- lld/ELF/Writer.cpp | 2 +- lld/test/ELF/lto/duplicated.ll | 10 ++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 lld/test/ELF/lto/duplicated.ll diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 473f7ab..e844f71 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -217,18 +217,22 @@ template void SymbolTable::wrap(StringRef Name) { // Returns a file from which symbol B was created. // If B does not belong to any file, returns a nullptr. -template -ELFFileBase *SymbolTable::findFile(SymbolBody *B) { +template InputFile *SymbolTable::findFile(SymbolBody *B) { for (const std::unique_ptr> &F : ObjectFiles) { ArrayRef Syms = F->getSymbols(); if (std::find(Syms.begin(), Syms.end(), B) != Syms.end()) return F.get(); } + for (const std::unique_ptr &F : BitcodeFiles) { + ArrayRef Syms = F->getSymbols(); + if (std::find(Syms.begin(), Syms.end(), B) != Syms.end()) + return F.get(); + } return nullptr; } // Returns "(internal)", "foo.a(bar.o)" or "baz.o". -template static std::string getFilename(ELFFileBase *F) { +static std::string getFilename(InputFile *F) { if (!F) return "(internal)"; if (!F->ArchiveName.empty()) @@ -240,8 +244,8 @@ template static std::string getFilename(ELFFileBase *F) { // Used to construct an error message. template std::string SymbolTable::conflictMsg(SymbolBody *Old, SymbolBody *New) { - ELFFileBase *F1 = findFile(Old); - ELFFileBase *F2 = findFile(New); + InputFile *F1 = findFile(Old); + InputFile *F2 = findFile(New); StringRef Sym = Old->getName(); return demangle(Sym) + " in " + getFilename(F1) + " and " + getFilename(F2); } diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index 7b04154..632e71b 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -64,7 +64,7 @@ public: void scanShlibUndefined(); SymbolBody *find(StringRef Name); void wrap(StringRef Name); - ELFFileBase *findFile(SymbolBody *B); + InputFile *findFile(SymbolBody *B); private: Symbol *insert(SymbolBody *New); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 661324b..a903f27 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -517,7 +517,7 @@ static void reportUndefined(SymbolTable &Symtab, SymbolBody *Sym) { return; std::string Msg = "undefined symbol: " + Sym->getName().str(); - if (ELFFileBase *File = Symtab.findFile(Sym)) + if (InputFile *File = Symtab.findFile(Sym)) Msg += " in " + File->getName().str(); if (Config->NoInhibitExec) warning(Msg); diff --git a/lld/test/ELF/lto/duplicated.ll b/lld/test/ELF/lto/duplicated.ll new file mode 100644 index 0000000..6ef6772 --- /dev/null +++ b/lld/test/ELF/lto/duplicated.ll @@ -0,0 +1,10 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o +; RUN: not ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared 2>&1 | FileCheck %s +; CHECK: duplicate symbol: f in {{.*}}.o and {{.*}}.o +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +define void @f() { + ret void +} -- 2.7.4