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: 00000000010040d8  0000000100000049 R_PPC64_TPREL64        0000000000000000 x + 0
46# IE-RELOC: 00000000010040e0  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 7 entries:
58# LE-SYM: 5: 0000000000000000     0 TLS     GLOBAL DEFAULT     6 x
59# LE-SYM: 6: 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, 12504(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: <IEVal>:
78# IE-NEXT:    pld 3, 8408(0), 1
79# IE-NEXT:    lwzx 3, 3, 13
80# IE-NEXT:    blr
81# LE-LABEL: <IEVal>:
82# LE-NEXT:    paddi 3, 13, -28672, 0
83# LE-NEXT:    lwz 3, 0(3)
84# LE-NEXT:    blr
85.section .text_val, "ax", %progbits
86IEVal:
87	pld 3, x@got@tprel@pcrel(0), 1
88	lwzx 3, 3, x@tls@pcrel
89	blr
90
91# IE-LABEL: <IETwoVal>:
92# IE-NEXT:    pld 3, 4312(0), 1
93# IE-NEXT:    pld 4, 4312(0), 1
94# IE-NEXT:    lwzx 3, 3, 13
95# IE-NEXT:    lwzx 4, 4, 13
96# IE-NEXT:    blr
97# LE-LABEL: <IETwoVal>:
98# LE-NEXT:    paddi 3, 13, -28672, 0
99# LE-NEXT:    paddi 4, 13, -28668, 0
100# LE-NEXT:    lwz 3, 0(3)
101# LE-NEXT:    lwz 4, 0(4)
102# LE-NEXT:    blr
103.section .text_twoval, "ax", %progbits
104IETwoVal:
105	pld 3, x@got@tprel@pcrel(0), 1
106	pld 4, y@got@tprel@pcrel(0), 1
107	lwzx 3, 3, x@tls@pcrel
108	lwzx 4, 4, y@tls@pcrel
109	blr
110
111# IE-LABEL: <IEIncrementVal>:
112# IE-NEXT:    pld 4, 224(0), 1
113# IE-NEXT:    lwzx 3, 4, 13
114# IE-NEXT:    stwx 3, 4, 13
115# IE-NEXT:    blr
116# LE-LABEL: <IEIncrementVal>:
117# LE-NEXT:    paddi 4, 13, -28668, 0
118# LE-NEXT:    lwz 3, 0(4)
119# LE-NEXT:    stw 3, 0(4)
120# LE-NEXT:    blr
121.section .text_incrval, "ax", %progbits
122IEIncrementVal:
123	pld 4, y@got@tprel@pcrel(0), 1
124	lwzx 3, 4, y@tls@pcrel
125	stwx 3, 4, y@tls@pcrel
126	blr
127