xref: /llvm-project/lld/test/ELF/riscv-tls-le.s (revision c532ba4edd7ad7675ba450ba43268aa9e7bda46b)
1# REQUIRES: riscv
2
3## Additionally test that (a) -no-pie/-pie have the same behavior
4## (b) --no-relax/--relax have the same behavior when R_RISCV_RELAX is suppressed.
5# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o
6# RUN: ld.lld --relax %t.32.o -o %t.32
7# RUN: llvm-nm -p %t.32 | FileCheck --check-prefixes=NM %s
8# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE %s
9# RUN: ld.lld -pie --no-relax %t.32.o -o %t.32
10# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE %s
11
12# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %s -o %t.64.o
13# RUN: ld.lld --no-relax %t.64.o -o %t.64
14# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE %s
15# RUN: ld.lld -pie --no-relax %t.64.o -o %t.64
16# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE %s
17# RUN: ld.lld %t.64.o -o %t.64.relax
18# RUN: llvm-objdump -d --no-show-raw-insn %t.64.relax | FileCheck --check-prefixes=LE-RELAX %s
19
20# RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
21
22# ERR: error: relocation R_RISCV_TPREL_HI20 against .LANCHOR0 cannot be used with -shared
23# ERR: error: relocation R_RISCV_TPREL_LO12_I against .LANCHOR0 cannot be used with -shared
24# ERR: error: relocation R_RISCV_TPREL_HI20 against a cannot be used with -shared
25# ERR: error: relocation R_RISCV_TPREL_LO12_I against a cannot be used with -shared
26# ERR: error: relocation R_RISCV_TPREL_HI20 against a cannot be used with -shared
27# ERR: error: relocation R_RISCV_TPREL_LO12_S against a cannot be used with -shared
28# ERR: error: relocation R_RISCV_TPREL_HI20 against a cannot be used with -shared
29# ERR: error: relocation R_RISCV_TPREL_LO12_S against a cannot be used with -shared
30
31# NM: {{0*}}00000008 b .LANCHOR0
32# NM: {{0*}}00000800 B a
33
34## .LANCHOR0@tprel = 8
35## a@tprel = 12
36# LE:      lui a1, 0x0
37# LE-NEXT: add a1, a1, tp
38# LE-NEXT: addi a1, a1, 0x8
39# LE-NEXT: lui a2, 0x0
40# LE-NEXT: add a2, a2, tp
41# LE-NEXT: addi a2, a2, 0x7fc
42# LE-NEXT: lui a3, 0x0
43# LE-NEXT: addi a0, a0, 0x1
44# LE-NEXT: add a3, a3, tp
45# LE-NEXT: addi a0, a0, 0x2
46# LE-NEXT: sw a0, 0x7fc(a3)
47# LE-NEXT: lui a4, 0x1
48# LE-NEXT: add a4, a4, tp
49# LE-NEXT: sw a0, -0x800(a4)
50# LE-EMPTY:
51
52# LE-RELAX:      <.text>:
53# LE-RELAX-NEXT:   addi a1, tp, 0x8
54# LE-RELAX-NEXT:   addi a2, tp, 0x7fc
55# LE-RELAX-NEXT:   addi a0, a0, 0x1
56# LE-RELAX-NEXT:   addi a0, a0, 0x2
57# LE-RELAX-NEXT:   sw a0, 0x7fc(tp)
58# LE-RELAX-NEXT:   lui a4, 0x1
59# LE-RELAX-NEXT:   add a4, a4, tp
60# LE-RELAX-NEXT:   sw a0, -0x800(a4)
61# LE-RELAX-EMPTY:
62
63lui a1, %tprel_hi(.LANCHOR0)
64add a1, a1, tp, %tprel_add(.LANCHOR0)
65addi a1, a1, %tprel_lo(.LANCHOR0)
66
67## hi20(a-4) = hi20(0x7fc) = 0. relaxable
68lui a2, %tprel_hi(a-4)
69add a2, a2, tp, %tprel_add(a-4)
70addi a2, a2, %tprel_lo(a-4)
71
72## hi20(a-4) = hi20(0x7fc) = 0. relaxable
73## Test non-adjacent instructions.
74lui a3, %tprel_hi(a-4)
75addi a0, a0, 0x1
76add a3, a3, tp, %tprel_add(a-4)
77addi a0, a0, 0x2
78sw a0, %tprel_lo(a-4)(a3)
79
80## hi20(a) = hi20(0x800) = 1. not relaxable
81lui a4, %tprel_hi(a)
82add a4, a4, tp, %tprel_add(a)
83sw a0, %tprel_lo(a)(a4)
84
85.section .tbss
86.space 8
87.LANCHOR0:
88.space 0x800-8
89.globl a
90a:
91.zero 4
92