1# REQUIRES: ppc
2
3# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t1.o
4# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-bsymbolic-local-def.s  -o %t2.o
5# RUN: ld.lld -Bsymbolic -shared %t1.o %t2.o -o %t
6# RUN: llvm-objdump -d -r --no-show-raw-insn %t | FileCheck %s
7# RUN: not ld.lld -shared %t1.o %t2.o -o /dev/null 2>&1 | FileCheck --check-prefix=FAIL %s
8
9# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t1.o
10# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-bsymbolic-local-def.s  -o %t2.o
11# RUN: ld.lld -Bsymbolic -shared %t1.o %t2.o -o %t
12# RUN: llvm-objdump -d -r --no-show-raw-insn %t | FileCheck %s
13# RUN: not ld.lld -shared %t1.o %t2.o -o /dev/null 2>&1 | FileCheck --check-prefix=FAIL %s
14
15# FAIL: call to def lacks nop, can't restore toc
16
17# Test to document the toc-restore behavior with -Bsymbolic option. Since
18# -Bsymbolic causes the call to bind to the internal definition we know the
19# caller and callee share the same TOC base. This means branching to the
20# local entry point of the callee, and no need for a nop to follow the call
21# (since there is no need to restore the TOC-pointer after the call).
22
23        .abiversion 2
24        .section ".text"
25
26        .p2align 2
27        .global caller
28        .type caller, @function
29caller:
30.Lcaller_gep:
31    addis 2, 12, .TOC.-.Lcaller_gep@ha
32    addi  2, 2, .TOC.-.Lcaller_gep@l
33.Lcaller_lep:
34    .localentry caller, .-caller
35    mflr 0
36    std 0, -16(1)
37    stdu 1, -32(1)
38    bl def
39    mr 31, 3
40    bl not_defined
41    nop
42    add 3, 3, 31
43    addi 1, 1, 32
44    ld 0, -16(1)
45    mtlr 0
46    blr
47
48# Note that the bl .+44 is a call to def's local entry, jumping past the first 2
49# instructions. Branching to the global entry would corrupt the TOC pointer
50# since the global entry requires that %r12 hold the address of the function
51# being called.
52
53# CHECK-LABEL: caller
54# CHECK:         bl 0x[[DEF:[0-9a-f]+]]
55# CHECK-NEXT:    mr 31, 3
56# CHECK-NEXT:    bl 0x[[NOT_DEFINED:[0-9a-f]+]]
57# CHECK-NEXT:    ld 2, 24(1)
58# CHECK-NEXT:    add 3, 3, 31
59# CHECK-NEXT:    addi 1, 1, 32
60# CHECK-NEXT:    ld 0, -16(1)
61# CHECK-NEXT:    mtlr 0
62# CHECK-NEXT:    blr
63# CHECK-EMPTY:
64# CHECK-NEXT:  <def>:
65# CHECK-NEXT:    addis 2, 12, 2
66# CHECK-NEXT:    addi 2, 2, -32448
67# CHECK-NEXT:    [[DEF]]: li 3, 55
68# CHECK-NEXT:    blr
69# CHECK-NEXT:    trap
70# CHECK-NEXT:    trap
71# CHECK-EMPTY:
72# CHECK-NEXT:  00000000000[[NOT_DEFINED]] <__plt_not_defined>:
73