Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -344,7 +344,7 @@ if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak()) return true; error(getLocation(S, RelOff) + ": relocation " + toString(Type) + - " cannot refer to absolute symbol '" + Body.getName() + + " cannot refer to absolute symbol '" + toString(Body) + "' defined in " + toString(Body.File)); return true; } @@ -394,7 +394,7 @@ // Copy relocation against zero-sized symbol doesn't make sense. uintX_t SymSize = SS->template getSize(); if (SymSize == 0) - fatal("cannot create a copy relocation for symbol " + SS->getName()); + fatal("cannot create a copy relocation for symbol " + toString(*SS)); uintX_t Alignment = getAlignment(SS); uintX_t Off = alignTo(Out::Bss->Size, Alignment); @@ -443,17 +443,16 @@ // only memory. We can hack around it if we are producing an executable and // the refered symbol can be preemepted to refer to the executable. if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) { - StringRef Name = Body.getName(); error(getLocation(S, RelOff) + ": can't create dynamic relocation " + toString(Type) + " against " + - ((Name.empty() ? "local symbol in readonly segment" - : "symbol '" + Name + "'")) + + (Body.getName().empty() ? "local symbol in readonly segment" + : "symbol '" + toString(Body) + "'") + " defined in " + toString(Body.File)); return Expr; } if (Body.getVisibility() != STV_DEFAULT) { error(getLocation(S, RelOff) + ": cannot preempt symbol '" + - Body.getName() + "' defined in " + toString(Body.File)); + toString(Body) + "' defined in " + toString(Body.File)); return Expr; } if (Body.isObject()) { @@ -487,7 +486,7 @@ Body.NeedsCopyOrPltAddr = true; return toPlt(Expr); } - error("symbol '" + Body.getName() + "' defined in " + toString(Body.File) + + error("symbol '" + toString(Body) + "' defined in " + toString(Body.File) + " is missing type"); return Expr; @@ -553,7 +552,7 @@ // Find a symbol at a given location. DefinedRegular *Encl = getSymbolAt(&S, Offset); if (Encl && Encl->Type == STT_FUNC) - return SrcFile + ":(function " + maybeDemangle(Encl->getName()) + ")"; + return SrcFile + ":(function " + toString(*Encl) + ")"; // If there's no symbol, print out the offset instead of a symbol name. return (SrcFile + ":(" + S.Name + "+0x" + utohexstr(Offset) + ")").str(); @@ -569,8 +568,8 @@ Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef) return; - std::string Msg = getLocation(S, Offset) + ": undefined symbol '" + - maybeDemangle(Sym.getName()) + "'"; + std::string Msg = + getLocation(S, Offset) + ": undefined symbol '" + toString(Sym) + "'"; if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn) warn(Msg); Index: lld/trunk/ELF/Strings.h =================================================================== --- lld/trunk/ELF/Strings.h +++ lld/trunk/ELF/Strings.h @@ -67,9 +67,6 @@ // it returns an unmodified string. std::string demangle(StringRef Name); -// Demangle if Config->Demangle is true. -std::string maybeDemangle(StringRef Name); - inline StringRef toStringRef(ArrayRef Arr) { return {(const char *)Arr.data(), Arr.size()}; } Index: lld/trunk/ELF/Strings.cpp =================================================================== --- lld/trunk/ELF/Strings.cpp +++ lld/trunk/ELF/Strings.cpp @@ -225,9 +225,3 @@ free(Buf); return S; } - -std::string elf::maybeDemangle(StringRef Name) { - if (Config->Demangle) - return demangle(Name); - return Name; -} Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -206,8 +206,8 @@ // Construct a string in the form of "Sym in File1 and File2". // Used to construct an error message. static std::string conflictMsg(SymbolBody *Existing, InputFile *NewFile) { - return "'" + maybeDemangle(Existing->getName()) + "' in " + - toString(Existing->File) + " and " + toString(NewFile); + return "'" + toString(*Existing) + "' in " + toString(Existing->File) + + " and " + toString(NewFile); } // Find an existing symbol or create and insert a new one, then apply the given @@ -361,8 +361,7 @@ std::string OldLoc = getLocation(*D->Section, D->Value); std::string NewLoc = getLocation(*ErrSec, ErrOffset); - print(NewLoc + ": duplicate symbol '" + maybeDemangle(Existing->getName()) + - "'"); + print(NewLoc + ": duplicate symbol '" + toString(*Existing) + "'"); print(OldLoc + ": previous definition was here"); } Index: lld/trunk/ELF/Symbols.h =================================================================== --- lld/trunk/ELF/Symbols.h +++ lld/trunk/ELF/Symbols.h @@ -453,6 +453,8 @@ offsetof(Symbol, Body)); } +std::string toString(const SymbolBody &B); + } // namespace elf } // namespace lld Index: lld/trunk/ELF/Symbols.cpp =================================================================== --- lld/trunk/ELF/Symbols.cpp +++ lld/trunk/ELF/Symbols.cpp @@ -12,6 +12,7 @@ #include "InputFiles.h" #include "InputSection.h" #include "OutputSections.h" +#include "Strings.h" #include "SyntheticSections.h" #include "Target.h" @@ -318,6 +319,13 @@ outs() << B->getName() << "\n"; } +// Returns a symbol for an error message. +std::string elf::toString(const SymbolBody &B) { + if (Config->Demangle) + return demangle(B.getName()); + return B.getName(); +} + template bool SymbolBody::hasThunk() const; template bool SymbolBody::hasThunk() const; template bool SymbolBody::hasThunk() const;