[lld] r240719 - COFF: Better error message for duplicate symbols.
Rui Ueyama
ruiu at google.com
Thu Jun 25 16:22:00 PDT 2015
Author: ruiu
Date: Thu Jun 25 18:22:00 2015
New Revision: 240719
URL: http://llvm.org/viewvc/llvm-project?rev=240719&view=rev
Log:
COFF: Better error message for duplicate symbols.
Now the symbol table prints out not only symbol names but
also file names for duplicate symbols.
Modified:
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/Symbols.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=240719&r1=240718&r2=240719&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Thu Jun 25 18:22:00 2015
@@ -184,7 +184,7 @@ SymbolBody *ObjectFile::createSymbolBody
if (Sym.isCommon()) {
auto *C = new (Alloc) CommonChunk(Sym);
Chunks.push_back(C);
- return new (Alloc) DefinedCommon(COFFObj.get(), Sym, C);
+ return new (Alloc) DefinedCommon(this, Sym, C);
}
if (Sym.isAbsolute()) {
COFFObj->getSymbolName(Sym, Name);
@@ -215,7 +215,7 @@ SymbolBody *ObjectFile::createSymbolBody
}
Chunk *C = SparseChunks[Sym.getSectionNumber()];
if (auto *SC = cast_or_null<SectionChunk>(C)) {
- auto *B = new (Alloc) DefinedRegular(COFFObj.get(), Sym, SC);
+ auto *B = new (Alloc) DefinedRegular(this, Sym, SC);
if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)
SC->setSymbol(B);
return B;
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=240719&r1=240718&r2=240719&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Jun 25 18:22:00 2015
@@ -120,7 +120,8 @@ std::error_code SymbolTable::resolve(Sym
++Version;
}
if (comp == 0) {
- llvm::errs() << "duplicate symbol: " << Name << "\n";
+ llvm::errs() << "duplicate symbol: " << Existing->getDebugName()
+ << " and " << New->getDebugName() << "\n";
return make_error_code(LLDError::DuplicateSymbols);
}
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=240719&r1=240718&r2=240719&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Thu Jun 25 18:22:00 2015
@@ -111,16 +111,24 @@ StringRef DefinedRegular::getName() {
// StringRefs for them (which involves lots of strlen() on the string table)
// is a waste of time.
if (Name.empty())
- COFFFile->getSymbolName(Sym, Name);
+ File->getCOFFObj()->getSymbolName(Sym, Name);
return Name;
}
StringRef DefinedCommon::getName() {
if (Name.empty())
- COFFFile->getSymbolName(Sym, Name);
+ File->getCOFFObj()->getSymbolName(Sym, Name);
return Name;
}
+std::string DefinedRegular::getDebugName() {
+ return (getName() + " " + File->getShortName()).str();
+}
+
+std::string DefinedCommon::getDebugName() {
+ return (getName() + " " + File->getShortName()).str();
+}
+
ErrorOr<std::unique_ptr<InputFile>> Lazy::getMember() {
auto MBRefOrErr = File->getMember(&Sym);
if (auto EC = MBRefOrErr.getError())
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=240719&r1=240718&r2=240719&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Thu Jun 25 18:22:00 2015
@@ -23,7 +23,6 @@ namespace lld {
namespace coff {
using llvm::object::Archive;
-using llvm::object::COFFObjectFile;
using llvm::object::COFFSymbolRef;
using llvm::object::coff_import_header;
@@ -80,6 +79,10 @@ public:
// they are duplicate (conflicting) symbols.
virtual int compare(SymbolBody *Other) = 0;
+ // Returns a name of this symbol including source file name.
+ // Used only for debugging and logging.
+ virtual std::string getDebugName() { return getName(); }
+
protected:
SymbolBody(Kind K) : SymbolKind(K) {}
@@ -113,8 +116,8 @@ public:
// Regular defined symbols read from object file symbol tables.
class DefinedRegular : public Defined {
public:
- DefinedRegular(COFFObjectFile *F, COFFSymbolRef S, SectionChunk *C)
- : Defined(DefinedRegularKind), COFFFile(F), Sym(S), Data(&C->Ptr),
+ DefinedRegular(ObjectFile *F, COFFSymbolRef S, SectionChunk *C)
+ : Defined(DefinedRegularKind), File(F), Sym(S), Data(&C->Ptr),
IsCOMDAT(C->isCOMDAT()) {}
static bool classof(const SymbolBody *S) {
@@ -129,13 +132,14 @@ public:
uint64_t getRVA() override { return (*Data)->getRVA() + Sym.getValue(); }
bool isExternal() override { return Sym.isExternal(); }
int compare(SymbolBody *Other) override;
+ std::string getDebugName() override;
bool isCOMDAT() { return IsCOMDAT; }
void markLive() { (*Data)->markLive(); }
Chunk *getChunk() { return *Data; }
private:
StringRef Name;
- COFFObjectFile *COFFFile;
+ ObjectFile *File;
COFFSymbolRef Sym;
SectionChunk **Data;
bool IsCOMDAT;
@@ -143,8 +147,8 @@ private:
class DefinedCommon : public Defined {
public:
- DefinedCommon(COFFObjectFile *F, COFFSymbolRef S, CommonChunk *C)
- : Defined(DefinedCommonKind), COFFFile(F), Sym(S), Data(C) {}
+ DefinedCommon(ObjectFile *F, COFFSymbolRef S, CommonChunk *C)
+ : Defined(DefinedCommonKind), File(F), Sym(S), Data(C) {}
static bool classof(const SymbolBody *S) {
return S->kind() == DefinedCommonKind;
@@ -155,12 +159,13 @@ public:
bool isExternal() override { return Sym.isExternal(); }
uint64_t getFileOff() override { return Data->getFileOff(); }
int compare(SymbolBody *Other) override;
+ std::string getDebugName() override;
private:
uint64_t getSize() { return Sym.getValue(); }
StringRef Name;
- COFFObjectFile *COFFFile;
+ ObjectFile *File;
COFFSymbolRef Sym;
CommonChunk *Data;
};
More information about the llvm-commits
mailing list