[lld] r279459 - [ELF] Only print symbol name when it is available

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 22 12:01:53 PDT 2016


Author: phosek
Date: Mon Aug 22 14:01:53 2016
New Revision: 279459

URL: http://llvm.org/viewvc/llvm-project?rev=279459&view=rev
Log:
[ELF] Only print symbol name when it is available

Not only symbols (like sections) have names, in case where we
fail to create relocation against such symbol, we should not
print out an empty string, instead we should print a generic
message.

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

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/test/ELF/dynamic-reloc-in-ro.s

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=279459&r1=279458&r2=279459&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Mon Aug 22 14:01:53 2016
@@ -401,9 +401,13 @@ template <class ELFT> static void addCop
 }
 
 template <class ELFT>
-static StringRef getLocalSymbolName(const elf::ObjectFile<ELFT> &File,
-                                    SymbolBody &Body) {
-  return File.getStringTable().data() + Body.getNameOffset();
+static StringRef getSymbolName(const elf::ObjectFile<ELFT> &File,
+                               SymbolBody &Body) {
+  if (Body.isLocal() && Body.getNameOffset())
+    return File.getStringTable().data() + Body.getNameOffset();
+  if (!Body.isLocal())
+    return Body.getName();
+  return "";
 }
 
 template <class ELFT>
@@ -428,10 +432,9 @@ 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.isLocal() ? getLocalSymbolName(File, Body)
-                                    : Body.getName();
+    StringRef Name = getSymbolName(File, Body);
     error("can't create dynamic relocation " + getRelName(Type) +
-          " against symbol " + Name);
+          " against " + (Name.empty() ? "readonly segment" : "symbol " + Name));
     return Expr;
   }
   if (Body.getVisibility() != STV_DEFAULT) {

Modified: lld/trunk/test/ELF/dynamic-reloc-in-ro.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-reloc-in-ro.s?rev=279459&r1=279458&r2=279459&view=diff
==============================================================================
--- lld/trunk/test/ELF/dynamic-reloc-in-ro.s (original)
+++ lld/trunk/test/ELF/dynamic-reloc-in-ro.s Mon Aug 22 14:01:53 2016
@@ -5,4 +5,4 @@
 foo:
 .quad foo
 
-// CHECK: can't create dynamic relocation R_X86_64_64 against symbol
+// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment




More information about the llvm-commits mailing list