[PATCH] D13825: [ELF2] Don't create RelativeReloc for weak undef symbols

hfinkel@anl.gov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 12:30:15 PDT 2015


hfinkel created this revision.
hfinkel added reviewers: rafael, ruiu.
hfinkel added a subscriber: llvm-commits.
hfinkel added a project: lld.

When we have a R_PPC64_ADDR64 for a weak undef symbol, which thus resolves to 0, and we're creating a shared library, we need to make sure that it stays 0 (because code that conditionally calls the weak function tests for this). Unfortunately, we were creating a R_PPC64_RELATIVE for these relocation targets, making the address of the undefined weak symbol equal to the base address of the shared library (which is non-zero). It seems like, in general, we should not be creating RelativeReloc relocs for undef weak symbols.


http://reviews.llvm.org/D13825

Files:
  ELF/Writer.cpp
  test/elf2/ppc64-weak-undef-call-shared.s

Index: test/elf2/ppc64-weak-undef-call-shared.s
===================================================================
--- /dev/null
+++ test/elf2/ppc64-weak-undef-call-shared.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+# RUN: ld.lld2 -shared %t.o -o %t.so
+# RUN: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s
+# REQUIRES: ppc
+
+.section        ".toc","aw"
+.quad weakfunc
+// CHECK-NOT: R_PPC64_RELATIVE
+
+.weak weakfunc
+
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -201,7 +201,8 @@
     }
 
     bool CBP = canBePreempted(Body, NeedsGot);
-    if (!CBP && (!Config->Shared || Target->isRelRelative(Type)))
+    if (!CBP && (!Config->Shared || Target->isRelRelative(Type) ||
+                 (Body && Body->isWeak() && Body->isUndefined())))
       continue;
     if (CBP)
       Body->setUsedInDynamicReloc();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13825.37626.patch
Type: text/x-patch
Size: 957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151016/6c2fd68a/attachment.bin>


More information about the llvm-commits mailing list