Define a helper function to demangle symbols.

llvm-svn: 285219
This commit is contained in:
Rui Ueyama 2016-10-26 18:28:06 +00:00
parent 85a28dcc5d
commit 5ce977ccd0
4 changed files with 15 additions and 10 deletions

View File

@ -553,8 +553,7 @@ static std::string getLocation(SymbolBody &Sym, InputSectionBase<ELFT> &S,
DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
if (Encl && Encl->Type == STT_FUNC) {
StringRef Func = getSymbolName(*File, *Encl);
return SrcFile + " (function " +
(Config->Demangle ? demangle(Func) : Func.str()) + ")";
return SrcFile + " (function " + maybeDemangle(Func) + ")";
}
return (SrcFile + " (" + S.Name + "+0x" + Twine::utohexstr(Offset) + ")")
@ -571,9 +570,8 @@ static void reportUndefined(SymbolBody &Sym, InputSectionBase<ELFT> &S,
Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef)
return;
std::string Msg =
getLocation(Sym, S, Offset) + ": undefined symbol '" +
(Config->Demangle ? demangle(Sym.getName()) : Sym.getName().str()) + "'";
std::string Msg = getLocation(Sym, S, Offset) + ": undefined symbol '" +
maybeDemangle(Sym.getName()) + "'";
if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
warn(Msg);

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "Strings.h"
#include "Config.h"
#include "Error.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
@ -124,3 +125,9 @@ std::string elf::demangle(StringRef Name) {
free(Buf);
return S;
}
std::string elf::maybeDemangle(StringRef Name) {
if (Config->Demangle)
return demangle(Name);
return Name;
}

View File

@ -30,6 +30,9 @@ StringRef unquote(StringRef S);
// 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<uint8_t> Arr) {
return {(const char *)Arr.data(), Arr.size()};
}

View File

@ -256,11 +256,8 @@ SymbolTable<ELFT>::insert(StringRef &Name, uint8_t Type, uint8_t Visibility,
template <typename ELFT>
std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,
InputFile *NewFile) {
std::string Sym = Existing->getName();
if (Config->Demangle)
Sym = demangle(Sym);
return Sym + " in " + getFilename(Existing->File) + " and " +
getFilename(NewFile);
return maybeDemangle(Existing->getName()) + " in " +
getFilename(Existing->File) + " and " + getFilename(NewFile);
}
template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {