Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -553,7 +553,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" + Twine::utohexstr(Offset) + ")") @@ -570,8 +570,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: ELF/Strings.h =================================================================== --- ELF/Strings.h +++ 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: ELF/Strings.cpp =================================================================== --- ELF/Strings.cpp +++ 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: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ 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: ELF/Symbols.h =================================================================== --- ELF/Symbols.h +++ ELF/Symbols.h @@ -449,6 +449,8 @@ offsetof(Symbol, Body)); } +std::string toString(SymbolBody *B); + } // namespace elf } // namespace lld Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ 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(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;