[PATCH] D23731: [ELF] Only print symbol name when it is available

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL279459: [ELF] Only print symbol name when it is available (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D23731?vs=68825&id=68898#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23731

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

Index: lld/trunk/ELF/Relocations.cpp
===================================================================
--- lld/trunk/ELF/Relocations.cpp
+++ lld/trunk/ELF/Relocations.cpp
@@ -401,9 +401,13 @@
 }
 
 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 @@
   // 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) {
Index: lld/trunk/test/ELF/dynamic-reloc-in-ro.s
===================================================================
--- lld/trunk/test/ELF/dynamic-reloc-in-ro.s
+++ lld/trunk/test/ELF/dynamic-reloc-in-ro.s
@@ -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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23731.68898.patch
Type: text/x-patch
Size: 1794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160822/14c29a90/attachment.bin>


More information about the llvm-commits mailing list