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

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 21 23:00:53 PDT 2016


phosek updated this revision to Diff 68825.
phosek marked 2 inline comments as done.

https://reviews.llvm.org/D23731

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

Index: test/ELF/dynamic-reloc-in-ro.s
===================================================================
--- test/ELF/dynamic-reloc-in-ro.s
+++ 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
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23731.68825.patch
Type: text/x-patch
Size: 1734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160822/70a44cc9/attachment-0001.bin>


More information about the llvm-commits mailing list