[lld] r343728 - [PPC64] Add test documenting toc-restore when linking with -Bsymbolic. [NFC]

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 3 14:58:42 PDT 2018


Author: sfertile
Date: Wed Oct  3 14:58:42 2018
New Revision: 343728

URL: http://llvm.org/viewvc/llvm-project?rev=343728&view=rev
Log:
[PPC64] Add test documenting toc-restore when linking with -Bsymbolic. [NFC]

Differential Revision: https://reviews.llvm.org/D52523

Added:
    lld/trunk/test/ELF/Inputs/ppc64-bsymbolic-local-def.s
    lld/trunk/test/ELF/ppc64-bsymbolic-toc-restore.s

Added: lld/trunk/test/ELF/Inputs/ppc64-bsymbolic-local-def.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/ppc64-bsymbolic-local-def.s?rev=343728&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/ppc64-bsymbolic-local-def.s (added)
+++ lld/trunk/test/ELF/Inputs/ppc64-bsymbolic-local-def.s Wed Oct  3 14:58:42 2018
@@ -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

Added: lld/trunk/test/ELF/ppc64-bsymbolic-toc-restore.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-bsymbolic-toc-restore.s?rev=343728&view=auto
==============================================================================
--- lld/trunk/test/ELF/ppc64-bsymbolic-toc-restore.s (added)
+++ lld/trunk/test/ELF/ppc64-bsymbolic-toc-restore.s Wed Oct  3 14:58:42 2018
@@ -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




More information about the llvm-commits mailing list