[lld] r250597 - [ELF2/PPC64] Don't create .plt entries for weak undef symbols
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 17:48:20 PDT 2015
Author: hfinkel
Date: Fri Oct 16 19:48:20 2015
New Revision: 250597
URL: http://llvm.org/viewvc/llvm-project?rev=250597&view=rev
Log:
[ELF2/PPC64] Don't create .plt entries for weak undef symbols
Instead of specifically creating .plt entries for weak undef symbols, mirror
the logic in r250584, and use canBePreempted to determine is a REL24 relocation
needs a .plt entry. This might cause relocateOne to be called for a weak undef
symbol, with a REL24 relocation, but ignore this as a special case (this will
cause SA == 0, which won't happen under any other circumstance).
Modified:
lld/trunk/ELF/Target.cpp
lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s
lld/trunk/test/elf2/ppc64-weak-undef-call.s
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250597&r1=250596&r2=250597&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Oct 16 19:48:20 2015
@@ -402,11 +402,8 @@ bool PPC64TargetInfo::relocNeedsGot(uint
}
bool PPC64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
- if (Type != R_PPC64_REL24)
- return false;
-
// These are function calls that need to be redirected through a PLT stub.
- return S.isShared() || (S.isUndefined() && S.isWeak());
+ return Type == R_PPC64_REL24 && canBePreempted(&S, false);
}
bool PPC64TargetInfo::isRelRelative(uint32_t Type) const {
@@ -500,6 +497,12 @@ void PPC64TargetInfo::relocateOne(uint8_
write32be(L, SA);
break;
case R_PPC64_REL24: {
+ // If we have an undefined weak symbol, we might get here with a symbol
+ // address of zero. That could overflow, but the code must be unreachable,
+ // so don't bother doing anything at all.
+ if (!SA)
+ break;
+
uint64_t PltStart = Out<ELF64BE>::Plt->getVA();
uint64_t PltEnd = PltStart + Out<ELF64BE>::Plt->getSize();
bool InPlt = PltStart <= SA && SA < PltEnd;
Modified: 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=250597&r1=250596&r2=250597&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s (original)
+++ lld/trunk/test/elf2/ppc64-weak-undef-call-shared.s Fri Oct 16 19:48:20 2015
@@ -7,5 +7,10 @@
.quad weakfunc
// CHECK-NOT: R_PPC64_RELATIVE
+.text
+.Lfoo:
+ bl weakfunc
+// CHECK-NOT: R_PPC64_REL24
+
.weak weakfunc
Modified: lld/trunk/test/elf2/ppc64-weak-undef-call.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/ppc64-weak-undef-call.s?rev=250597&r1=250596&r2=250597&view=diff
==============================================================================
--- lld/trunk/test/elf2/ppc64-weak-undef-call.s (original)
+++ lld/trunk/test/elf2/ppc64-weak-undef-call.s Fri Oct 16 19:48:20 2015
@@ -19,5 +19,9 @@ _start:
.weak weakfunc
# It does not really matter how we fixup the bl, if at all, because it needs to
-# be unreachable. But, we should link successfully.
+# be unreachable. But, we should link successfully. We should not, however,
+# generate a .plt entry (this would be wasted space). For now, we do nothing
+# (leaving the zero relative offset present in the input).
+# CHECK: 10010000: 48 00 00 01 bl .+0
+# CHECK: 10010004: 60 00 00 00 nop
# CHECK: 10010008: 4e 80 00 20 blr
More information about the llvm-commits
mailing list