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

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 19 17:29:02 PDT 2016


phosek created this revision.
phosek added a reviewer: ruiu.
phosek added subscribers: llvm-commits, phosek.
phosek added a project: lld.

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.

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
@@ -428,10 +428,10 @@
   // 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();
-    error("can't create dynamic relocation " + getRelName(Type) +
-          " against symbol " + Name);
+    error("can't create dynamic relocation " + getRelName(Type) + " against " +
+          (Body.isLocal() && !Body.getNameOffset() ? "readonly segment" :
+           "symbol " + (Body.isLocal() ? getLocalSymbolName(File, Body)
+                                       : Body.getName())));
     return Expr;
   }
   if (Body.getVisibility() != STV_DEFAULT) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23731.68751.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160820/de8b0ec2/attachment.bin>


More information about the llvm-commits mailing list