[lld] r250558 - [ELF2] Don't create RelativeReloc for weak undef symbols
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 15:11:06 PDT 2015
Author: hfinkel
Date: Fri Oct 16 17:11:05 2015
New Revision: 250558
URL: http://llvm.org/viewvc/llvm-project?rev=250558&view=rev
Log:
[ELF2] Don't create RelativeReloc for weak undef symbols
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). In general, we should not be
creating RelativeReloc relocs for undef weak symbols.
Added:
lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s
Modified:
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250558&r1=250557&r2=250558&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Oct 16 17:11:05 2015
@@ -477,7 +477,10 @@ bool lld::elf2::canBePreempted(const Sym
// the plt entry would have a non zero address.
// Since we cannot do anything better, we just resolve the symbol to 0 and
// don't produce a dynamic relocation.
- return NeedsGot;
+ //
+ // As an extra hack, assume that if we are producing a shared library the
+ // user knows what he or she is doing and can handle a dynamic relocation.
+ return Config->Shared || NeedsGot;
}
if (!Config->Shared)
return false;
Added: lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s?rev=250558&view=auto
==============================================================================
--- lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s (added)
+++ lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s Fri Oct 16 17:11:05 2015
@@ -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
+
More information about the llvm-commits
mailing list