[PATCH] D52523: [PPC64] Add test documenting toc-restore behaviour with -Bsymbolic option. [NFC]

Sean Fertile via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 25 15:46:04 PDT 2018


sfertile created this revision.
sfertile added reviewers: syzaara, ruiu, MaskRay.
Herald added subscribers: jsji, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D52523

Files:
  test/ELF/Inputs/ppc64-bsymbolic-local-def.s
  test/ELF/ppc64-bsymbolic-toc-restore.s


Index: test/ELF/ppc64-bsymbolic-toc-restore.s
===================================================================
--- /dev/null
+++ test/ELF/ppc64-bsymbolic-toc-restore.s
@@ -0,0 +1,68 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-bsymbolic-local-def.s  -o %t2.o
+# RUN: ld.lld -Bsymbolic -shared %t1.o %t2.o -o %t
+# RUN: llvm-objdump -d -r %t | FileCheck %s
+# RUN: not ld.lld -shared %t1.o %t2.o -o %t 2>&1 | FileCheck --check-prefix=FAIL %s
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-bsymbolic-local-def.s  -o %t2.o
+# RUN: ld.lld -Bsymbolic -shared %t1.o %t2.o -o %t
+# RUN: llvm-objdump -d -r %t | FileCheck %s
+# RUN: not ld.lld -shared %t1.o %t2.o -o %t 2>&1 | FileCheck --check-prefix=FAIL %s
+
+# FAIL: call lacks nop, can't restore toc
+
+# Test to document the toc-restore behavior with -Bsymbolic option. Since
+# -Bsymbolic causes the call to bind to the internal defintion we know the
+# caller and callee share the same TOC base. This means branching to the
+# local entry point of the callee, and no need for a nop to follow the call
+# (since there is no need to restore the TOC-pointer after the call).
+
+        .abiversion 2
+        .section ".text"
+
+        .p2align 2
+        .global caller
+        .type caller, @function
+caller:
+.Lcaller_gep:
+    addis 2, 12, .TOC.-.Lcaller_gep at ha
+    addi  2, 2, .TOC.-.Lcaller_gep at l
+.Lcaller_lep:
+    .localentry caller, .-caller
+    mflr 0
+    std 0, -16(1)
+    stdu 1, -32(1)
+    bl def
+    mr 31, 3
+    bl not_defined
+    nop
+    add 3, 3, 31
+    addi 1, 1, 32
+    ld 0, -16(1)
+    mtlr 0
+    blr
+
+# Note that the bl .+44 is a call to def's local entry, jumping past the first 2
+# instructions. Branching to the global entry would corrupt the TOC pointer
+# since the global entry requires that %r12 hold the address of the function
+# being called.
+
+# CHECK-LABEL: caller
+# CHECK:         bl .+44
+# CHECK-NEXT:    mr 31, 3
+# CHECK-NEXT:    bl .+67108816
+# CHECK-NEXT:    ld 2, 24(1)
+# CHECK-NEXT:    add 3, 3, 31
+# CHECK-NEXT:    addi 1, 1, 32
+# CHECK-NEXT:    ld 0, -16(1)
+# CHECK-NEXT:    mtlr 0
+# CHECK-NEXT:    blr
+# CHECK-EMPTY:
+# CHECK-NEXT:  def:
+# CHECK-NEXT:    addis 2, 12, 2
+# CHECK-NEXT:    addi 2, 2, -32636
+# CHECK-NEXT:    li 3, 55
+# CHECK-NEXT:    blr
Index: test/ELF/Inputs/ppc64-bsymbolic-local-def.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/ppc64-bsymbolic-local-def.s
@@ -0,0 +1,14 @@
+        .abiversion 2
+        .section ".text"
+
+        .p2align 2
+        .global def
+        .type def, @function
+def:
+.Ldef_gep:
+    addis 2, 12, .TOC.-.Ldef_gep at ha
+    addi 2, 2, .TOC.-.Ldef_gep at l
+.Ldef_lep:
+    .localentry def, .-def
+    li 3, 55
+    blr


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52523.167021.patch
Type: text/x-patch
Size: 2992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180925/ab655f77/attachment.bin>


More information about the llvm-commits mailing list