1# REQUIRES: ppc
2
3## Test that we create canonical PLT entries for -no-pie.
4
5# RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
6# RUN: llvm-mc -filetype=obj -triple=powerpc %p/Inputs/canonical-plt-pcrel.s -o %t1.o
7# RUN: ld.lld %t1.o -o %t1.so -shared -soname=so
8
9# RUN: ld.lld %t.o %t1.so -o %t
10# RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
11# RUN: llvm-readelf -S -s %t | FileCheck --check-prefix=SYM %s
12# RUN: llvm-readelf -x .plt %t | FileCheck --check-prefix=HEX %s
13# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
14
15# REL:      Relocations [
16# REL-NEXT:   .rela.plt {
17# REL-NEXT:     0x10030318 R_PPC_JMP_SLOT func 0x0
18# REL-NEXT:     0x1003031C R_PPC_JMP_SLOT func2 0x0
19# REL-NEXT:     0x10030320 R_PPC_JMP_SLOT ifunc 0x0
20# REL-NEXT:   }
21# REL-NEXT: ]
22
23# SYM: .glink PROGBITS 1001022c
24
25## st_value points to the canonical PLT entry in .glink
26# SYM: Symbol table '.dynsym'
27# SYM: 1001023c 0 FUNC GLOBAL DEFAULT UND func
28# SYM: 1001022c 0 FUNC GLOBAL DEFAULT UND func2
29# SYM: 1001024c 0 FUNC GLOBAL DEFAULT UND ifunc
30# SYM: Symbol table '.symtab'
31# SYM: 1001023c 0 FUNC GLOBAL DEFAULT UND func
32# SYM: 1001022c 0 FUNC GLOBAL DEFAULT UND func2
33# SYM: 1001024c 0 FUNC GLOBAL DEFAULT UND ifunc
34
35# HEX: 0x10030318 1001025c 10010260 10010264
36
37## Canonical PLT entry of func2.
38## 0x1003031C = 65536*4099+796
39# CHECK:      1001022c <.glink>:
40# CHECK-NEXT:           lis 11, 4099
41# CHECK-NEXT:           lwz 11, 796(11)
42# CHECK-NEXT:           mtctr 11
43# CHECK-NEXT:           bctr
44
45## Canonical PLT entry of func.
46## 0x10030318 = 65536*4099+792
47# CHECK-NEXT: 1001023c: lis 11, 4099
48# CHECK-NEXT:           lwz 11, 792(11)
49# CHECK-NEXT:           mtctr 11
50# CHECK-NEXT:           bctr
51
52## Canonical PLT entry of ifunc.
53## 0x10030320 = 65536*4099+800
54# CHECK-NEXT: 1001024c: lis 11, 4099
55# CHECK-NEXT:           lwz 11, 800(11)
56# CHECK-NEXT:           mtctr 11
57# CHECK-NEXT:           bctr
58
59## The 3 b instructions are referenced by .plt entries.
60# CHECK-NEXT: 1001025c: b 0x10010268
61# CHECK-NEXT:           b 0x10010268
62# CHECK-NEXT:           b 0x10010268
63
64## PLTresolve of 64 bytes is at the end.
65## Operands of addis & addi: -0x1001025c = 65536*-4097-604
66# CHECK-NEXT:           lis 12, 0
67# CHECK-NEXT:           addis 11, 11, -4097
68# CHECK-NEXT:           lwz 0, 4(12)
69# CHECK-NEXT:           addi 11, 11, -604
70# CHECK-NEXT:           mtctr 0
71# CHECK-NEXT:           add 0, 11, 11
72# CHECK-NEXT:           lwz 12, 8(12)
73# CHECK-NEXT:           add 11, 0, 11
74# CHECK-NEXT:           bctr
75# CHECK-COUNT-7:        nop
76
77.globl _start
78_start:
79  b func
80  lis 3, func2@ha
81  la 3, func2@l(3)
82  lis 3, func@ha
83  la 3, func@l(3)
84  lis 4, ifunc@ha
85  la 4, ifunc@l(4)
86