xref: /llvm-project/lld/test/ELF/ppc64-pcrel-call-to-toc.s (revision 7198c87f42f6c15d76b127c1c63530e9b4d5dd39)
1# REQUIRES: ppc
2# RUN: echo 'SECTIONS { \
3# RUN:   .text_func   0x10010000 : { *(.text_func) } \
4# RUN:   .text_callee 0x10020000 : { *(.text_callee) } \
5# RUN:   .text_caller 0x10030000 : { *(.text_caller) } \
6# RUN:   }' > %t.script
7
8# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
9# RUN: ld.lld -T %t.script %t.o -o %t
10# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL
11# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
12
13# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o
14# RUN: ld.lld -T %t.script %t.o -o %t --no-power10-stubs --power10-stubs=yes
15# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL
16# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
17
18# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
19# RUN: ld.lld -T %t.script %t.o -o %t --power10-stubs=auto --no-power10-stubs
20# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL
21# RUN: llvm-objdump -d --no-show-raw-insn %t \
22# RUN: | FileCheck %s --check-prefix=CHECK-NOP10
23
24## When a function without TOC accesses a function using TOC, an r12 setup stub
25## is inserted
26
27# SYMBOL:      1: 0000000010010000 0 NOTYPE LOCAL DEFAULT 1 func
28# SYMBOL-NEXT: 2: 0000000010020000 0 NOTYPE LOCAL DEFAULT [<other: 0x60>] 2 callee
29# SYMBOL:      4: 0000000010030000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 3 caller
30# SYMBOL:      6: 0000000010030010 32 FUNC LOCAL DEFAULT 3 __gep_setup_callee
31
32# CHECK-LABEL: <func>:
33# CHECK-NEXT:  blr
34
35# CHECK-LABEL: <callee>:
36# CHECK:       bl 0x10010000
37# CHECK-NEXT:  addis 4, 2, -1
38# CHECK-NEXT:  lwz 4, 32728(4)
39# CHECK-NEXT:  blr
40
41# CHECK-LABEL: <caller>:
42# CHECK-NEXT:  bl 0x10030010
43# CHECK-NEXT:  blr
44
45# CHECK-LABEL: <__gep_setup_callee>:
46# CHECK-NEXT:  paddi 12, 0, -65552, 1
47# CHECK-NEXT:  mtctr 12
48# CHECK-NEXT:  bctr
49
50# CHECK-NOP10-LABEL: <__gep_setup_callee>:
51# CHECK-NOP10-NEXT:  mflr 12
52# CHECK-NOP10-NEXT:  bcl 20, 31, 0x10030018
53# CHECK-NOP10-NEXT:  mflr 11
54# CHECK-NOP10-NEXT:  mtlr 12
55# CHECK-NOP10-NEXT:  addis 12, 11, -1
56# CHECK-NOP10-NEXT:  addi 12, 12, -24
57# CHECK-NOP10-NEXT:  mtctr 12
58# CHECK-NOP10-NEXT:  bctr
59
60.section .text_func, "ax", %progbits
61func:
62  blr
63
64.section .text_callee, "ax", %progbits
65callee:
66.Lfunc_gep1:
67  addis 2, 12, .TOC.-.Lfunc_gep1@ha
68  addi 2, 2, .TOC.-.Lfunc_gep1@l
69.Lfunc_lep1:
70  .localentry callee, .Lfunc_lep1-.Lfunc_gep1
71  bl func
72  addis 4, 2, global@toc@ha
73  lwz 4, global@toc@l(4)
74  blr
75
76.section .text_caller, "ax", %progbits
77caller:
78  .localentry caller, 1
79  bl callee@notoc
80  blr
81global:
82  .long	0
83  .size	global, 4
84