2 # RUN: echo '.tbss; .globl b, c; b: .zero 4; c:' > %t.s
3 # RUN: echo '.globl __tls_get_addr; __tls_get_addr:' > %tga.s
5 ## RISC-V psABI doesn't specify TLS relaxation. Though the code sequences are not
6 ## relaxed, dynamic relocations can be omitted for GD->LE relaxation.
8 # RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o
9 # RUN: llvm-mc -filetype=obj -triple=riscv32 %t.s -o %t1.32.o
10 # RUN: ld.lld -shared -soname=t1.so %t1.32.o -o %t1.32.so
11 # RUN: llvm-mc -filetype=obj -triple=riscv32 %tga.s -o %tga.32.o
13 # RUN: ld.lld -shared %t.32.o %t1.32.o -o %t.32.so
14 # RUN: llvm-readobj -r %t.32.so | FileCheck --check-prefix=GD32-REL %s
15 # RUN: llvm-objdump -d --no-show-raw-insn %t.32.so | FileCheck --check-prefix=GD32 %s
17 # RUN: ld.lld %t.32.o %t1.32.o %tga.32.o -o %t.32
18 # RUN: llvm-readelf -r %t.32 | FileCheck --check-prefix=NOREL %s
19 # RUN: llvm-readelf -x .got %t.32 | FileCheck --check-prefix=LE32-GOT %s
20 # RUN: ld.lld -pie %t.32.o %t1.32.o %tga.32.o -o %t.32
21 # RUN: llvm-readelf -r %t.32 | FileCheck --check-prefix=NOREL %s
22 # RUN: llvm-readelf -x .got %t.32 | FileCheck --check-prefix=LE32-GOT %s
24 # RUN: ld.lld %t.32.o %t1.32.so %tga.32.o -o %t.32
25 # RUN: llvm-readobj -r %t.32 | FileCheck --check-prefix=IE32-REL %s
26 # RUN: llvm-readelf -x .got %t.32 | FileCheck --check-prefix=IE32-GOT %s
28 # RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o
29 # RUN: llvm-mc -filetype=obj -triple=riscv64 %t.s -o %t1.64.o
30 # RUN: ld.lld -shared -soname=t1.so %t1.64.o -o %t1.64.so
31 # RUN: llvm-mc -filetype=obj -triple=riscv64 %tga.s -o %tga.64.o
33 # RUN: ld.lld -shared %t.64.o %t1.64.o -o %t.64.so
34 # RUN: llvm-readobj -r %t.64.so | FileCheck --check-prefix=GD64-REL %s
35 # RUN: llvm-objdump -d --no-show-raw-insn %t.64.so | FileCheck --check-prefix=GD64 %s
37 # RUN: ld.lld %t.64.o %t1.64.o %tga.64.o -o %t.64
38 # RUN: llvm-readelf -r %t.64 | FileCheck --check-prefix=NOREL %s
39 # RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=LE64-GOT %s
40 # RUN: ld.lld -pie %t.64.o %t1.64.o %tga.64.o -o %t.64
41 # RUN: llvm-readelf -r %t.64 | FileCheck --check-prefix=NOREL %s
42 # RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=LE64-GOT %s
44 # RUN: ld.lld %t.64.o %t1.64.so %tga.64.o -o %t.64
45 # RUN: llvm-readobj -r %t.64 | FileCheck --check-prefix=IE64-REL %s
46 # RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=IE64-GOT %s
48 # GD32-REL: .rela.dyn {
49 # GD32-REL-NEXT: 0x2314 R_RISCV_TLS_DTPMOD32 a 0x0
50 # GD32-REL-NEXT: 0x2318 R_RISCV_TLS_DTPREL32 a 0x0
51 # GD32-REL-NEXT: 0x231C R_RISCV_TLS_DTPMOD32 b 0x0
52 # GD32-REL-NEXT: 0x2320 R_RISCV_TLS_DTPREL32 b 0x0
55 ## &DTPMOD(a) - . = 0x2314 - 0x1250 = 4096*1+196
56 # GD32: 1250: auipc a0, 0x1
57 # GD32-NEXT: addi a0, a0, 0xc4
58 # GD32-NEXT: auipc ra, 0x0
59 # GD32-NEXT: jalr 0x38(ra)
61 ## &DTPMOD(b) - . = 0x231C - 0x1260 = 4096*1+188
62 # GD32: 1260: auipc a0, 0x1
63 # GD32-NEXT: addi a0, a0, 0xbc
64 # GD32-NEXT: auipc ra, 0x0
65 # GD32-NEXT: jalr 0x28(ra)
67 # GD64-REL: .rela.dyn {
68 # GD64-REL-NEXT: 0x24D8 R_RISCV_TLS_DTPMOD64 a 0x0
69 # GD64-REL-NEXT: 0x24E0 R_RISCV_TLS_DTPREL64 a 0x0
70 # GD64-REL-NEXT: 0x24E8 R_RISCV_TLS_DTPMOD64 b 0x0
71 # GD64-REL-NEXT: 0x24F0 R_RISCV_TLS_DTPREL64 b 0x0
74 ## &DTPMOD(a) - . = 0x24d8 - 0x1398 = 4096*1+320
75 # GD64: 1398: auipc a0, 0x1
76 # GD64-NEXT: addi a0, a0, 0x140
77 # GD64-NEXT: auipc ra, 0x0
78 # GD64-NEXT: jalr 0x40(ra)
80 ## &DTPMOD(b) - . = 0x24e8 - 0x13a8 = 4096*1+320
81 # GD64: 13a8: auipc a0, 0x1
82 # GD64-NEXT: addi a0, a0, 0x140
83 # GD64-NEXT: auipc ra, 0x0
84 # GD64-NEXT: jalr 0x30(ra)
86 # NOREL: no relocations
88 ## .got contains pre-populated values: [a@dtpmod, a@dtprel, b@dtpmod, b@dtprel]
89 ## a@dtprel = st_value(a)-0x800 = 0xfffff808
90 ## b@dtprel = st_value(b)-0x800 = 0xfffff80c
91 # LE32-GOT: section '.got':
92 # LE32-GOT-NEXT: 0x[[#%x,A:]] [[#%x,GOT:]] 01000000 08f8ffff 01000000
93 # LE32-GOT-NEXT: 0x[[#%x,A:]] 0cf8ffff
94 # LE64-GOT: section '.got':
95 # LE64-GOT-NEXT: 0x[[#%x,A:]] [[#%x,GOT:]] [[#%x,GOT:]] 01000000 00000000
96 # LE64-GOT-NEXT: 0x[[#%x,A:]] 08f8ffff ffffffff 01000000 00000000
97 # LE64-GOT-NEXT: 0x[[#%x,A:]] 0cf8ffff ffffffff
99 ## a is local - relaxed to LE - its DTPMOD/DTPREL slots are link-time constants.
100 ## b is external - DTPMOD/DTPREL dynamic relocations are required.
101 # IE32-REL: .rela.dyn {
102 # IE32-REL-NEXT: 0x12234 R_RISCV_TLS_DTPMOD32 b 0x0
103 # IE32-REL-NEXT: 0x12238 R_RISCV_TLS_DTPREL32 b 0x0
105 # IE32-GOT: section '.got':
106 # IE32-GOT-NEXT: 0x00012228 c8210100 01000000 08f8ffff 00000000
107 # IE32-GOT-NEXT: 0x00012238 00000000
109 # IE64-REL: .rela.dyn {
110 # IE64-REL-NEXT: 0x12398 R_RISCV_TLS_DTPMOD64 b 0x0
111 # IE64-REL-NEXT: 0x123A0 R_RISCV_TLS_DTPREL64 b 0x0
113 # IE64-GOT: section '.got':
114 # IE64-GOT-NEXT: 0x00012380 c0220100 00000000 01000000 00000000
115 # IE64-GOT-NEXT: 0x00012390 08f8ffff ffffffff 00000000 00000000
116 # IE64-GOT-NEXT: 0x000123a0 00000000 00000000
119 call __tls_get_addr@plt
122 call __tls_get_addr@plt