[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
Tue Aug 6 10:01:39 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL368057: [ELF][PPC] Don't relax ifunc toc-indirect accesses to toc-relative (authored by MaskRay, committed by ).

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65755/new/

https://reviews.llvm.org/D65755

Files:
  lld/trunk/ELF/Arch/PPC64.cpp
  lld/trunk/test/ELF/ppc64-toc-relax-ifunc.s


Index: lld/trunk/test/ELF/ppc64-toc-relax-ifunc.s
===================================================================
--- lld/trunk/test/ELF/ppc64-toc-relax-ifunc.s
+++ lld/trunk/test/ELF/ppc64-toc-relax-ifunc.s
@@ -0,0 +1,20 @@
+# 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
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+## 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: lld/trunk/ELF/Arch/PPC64.cpp
===================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp
+++ lld/trunk/ELF/Arch/PPC64.cpp
@@ -172,7 +172,11 @@
                    : 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,
+  // which will run at load time to determine the relocated value. It is not
+  // known until load time, so the access cannot be relaxed.
+  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.213644.patch
Type: text/x-patch
Size: 1607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190806/875e614a/attachment.bin>


More information about the llvm-commits mailing list