[memprof] Remove an unused using directive (#117004)
[llvm-project.git] / lld / test / ELF / ppc64-local-exec-tls.s
blobf5cb683b9fcfc0ecf5b5ac46d78b733a83288540
1 // REQUIRES: ppc
2 // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
3 // RUN: ld.lld %t.o -o %t
4 // RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s
5 // RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s
7 // RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
9 /// Reject local-exec TLS relocations for -shared.
10 // ERR: error: relocation R_PPC64_TPREL16_HA against a cannot be used with -shared
11 // ERR: error: relocation R_PPC64_TPREL16_LO against a cannot be used with -shared
12 // ERR: error: relocation R_PPC64_TPREL16 against b cannot be used with -shared
13 // ERR: error: relocation R_PPC64_TPREL16_HI against b cannot be used with -shared
14 // ERR: error: relocation R_PPC64_TPREL16_DS against b cannot be used with -shared
15 // ERR: error: relocation R_PPC64_TPREL16_LO_DS against b cannot be used with -shared
16 // ERR: error: relocation R_PPC64_TPREL16_HIGHESTA against b cannot be used with -shared
17 // ERR: error: relocation R_PPC64_TPREL16_HIGHERA against b cannot be used with -shared
19 .text
20 .abiversion 2
21 .globl test_local_exec # -- Begin function test_local_exec
22 .p2align 4
23 .type test_local_exec,@function
24 test_local_exec: # @test_local_exec
25 .Lfunc_begin0:
26 # %bb.0: # %entry
27 li 3, 0
28 stw 3, -12(1)
29 addis 3, 13, a@tprel@ha
30 addi 3, 3, a@tprel@l
31 ld 3, 0(3)
32 mr 4, 3
33 extsw 3, 4
34 blr
35 .long 0
36 .quad 0
37 .Lfunc_end0:
38 .size test_local_exec, .Lfunc_end0-.Lfunc_begin0
39 # -- End function
40 test_tprel:
41 .Lfunc_gep1:
42 addis 2, 12, .TOC.-.Lfunc_gep1@ha
43 addi 2, 2, .TOC.-.Lfunc_gep1@l
44 .Lfunc_lep1:
45 .localentry test_tprel, .Lfunc_lep1-.Lfunc_gep1
46 addi 3, 13, b@tprel
47 blr
50 test_hi:
51 .Lfunc_gep2:
52 addis 2, 12, .TOC.-.Lfunc_gep2@ha
53 addi 2, 2, .TOC.-.Lfunc_gep2@l
54 .Lfunc_lep2:
55 .localentry test_hi, .Lfunc_lep2-.Lfunc_gep2
56 addis 3, 13, b@tprel@h
57 blr
59 test_ds:
60 .Lfunc_gep3:
61 addis 2, 12, .TOC.-.Lfunc_gep3@ha
62 addi 2, 2, .TOC.-.Lfunc_gep3@l
63 .Lfunc_lep3:
64 .localentry test_ds, .Lfunc_lep3-.Lfunc_gep3
65 ld 3, b@tprel(13)
66 blr
68 test_lo_ds:
69 .Lfunc_gep4:
70 addis 2, 12, .TOC.-.Lfunc_gep4@ha
71 addi 2, 2, .TOC.-.Lfunc_gep4@l
72 .Lfunc_lep4:
73 .localentry test_lo_ds, .Lfunc_lep4-.Lfunc_gep4
74 ld 3, b@tprel@l(13)
75 blr
77 test_highest_a:
78 .Lfunc_gep5:
79 addis 2, 12, .TOC.-.Lfunc_gep5@ha
80 addi 2, 2, .TOC.-.Lfunc_gep5@l
81 .Lfunc_lep5:
82 .localentry test_highest_a, .Lfunc_lep5-.Lfunc_gep5
83 lis 4, b@tprel@highesta
84 ori 4, 4, b@tprel@highera
85 lis 5, b@tprel@ha
86 addi 5, 5, b@tprel@l
87 sldi 4, 4, 32
88 or 4, 4, 5
89 add 3, 13, 4
90 blr
92 test_highest:
93 .Lfunc_gep6:
94 addis 2, 12, .TOC.-.Lfunc_gep6@ha
95 addi 2, 2, .TOC.-.Lfunc_gep6@l
96 .Lfunc_lep6:
97 .localentry test_highest, .Lfunc_lep6-.Lfunc_gep6
98 lis 4, b@tprel@highest
99 ori 4, 4, b@tprel@higher
100 sldi 4, 4, 32
101 oris 4, 4, b@tprel@h
102 ori 4, 4, b@tprel@l
103 add 3, 13, 4
106 .type a,@object # @a
107 .type b,@object # @b
108 .section .tdata,"awT",@progbits
109 .p2align 3
111 .quad 55 # 0x37
112 .size a, 8
115 .quad 55 # 0x37
116 .size b, 8
118 // Verify that the input has every initial-exec tls relocation type.
119 // InputRelocs: Relocation section '.rela.text'
120 // InputRelocs: R_PPC64_TPREL16_HA {{0+}} a + 0
121 // InputRelocs: R_PPC64_TPREL16_LO {{0+}} a + 0
122 // InputRelocs: R_PPC64_TPREL16 {{0+8}} b + 0
123 // InputRelocs: R_PPC64_TPREL16_HI {{0+8}} b + 0
124 // InputRelocs: R_PPC64_TPREL16_DS {{0+8}} b + 0
125 // InputRelocs: R_PPC64_TPREL16_LO_DS {{0+8}} b + 0
126 // InputRelocs: R_PPC64_TPREL16_HIGHESTA {{0+8}} b + 0
127 // InputRelocs: R_PPC64_TPREL16_HIGHERA {{0+8}} b + 0
128 // InputRelocs: R_PPC64_TPREL16_HIGHEST {{0+8}} b + 0
129 // InputRelocs: R_PPC64_TPREL16_HIGHER {{0+8}} b + 0
131 // The start of the TLS storage area is 0x7000 bytes before the thread pointer (r13).
132 // We are building the address of the first TLS variable, relative to the thread pointer.
133 // #ha(a@tprel) --> (0 - 0x7000 + 0x8000) >> 16 = 0
134 // #lo(a@tprel)) --> (0 - 0x7000) & 0xFFFF = -0x7000 = -28672
135 // Dis: <test_local_exec>:
136 // Dis: addis 3, 13, 0
137 // Dis: addi 3, 3, -28672
139 // We are building the offset for the second TLS variable
140 // Offset within tls storage - 0x7000
141 // b@tprel = 8 - 0x7000 = 28664
142 // Dis: <test_tprel>:
143 // Dis: addi 3, 13, -28664
145 // #hi(b@tprel) --> (8 - 0x7000) >> 16 = -1
146 // Dis: <test_hi>:
147 // Dis: addis 3, 13, -1
149 // b@tprel = 8 - 0x7000 = -28664
150 // Dis: <test_ds>:
151 // Dis: ld 3, -28664(13)
153 // #lo(b@tprel) --> (8 - 0x7000) & 0xFFFF = -28664
154 // Dis: <test_lo_ds>:
155 // Dis: ld 3, -28664(13)
157 // #highesta(b@tprel) --> ((0x8 - 0x7000 + 0x8000) >> 48) & 0xFFFF = 0
158 // #highera(b@tprel) --> ((0x8 - 0x7000 + 0x8000) >> 32) & 0xFFFF = 0
159 // #ha(k@dtprel) --> ((0x8 - 0x7000 + 0x8000) >> 16) & 0xFFFF = 0
160 // #lo(k@dtprel) --> ((0x8 - 0x7000) & 0xFFFF = -28664
161 // Dis: <test_highest_a>:
162 // Dis: lis 4, 0
163 // Dis: ori 4, 4, 0
164 // Dis: lis 5, 0
165 // Dis: addi 5, 5, -28664
167 // #highest(b@tprel) --> ((0x8 - 0x7000) >> 48) & 0xFFFF = 0xFFFF = -1
168 // #higher(b@tprel) --> ((0x8 - 0x7000) >> 32) & 0xFFFF = 0xFFFF = 65535
169 // #hi(k@dtprel) --> ((0x8 - 0x7000) >> 16) & 0xFFFF = 0xFFFF = 65535
170 // #lo(k@dtprel) --> ((0x8 - 0x7000) & 0xFFFF = 33796
171 // Dis: <test_highest>:
172 // Dis: lis 4, -1
173 // Dis: ori 4, 4, 65535
174 // Dis: oris 4, 4, 65535
175 // Dis: ori 4, 4, 36872