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 LD->LE relaxation.
7 ## LD uses the same relocation as GD: R_RISCV_GD_HI20, the difference is that it
8 ## references a local symbol (.LANCHOR0).
10 # RUN: llvm-mc -filetype=obj -triple=riscv32 -position-independent %s -o %t.32.o
11 # RUN: llvm-mc -filetype=obj -triple=riscv32 %tga.s -o %tga.o
13 # RUN: ld.lld -shared %t.32.o -o %t.32.so
14 # RUN: llvm-readobj -r %t.32.so | FileCheck --check-prefix=LD32-REL %s
15 # RUN: llvm-readelf -x .got %t.32.so | FileCheck --check-prefix=LD32-GOT %s
16 # RUN: llvm-objdump -d --no-show-raw-insn %t.32.so | FileCheck --check-prefixes=LD,LD32 %s
18 # RUN: ld.lld %t.32.o %tga.o -o %t.32
19 # RUN: llvm-readelf -r %t.32 | FileCheck --check-prefix=NOREL %s
20 # RUN: llvm-readelf -x .got %t.32 | FileCheck --check-prefix=LE32-GOT %s
21 # RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE,LE32 %s
23 # RUN: llvm-mc -filetype=obj -triple=riscv64 -position-independent %s -o %t.64.o
24 # RUN: llvm-mc -filetype=obj -triple=riscv64 %tga.s -o %tga.o
26 # RUN: ld.lld -shared %t.64.o -o %t.64.so
27 # RUN: llvm-readobj -r %t.64.so | FileCheck --check-prefix=LD64-REL %s
28 # RUN: llvm-readelf -x .got %t.64.so | FileCheck --check-prefix=LD64-GOT %s
29 # RUN: llvm-objdump -d --no-show-raw-insn %t.64.so | FileCheck --check-prefixes=LD,LD64 %s
31 # RUN: ld.lld %t.64.o %tga.o -o %t.64
32 # RUN: llvm-readelf -r %t.64 | FileCheck --check-prefix=NOREL %s
33 # RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=LE64-GOT %s
34 # RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE,LE64 %s
36 ## a@dtprel = st_value(a)-0x800 = 0xfffff808 is a link-time constant.
37 # LD32-REL: .rela.dyn {
38 # LD32-REL-NEXT: 0x22AC
39 # LD32-REL-NEXT: 0x22B0 R_RISCV_TLS_DTPMOD32 - 0x0
41 # LD32-GOT: section '.got':
42 # LD32-GOT-NEXT: 0x000022a8 30220000 00000000 00000000 00f8ffff
44 # LD64-REL: .rela.dyn {
45 # LD64-REL-NEXT: 0x2448
46 # LD64-REL-NEXT: 0x2450 R_RISCV_TLS_DTPMOD64 - 0x0
48 # LD64-GOT: section '.got':
49 # LD64-GOT-NEXT: 0x00002440 50230000 00000000 00000000 00000000
50 # LD64-GOT-NEXT: 0x00002450 00000000 00000000 00f8ffff ffffffff
52 ## rv32: &DTPMOD(a) - . = 0x22b0 - 0x11d8 = 4096*1+216
53 ## rv64: &DTPMOD(a) - . = 0x2450 - 0x12f8 = 4096*1+344
54 # LD32: 11d8: auipc a0, 0x1
55 # LD32-NEXT: addi a0, a0, 0xd8
56 # LD64: 12f8: auipc a0, 0x1
57 # LD64-NEXT: addi a0, a0, 0x158
58 # LD-NEXT: auipc ra, 0x0
59 # LD-NEXT: jalr 0x40(ra)
61 # NOREL: no relocations
63 ## a is local - its DTPMOD/DTPREL slots are link-time constants.
64 ## a@dtpmod = 1 (main module)
65 # LE32-GOT: section '.got':
66 # LE32-GOT-NEXT: 0x00012134 00000000 34210100 01000000 00f8ffff
68 # LE64-GOT: section '.got':
69 # LE64-GOT-NEXT: 0x000121e8 00000000 00000000 e8210100 00000000
70 # LE64-GOT-NEXT: 0x000121f8 01000000 00000000 00f8ffff ffffffff
72 ## rv32: DTPMOD(.LANCHOR0) - . = 0x1213c - 0x11114 = 4096*1+40
73 ## rv64: DTPMOD(.LANCHOR0) - . = 0x121f8 - 0x111c8 = 4096*1+48
74 # LE32: 11114: auipc a0, 0x1
75 # LE32-NEXT: addi a0, a0, 0x28
76 # LE64: 111c8: auipc a0, 0x1
77 # LE64-NEXT: addi a0, a0, 0x30
78 # LE-NEXT: auipc ra, 0x0
79 # LE-NEXT: jalr 0x18(ra)
81 la.tls.gd a0
, .LANCHOR0
82 call __tls_get_addr@plt
86 ## This is irrelevant to TLS. We use it to take 2 GOT slots to check DTPREL
87 ## offsets are correct.
88 la a5
, _GLOBAL_OFFSET_TABLE_
90 .section .tbss,"awT",@nobits