1# REQUIRES: ppc
2
3# RUN: split-file %s %t
4
5# RUN: llvm-mc -filetype=obj -triple=powerpc64le %t/asm -o %t.o
6# RUN: llvm-mc -filetype=obj -triple=powerpc64le %t/defs -o %t-defs.o
7# RUN: ld.lld --shared %t-defs.o --soname=t-defs -o %t-defs.so
8# RUN: ld.lld -T %t/lds %t.o %t-defs.so -o %t-ie
9# RUN: ld.lld -T %t/lds %t.o %t-defs.o -o %t-le
10
11# RUN: llvm-readelf -r %t-ie | FileCheck %s --check-prefix=IE-RELOC
12# RUN: llvm-readelf -s %t-ie | FileCheck %s --check-prefix=IE-SYM
13# RUN: llvm-readelf -x .got %t-ie | FileCheck %s --check-prefix=IE-GOT
14# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t-ie | FileCheck %s --check-prefix=IE
15
16# RUN: llvm-readelf -r %t-le | FileCheck %s --check-prefix=LE-RELOC
17# RUN: llvm-readelf -s %t-le | FileCheck %s --check-prefix=LE-SYM
18# RUN: llvm-readelf -x .got %t-le 2>&1 | FileCheck %s --check-prefix=LE-GOT
19# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t-le | FileCheck %s --check-prefix=LE
20
21## This test checks the Initial Exec PC Relative TLS implementation.
22## The IE version checks that the relocations are generated correctly.
23## The LE version checks that the Initial Exec to Local Exec relaxation is
24## done correctly.
25
26#--- lds
27SECTIONS {
28  .text_addr 0x1001000 : { *(.text_addr) }
29  .text_val 0x1002000 : { *(.text_val) }
30  .text_twoval 0x1003000 : { *(.text_twoval) }
31  .text_incrval 0x1004000 : { *(.text_incrval) }
32}
33
34#--- defs
35.section .tbss,"awT",@nobits
36.globl	x
37x:
38	.long	0
39.globl	y
40y:
41	.long	0
42
43#--- asm
44# IE-RELOC: Relocation section '.rela.dyn' at offset 0x10090 contains 2 entries:
45# IE-RELOC: 00000000010040e0  0000000100000049 R_PPC64_TPREL64        0000000000000000 x + 0
46# IE-RELOC: 00000000010040e8  0000000200000049 R_PPC64_TPREL64        0000000000000000 y + 0
47
48# IE-SYM:   Symbol table '.dynsym' contains 3 entries:
49# IE-SYM:   1: 0000000000000000     0 TLS     GLOBAL DEFAULT   UND x
50# IE-SYM:   2: 0000000000000000     0 TLS     GLOBAL DEFAULT   UND y
51
52# IE-GOT:      Hex dump of section '.got':
53# IE-GOT-NEXT: 0x010040d8 d8c00001 00000000 00000000 00000000
54
55# LE-RELOC: There are no relocations in this file.
56
57# LE-SYM: Symbol table '.symtab' contains 8 entries:
58# LE-SYM: 6: 0000000000000000     0 TLS     GLOBAL DEFAULT     6 x
59# LE-SYM: 7: 0000000000000004     0 TLS     GLOBAL DEFAULT     6 y
60
61# LE-GOT: could not find section '.got'
62
63# IE-LABEL: <IEAddr>:
64# IE-NEXT:    pld 3, 12512(0), 1
65# IE-NEXT:    add 3, 3, 13
66# IE-NEXT:    blr
67# LE-LABEL: <IEAddr>:
68# LE-NEXT:    paddi 3, 13, -28672, 0
69# LE-NEXT:    nop
70# LE-NEXT:    blr
71.section .text_addr, "ax", %progbits
72IEAddr:
73	pld 3, x@got@tprel@pcrel(0), 1
74	add 3, 3, x@tls@pcrel
75	blr
76
77# IE-LABEL: <IEAddrCopy>:
78# IE-NEXT:    pld 3, 12496(0), 1
79# IE-NEXT:    add 4, 3, 13
80# IE-NEXT:    blr
81# LE-LABEL: <IEAddrCopy>:
82# LE-NEXT:    paddi 3, 13, -28672, 0
83# LE-NEXT:    mr 4, 3
84# LE-NEXT:    blr
85.section .text_addr, "ax", %progbits
86IEAddrCopy:
87	pld 3, x@got@tprel@pcrel(0), 1
88	add 4, 3, x@tls@pcrel
89	blr
90
91# IE-LABEL: <IEVal>:
92# IE-NEXT:    pld 3, 8416(0), 1
93# IE-NEXT:    lwzx 3, 3, 13
94# IE-NEXT:    blr
95# LE-LABEL: <IEVal>:
96# LE-NEXT:    paddi 3, 13, -28672, 0
97# LE-NEXT:    lwz 3, 0(3)
98# LE-NEXT:    blr
99.section .text_val, "ax", %progbits
100IEVal:
101	pld 3, x@got@tprel@pcrel(0), 1
102	lwzx 3, 3, x@tls@pcrel
103	blr
104
105# IE-LABEL: <IETwoVal>:
106# IE-NEXT:    pld 3, 4320(0), 1
107# IE-NEXT:    pld 4, 4320(0), 1
108# IE-NEXT:    lwzx 3, 3, 13
109# IE-NEXT:    lwzx 4, 4, 13
110# IE-NEXT:    blr
111# LE-LABEL: <IETwoVal>:
112# LE-NEXT:    paddi 3, 13, -28672, 0
113# LE-NEXT:    paddi 4, 13, -28668, 0
114# LE-NEXT:    lwz 3, 0(3)
115# LE-NEXT:    lwz 4, 0(4)
116# LE-NEXT:    blr
117.section .text_twoval, "ax", %progbits
118IETwoVal:
119	pld 3, x@got@tprel@pcrel(0), 1
120	pld 4, y@got@tprel@pcrel(0), 1
121	lwzx 3, 3, x@tls@pcrel
122	lwzx 4, 4, y@tls@pcrel
123	blr
124
125# IE-LABEL: <IEIncrementVal>:
126# IE-NEXT:    pld 4, 232(0), 1
127# IE-NEXT:    lwzx 3, 4, 13
128# IE-NEXT:    stwx 3, 4, 13
129# IE-NEXT:    blr
130# LE-LABEL: <IEIncrementVal>:
131# LE-NEXT:    paddi 4, 13, -28668, 0
132# LE-NEXT:    lwz 3, 0(4)
133# LE-NEXT:    stw 3, 0(4)
134# LE-NEXT:    blr
135.section .text_incrval, "ax", %progbits
136IEIncrementVal:
137	pld 4, y@got@tprel@pcrel(0), 1
138	lwzx 3, 4, y@tls@pcrel
139	stwx 3, 4, y@tls@pcrel
140	blr
141