[PATCH] D65755: [ELF][PPC] Don't relax ifunc toc-indirect accesses to toc-relative
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 09:37:41 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: luporl, ruiu, sfertile.
Herald added subscribers: llvm-commits, jsji, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Fixes PR42759.
// If ifunc is taken address in -fPIC code, it may have a toc entry
.section .toc,"aw", at progbits
.quad ifunc
// ifunc may be defined as STT_GNU_IFUNC in another object file
.type ifunc, %gnu_indirect_function
If ifunc is non-preemptable (e.g. when linking an executable), the toc
entry will be relocated by R_PPC64_IRELATIVE.
R_*_IRELATIVE is used to represent the symbolic value of a
non-preemptable ifunc in a writable location. It has an unknown value at
link time, so we cannot apply toc-indirect to toc-relative relaxation.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D65755
Files:
ELF/Arch/PPC64.cpp
test/ELF/ppc64-toc-relax-ifunc.s
Index: test/ELF/ppc64-toc-relax-ifunc.s
===================================================================
--- /dev/null
+++ test/ELF/ppc64-toc-relax-ifunc.s
@@ -0,0 +1,19 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
+# RUN: echo '.globl ifunc; .type ifunc, %gnu_indirect_function; ifunc:' | \
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le - -o %t1.o
+# RUN: ld.lld %t.o %t1.o -o %t
+
+## ifunc is a non-preemptable STT_GNU_IFUNC. Its toc entry will be
+## relocated by R_PPC64_IRELATIVE, not representable by a toc-relative value.
+## Check the toc-indirect access is not relaxed.
+
+# CHECK: nop
+# CHECK-NEXT: ld 3, -32768(2)
+
+addis 3, 2, .toc at toc@ha
+ld 3, .toc at toc@l(3)
+
+.section .toc,"aw", at progbits
+ .quad ifunc
Index: ELF/Arch/PPC64.cpp
===================================================================
--- ELF/Arch/PPC64.cpp
+++ ELF/Arch/PPC64.cpp
@@ -172,7 +172,10 @@
: getRelaTocSymAndAddend<ELF64BE>(tocISB, rel.addend);
// Only non-preemptable defined symbols can be relaxed.
- if (!d || d->isPreemptible)
+ //
+ // The toc entry of a non-preemptable ifunc is relocated by R_PPC64_IRELATIVE,
+ // not representable as a toc-relative value. Exclude ifunc.
+ if (!d || d->isPreemptible || d->isGnuIFunc())
return false;
// Two instructions can materialize a 32-bit signed offset from the toc base.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65755.213383.patch
Type: text/x-patch
Size: 1406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190805/6123c480/attachment.bin>
More information about the llvm-commits
mailing list