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

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 20 22:52:31 PDT 2016


phosek updated this revision to Diff 68796.
phosek marked an inline comment 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
@@ -407,6 +407,16 @@
 }
 
 template <class ELFT>
+static StringRef getSymbolName(const elf::ObjectFile<ELFT> &File,
+                               SymbolBody &Body) {
+  if (Body.isLocal() && Body.getNameOffset())
+    return getLocalSymbolName(File, Body);
+  else if (!Body.isLocal())
+    return Body.getName();
+  return "";
+}
+
+template <class ELFT>
 static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body,
                           bool IsWrite, RelExpr Expr, uint32_t Type,
                           const uint8_t *Data) {
@@ -428,10 +438,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.68796.patch
Type: text/x-patch
Size: 1726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160821/2084182c/attachment.bin>


More information about the llvm-commits mailing list