forked from OSchip/llvm-project
Define a helper function to demangle symbols.
llvm-svn: 285219
This commit is contained in:
parent
85a28dcc5d
commit
5ce977ccd0
|
@ -553,8 +553,7 @@ static std::string getLocation(SymbolBody &Sym, InputSectionBase<ELFT> &S,
|
||||||
DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
|
DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
|
||||||
if (Encl && Encl->Type == STT_FUNC) {
|
if (Encl && Encl->Type == STT_FUNC) {
|
||||||
StringRef Func = getSymbolName(*File, *Encl);
|
StringRef Func = getSymbolName(*File, *Encl);
|
||||||
return SrcFile + " (function " +
|
return SrcFile + " (function " + maybeDemangle(Func) + ")";
|
||||||
(Config->Demangle ? demangle(Func) : Func.str()) + ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (SrcFile + " (" + S.Name + "+0x" + Twine::utohexstr(Offset) + ")")
|
return (SrcFile + " (" + S.Name + "+0x" + Twine::utohexstr(Offset) + ")")
|
||||||
|
@ -571,9 +570,8 @@ static void reportUndefined(SymbolBody &Sym, InputSectionBase<ELFT> &S,
|
||||||
Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef)
|
Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string Msg =
|
std::string Msg = getLocation(Sym, S, Offset) + ": undefined symbol '" +
|
||||||
getLocation(Sym, S, Offset) + ": undefined symbol '" +
|
maybeDemangle(Sym.getName()) + "'";
|
||||||
(Config->Demangle ? demangle(Sym.getName()) : Sym.getName().str()) + "'";
|
|
||||||
|
|
||||||
if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
|
if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
|
||||||
warn(Msg);
|
warn(Msg);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Strings.h"
|
#include "Strings.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
|
@ -124,3 +125,9 @@ std::string elf::demangle(StringRef Name) {
|
||||||
free(Buf);
|
free(Buf);
|
||||||
return S;
|
return S;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string elf::maybeDemangle(StringRef Name) {
|
||||||
|
if (Config->Demangle)
|
||||||
|
return demangle(Name);
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ StringRef unquote(StringRef S);
|
||||||
// it returns an unmodified string.
|
// it returns an unmodified string.
|
||||||
std::string demangle(StringRef Name);
|
std::string demangle(StringRef Name);
|
||||||
|
|
||||||
|
// Demangle if Config->Demangle is true.
|
||||||
|
std::string maybeDemangle(StringRef Name);
|
||||||
|
|
||||||
inline StringRef toStringRef(ArrayRef<uint8_t> Arr) {
|
inline StringRef toStringRef(ArrayRef<uint8_t> Arr) {
|
||||||
return {(const char *)Arr.data(), Arr.size()};
|
return {(const char *)Arr.data(), Arr.size()};
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,11 +256,8 @@ SymbolTable<ELFT>::insert(StringRef &Name, uint8_t Type, uint8_t Visibility,
|
||||||
template <typename ELFT>
|
template <typename ELFT>
|
||||||
std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,
|
std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,
|
||||||
InputFile *NewFile) {
|
InputFile *NewFile) {
|
||||||
std::string Sym = Existing->getName();
|
return maybeDemangle(Existing->getName()) + " in " +
|
||||||
if (Config->Demangle)
|
getFilename(Existing->File) + " and " + getFilename(NewFile);
|
||||||
Sym = demangle(Sym);
|
|
||||||
return Sym + " in " + getFilename(Existing->File) + " and " +
|
|
||||||
getFilename(NewFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {
|
template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {
|
||||||
|
|
Loading…
Reference in New Issue