ppc64-dtprel.s
5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// REQUIRES: ppc
// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
// RUN: ld.lld -shared %t.o -o %t.so
// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s
// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s
// RUN: llvm-readelf -x .got %t.so | FileCheck --check-prefix=HEX-LE %s
// RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=Dis %s
// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
// RUN: ld.lld -shared %t.o -o %t.so
// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s
// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s
// RUN: llvm-readelf -x .got %t.so | FileCheck --check-prefix=HEX-BE %s
// RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=Dis %s
.text
.abiversion 2
.globl test
.p2align 4
.type test,@function
test:
.Lfunc_gep0:
addis 2, 12, .TOC.-.Lfunc_gep0@ha
addi 2, 2, .TOC.-.Lfunc_gep0@l
.Lfunc_lep0:
.localentry test, .Lfunc_lep0-.Lfunc_gep0
mflr 0
std 0, 16(1)
stdu 1, -32(1)
addis 3, 2, i@got@tlsld@ha
addi 3, 3, i@got@tlsld@l
bl __tls_get_addr(i@tlsld)
nop
addi 4, 3, i@dtprel
lwa 4, i@dtprel(3)
ld 0, 16(1)
mtlr 0
blr
.globl test_64
.p2align 4
.type test_64,@function
.globl test_adjusted
.p2align 4
.type test_adjusted,@function
test_adjusted:
.Lfunc_gep1:
addis 2, 12, .TOC.-.Lfunc_gep1@ha
addi 2, 2, .TOC.-.Lfunc_gep1@l
.Lfunc_lep1:
.localentry test_adjusted, .Lfunc_lep1-.Lfunc_gep1
mflr 0
std 0, 16(1)
stdu 1, -32(1)
addis 3, 2, k@got@tlsld@ha
addi 3, 3, k@got@tlsld@l
bl __tls_get_addr(k@tlsld)
nop
lis 4, k@dtprel@highesta
ori 4, 4, k@dtprel@highera
lis 5, k@dtprel@ha
addi 5, 5, k@dtprel@l
sldi 4, 4, 32
or 4, 4, 5
add 3, 3, 4
addi 1, 1, 32
ld 0, 16(1)
mtlr 0
blr
.globl test_not_adjusted
.p2align 4
.type test_not_adjusted,@function
test_not_adjusted:
.Lfunc_gep2:
addis 2, 12, .TOC.-.Lfunc_gep2@ha
addi 2, 2, .TOC.-.Lfunc_gep2@l
.Lfunc_lep2:
.localentry test_not_adjusted, .Lfunc_lep2-.Lfunc_gep2
mflr 0
std 0, 16(1)
stdu 1, -32(1)
addis 3, 2, i@got@tlsld@ha
addi 3, 3, i@got@tlsld@l
bl __tls_get_addr(k@tlsld)
nop
lis 4, k@dtprel@highest
ori 4, 4, k@dtprel@higher
sldi 4, 4, 32
oris 4, 4, k@dtprel@h
ori 4, 4, k@dtprel@l
add 3, 3, 4
addi 1, 1, 32
ld 0, 16(1)
mtlr 0
blr
.section .debug_addr,"",@progbits
.quad i@dtprel+32768
.type i,@object
.section .tdata,"awT",@progbits
.space 1024
.p2align 2
i:
.long 55
.size i, 4
.space 1024 * 1024 * 4
.type k,@object
.p2align 2
k:
.long 128
.size k,4
// Verify the input has all the remaining DTPREL based relocations we want to
// test.
// InputRelocs: Relocation section '.rela.text'
// InputRelocs: R_PPC64_DTPREL16 {{[0-9a-f]+}} i + 0
// InputRelocs: R_PPC64_DTPREL16_DS {{[0-9a-f]+}} i + 0
// InputRelocs: R_PPC64_DTPREL16_HIGHESTA {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_HIGHERA {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_HA {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_HIGHEST {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_HIGHER {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_HI {{[0-9a-f]+}} k + 0
// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0
// InputRelocs: Relocation section '.rela.debug_addr'
// InputRelocs: R_PPC64_DTPREL64 {{[0-9a-f]+}} i + 8000
// Expect a single dynamic relocation in the '.rela.dyn section for the module id.
// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 1 entries:
// OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
// OutputRelocs-NEXT: R_PPC64_DTPMOD64
// The got entry for i is at .got+8*1 = 0x4209e0
// i@dtprel = 1024 - 0x8000 = -31744 = 0xffffffffffff8400
// HEX-LE: section '.got':
// HEX-LE-NEXT: 4209d0 d0894200 00000000 00000000 00000000
// HEX-LE-NEXT: 4209e0 00000000 00000000
// HEX-BE: section '.got':
// HEX-BE-NEXT: 4209d0 00000000 004289d0 00000000 00000000
// HEX-BE-NEXT: 4209e0 00000000 00000000
// Dis: <test>:
// Dis: addi 4, 3, -31744
// Dis-NEXT: lwa 4, -31744(3)
// #k@dtprel(1024 + 4 + 1024 * 1024 * 4) = 0x400404
// #highesta(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 48) & 0xffff = 0
// #highera(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 32) & 0xffff = 0
// #ha(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 16) & 0xffff = 64
// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = -31740
// Dis: <test_adjusted>:
// Dis: lis 4, 0
// Dis: ori 4, 4, 0
// Dis: lis 5, 64
// Dis: addi 5, 5, -31740
// #highest(k@dtprel) --> ((0x400404 - 0x8000) >> 48) & 0xffff = 0
// #higher(k@dtprel) --> ((0x400404 - 0x8000) >> 32) & 0xffff = 0
// #hi(k@dtprel) --> ((0x400404 - 0x8000) >> 16) & 0xffff = 63
// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = 33796
// Dis: <test_not_adjusted>:
// Dis: lis 4, 0
// Dis: ori 4, 4, 0
// Dis: oris 4, 4, 63
// Dis: ori 4, 4, 33796