[PATCH] D76904: [ELF][PPC64] Enable R_PPC64_REL14 trunks

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 22:51:19 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: nathanchance, sfertile.
Herald added subscribers: llvm-commits, steven.zhang, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

The thunk implementation is available but an assertion disallows it.
Linux kernel has such a use case: in arch/powerpc/kernel/exceptions-64s.S:handle_page_fault,
beq+ ret_from_except_lite may get out of range.

Link: https://github.com/ClangBuiltLinux/linux/issues/951


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76904

Files:
  lld/ELF/Thunks.cpp
  lld/test/ELF/ppc64-long-branch-rel14.s


Index: lld/test/ELF/ppc64-long-branch-rel14.s
===================================================================
--- /dev/null
+++ lld/test/ELF/ppc64-long-branch-rel14.s
@@ -0,0 +1,60 @@
+# REQUIRES: ppc
+# RUN: echo 'SECTIONS { \
+# RUN:       .text_low 0x2000: { *(.text_low) } \
+# RUN:       .text_high 0xa000 : { *(.text_high) } \
+# RUN:       }' > %t.lds
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o
+# RUN: ld.lld -T %t.lds %t.o -o %t
+# RUN: llvm-readelf -r %t | FileCheck --check-prefix=SEC %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
+# RUN: ld.lld -pie -T %t.lds %t.o -o %t
+# RUN: llvm-readelf -r %t | FileCheck --check-prefix=SEC %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+
+# SEC: There are no relocations in this file.
+
+# CHECK-LABEL: <_start>:
+# CHECK-NEXT:  2000: bt 2, .+20
+# CHECK-NEXT:        bt+ 2, .+16
+# CHECK-NEXT:        bf 2, .+32764
+# CHECK-NEXT:        bt 2, .+24
+# CHECK-NEXT:        blr
+# CHECK-EMPTY:
+# CHECK-NEXT: <__long_branch_high>:
+# CHECK-NEXT:  2014: addis 12, 2, 0
+# CHECK-NEXT:        ld 12, {{.*}}(12)
+# CHECK-NEXT:        mtctr 12
+# CHECK-NEXT:        bctr
+# CHECK-EMPTY:
+
+# CHECK-NEXT: <__long_branch_>:
+# CHECK-NEXT:  2024: addis 12, 2, 0
+# CHECK-NEXT:        ld 12, {{.*}}(12)
+# CHECK-NEXT:        mtctr 12
+# CHECK-NEXT:        bctr
+
+.section .text_low, "ax", @progbits
+.globl _start
+_start:
+beq high           # Need a thunk
+beq+ high          # Need a thunk
+bne high
+beq .text_high+16  # Need a thunk
+blr
+
+# CHECK-LABEL: <.text_high>:
+# CHECK-NEXT:      a000: nop
+# CHECK-EMPTY:
+# CHECK-LABEL: <high>:
+# CHECK-NEXT:      a004: bf 0, .+32772
+# CHECK-NEXT:            bt 1, .+32768
+
+.section .text_high, "ax", @progbits
+nop
+.globl high
+high:
+bge .text_low+8
+bgt .text_low+8
Index: lld/ELF/Thunks.cpp
===================================================================
--- lld/ELF/Thunks.cpp
+++ lld/ELF/Thunks.cpp
@@ -945,7 +945,8 @@
 }
 
 static Thunk *addThunkPPC64(RelType type, Symbol &s, int64_t a) {
-  assert(type == R_PPC64_REL24 && "unexpected relocation type for thunk");
+  assert((type == R_PPC64_REL14 || type == R_PPC64_REL24) &&
+         "unexpected relocation type for thunk");
   if (s.isInPlt())
     return make<PPC64PltCallStub>(s);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76904.253045.patch
Type: text/x-patch
Size: 2367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200327/480c823a/attachment.bin>


More information about the llvm-commits mailing list