Define toString(const SymbolBody &) and remove maybeDemangle instead.

Differential Revision: https://reviews.llvm.org/D27065

llvm-svn: 287899
This commit is contained in:
Rui Ueyama 2016-11-24 20:24:18 +00:00
parent a331133e6d
commit a3ac17372b
6 changed files with 22 additions and 23 deletions

View File

@ -344,7 +344,7 @@ static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type,
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 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol<ELFT> *SS) {
// Copy relocation against zero-sized symbol doesn't make sense.
uintX_t SymSize = SS->template getSize<ELFT>();
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<ELFT>::Bss->Size, Alignment);
@ -443,17 +443,16 @@ static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body,
// 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 @@ static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body,
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 @@ std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset) {
// Find a symbol at a given location.
DefinedRegular<ELFT> *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 @@ static void reportUndefined(SymbolBody &Sym, InputSectionBase<ELFT> &S,
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);

View File

@ -225,9 +225,3 @@ 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

@ -67,9 +67,6 @@ private:
// 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

@ -206,8 +206,8 @@ std::pair<Symbol *, bool> SymbolTable<ELFT>::insert(StringRef Name) {
// 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 @@ static void reportDuplicate(SymbolBody *Existing,
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");
}

View File

@ -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 @@ void elf::printTraceSymbol(Symbol *Sym) {
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<ELF32LE>() const;
template bool SymbolBody::hasThunk<ELF32BE>() const;
template bool SymbolBody::hasThunk<ELF64LE>() const;

View File

@ -453,6 +453,8 @@ inline Symbol *SymbolBody::symbol() {
offsetof(Symbol, Body));
}
std::string toString(const SymbolBody &B);
} // namespace elf
} // namespace lld