[lld] r287899 - Define toString(const SymbolBody &) and remove maybeDemangle instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 24 12:24:19 PST 2016


Author: ruiu
Date: Thu Nov 24 14:24:18 2016
New Revision: 287899

URL: http://llvm.org/viewvc/llvm-project?rev=287899&view=rev
Log:
Define toString(const SymbolBody &) and remove maybeDemangle instead.

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

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Strings.cpp
    lld/trunk/ELF/Strings.h
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Nov 24 14:24:18 2016
@@ -344,7 +344,7 @@ static bool isStaticLinkTimeConstant(Rel
     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 addCop
   // 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::Obj
   // 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::Obj
     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
   // 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 &
       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);

Modified: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.cpp (original)
+++ lld/trunk/ELF/Strings.cpp Thu Nov 24 14:24:18 2016
@@ -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;
-}

Modified: lld/trunk/ELF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.h (original)
+++ lld/trunk/ELF/Strings.h Thu Nov 24 14:24:18 2016
@@ -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()};
 }

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Nov 24 14:24:18 2016
@@ -206,8 +206,8 @@ std::pair<Symbol *, bool> SymbolTable<EL
 // 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 *
   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");
 }
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Thu Nov 24 14:24:18 2016
@@ -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;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=287899&r1=287898&r2=287899&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Thu Nov 24 14:24:18 2016
@@ -453,6 +453,8 @@ inline Symbol *SymbolBody::symbol() {
                                     offsetof(Symbol, Body));
 }
 
+std::string toString(const SymbolBody &B);
+
 } // namespace elf
 } // namespace lld
 




More information about the llvm-commits mailing list