1# REQUIRES: ppc 2# RUN: echo 'SECTIONS { \ 3# RUN: .text_caller1 0x10010000 : { *(.text_caller1) } \ 4# RUN: .text_caller2 0x10020000 : { *(.text_caller2) } \ 5# RUN: .text_caller3 0x10030000 : { *(.text_caller3) } \ 6# RUN: }' > %t.script 7 8# RUN: llvm-mc -filetype=obj -triple=powerpc64le --defsym AUX=1 %s -o %t1.o 9# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t2.o 10# RUN: ld.lld --shared %t2.o -o %t2.so 11# RUN: ld.lld -T %t.script %t1.o %t2.so -o %t 12# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL 13# RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC 14# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL 15# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s 16 17# RUN: llvm-mc -filetype=obj -triple=powerpc64 --defsym AUX=1 %s -o %t1.o 18# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t2.o 19# RUN: ld.lld --shared %t2.o -o %t2.so 20# RUN: ld.lld -T %t.script %t1.o %t2.so -o %t 21# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL 22# RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC 23# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL 24# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s 25 26## The test is created to check that when a function without TOC access an 27## external function, a r12 setup stub is inserted. 28 29# SYMBOL: Symbol table '.dynsym' contains 4 entries: 30# SYMBOL: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x60>] UND callee_global_TOC 31# SYMBOL-NEXT: 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND callee_global_stother0 32# SYMBOL-NEXT: 3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x20>] UND callee_global_stother1 33 34# SYMBOL: Symbol table '.symtab' contains 12 entries: 35# SYMBOL: 2: 0000000010010000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 6 caller1 36# SYMBOL-NEXT: 3: 0000000010020000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 7 caller2 37# SYMBOL-NEXT: 4: 0000000010030000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 8 caller3 38# SYMBOL: 6: 0000000010010010 16 FUNC LOCAL DEFAULT 6 __plt_pcrel_callee_global_stother0 39# SYMBOL-NEXT: 7: 0000000010020010 16 FUNC LOCAL DEFAULT 7 __plt_pcrel_callee_global_stother1 40# SYMBOL-NEXT: 8: 0000000010030010 16 FUNC LOCAL DEFAULT 8 __plt_pcrel_callee_global_TOC 41# SYMBOL-NEXT: 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x60>] UND callee_global_TOC 42# SYMBOL-NEXT: 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND callee_global_stother0 43# SYMBOL-NEXT: 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x20>] UND callee_global_stother1 44 45## DT_PLTGOT points to .plt 46# SEC: .plt NOBITS 0000000010030148 040148 000028 00 WA 0 0 8 47# SEC: 0x0000000000000003 (PLTGOT) 0x10030148 48 49## The first 2 entries in the .plt are reserved for the dynamic linkers 50## usage. The JMP_SLOT relocations are stored at .plt[2], .plt[3], .plt[4]. 51## Check that we emit 3 R_PPC64_JMP_SLOT in .rela.plt. 52# REL: .rela.plt { 53# REL-NEXT: 0x10030158 R_PPC64_JMP_SLOT callee_global_stother0 0x0 54# REL-NEXT: 0x10030160 R_PPC64_JMP_SLOT callee_global_stother1 0x0 55# REL-NEXT: 0x10030168 R_PPC64_JMP_SLOT callee_global_TOC 0x0 56# REL-NEXT: } 57 58# CHECK-LABEL: <caller1>: 59# CHECK: 10010000: bl 0x10010010 60# CHECK-NEXT: 10010004: blr 61 62## .plt[2] - 0x10010010 = 0x10030158 - 0x10010010 = 0x20148 = 131400 63# CHECK-LABEL: <__plt_pcrel_callee_global_stother0>: 64# CHECK: 10010010: pld 12, 131400(0), 1 65# CHECK-NEXT: 10010018: mtctr 12 66# CHECK-NEXT: 1001001c: bctr 67 68# CHECK-LABEL: <caller2>: 69# CHECK: 10020000: bl 0x10020010 70# CHECK-NEXT: 10020004: blr 71 72## .plt[3] - 0x10020010 = 0x10030160 - 0x10020010 = 0x10150 = 65872 73# CHECK-LABEL: <__plt_pcrel_callee_global_stother1>: 74# CHECK: 10020010: pld 12, 65872(0), 1 75# CHECK-NEXT: 10020018: mtctr 12 76# CHECK-NEXT: 1002001c: bctr 77 78# CHECK-LABEL: <caller3>: 79# CHECK: 10030000: bl 0x10030010 80# CHECK-NEXT: 10030004: blr 81 82## .plt[4] - 0x10030010 = 0x10030168 - 0x10030010 = 0x150 = 344 83# CHECK-LABEL: <__plt_pcrel_callee_global_TOC>: 84# CHECK: 10030010: pld 12, 344(0), 1 85# CHECK-NEXT: 10030018: mtctr 12 86# CHECK-NEXT: 1003001c: bctr 87 88.ifdef AUX 89.section .text_caller1, "ax", %progbits 90caller1: 91 .localentry caller1, 1 92 bl callee_global_stother0@notoc 93 blr 94.section .text_caller2, "ax", %progbits 95caller2: 96 .localentry caller2, 1 97 bl callee_global_stother1@notoc 98 blr 99 100.section .text_caller3, "ax", %progbits 101caller3: 102 .localentry caller3, 1 103 bl callee_global_TOC@notoc 104 blr 105 106.else 107func_extern: 108 blr 109.globl callee_global_stother0 110callee_global_stother0: 111 blr 112.globl callee_global_stother1 113callee_global_stother1: 114 .localentry callee_global_stother1, 1 115 ## nop is not needed after bl for R_PPC64_REL24_NOTOC 116 bl func_extern@notoc 117 blr 118.globl callee_global_TOC 119callee_global_TOC: 120.Lfunc_gep1: 121 addis 2, 12, .TOC.-.Lfunc_gep1@ha 122 addi 2, 2, .TOC.-.Lfunc_gep1@l 123.Lfunc_lep1: 124 .localentry callee_global_TOC, .Lfunc_lep1-.Lfunc_gep1 125 addis 4, 2, global@toc@ha 126 lwz 3, global@toc@l(4) 127 blr 128global: 129 .long 0 130 .size global, 4 131.endif 132