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