[lld] r285219 - Define a helper function to demangle symbols.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 11:28:07 PDT 2016
Author: ruiu
Date: Wed Oct 26 13:28:06 2016
New Revision: 285219
URL: http://llvm.org/viewvc/llvm-project?rev=285219&view=rev
Log:
Define a helper function to demangle symbols.
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Strings.cpp
lld/trunk/ELF/Strings.h
lld/trunk/ELF/SymbolTable.cpp
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=285219&r1=285218&r2=285219&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Oct 26 13:28:06 2016
@@ -553,8 +553,7 @@ static std::string getLocation(SymbolBod
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 &
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);
Modified: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=285219&r1=285218&r2=285219&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.cpp (original)
+++ lld/trunk/ELF/Strings.cpp Wed Oct 26 13:28:06 2016
@@ -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;
+}
Modified: lld/trunk/ELF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=285219&r1=285218&r2=285219&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.h (original)
+++ lld/trunk/ELF/Strings.h Wed Oct 26 13:28:06 2016
@@ -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()};
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=285219&r1=285218&r2=285219&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Oct 26 13:28:06 2016
@@ -256,11 +256,8 @@ SymbolTable<ELFT>::insert(StringRef &Nam
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) {
More information about the llvm-commits
mailing list