1# RUN: llvm-mc -triple riscv32 -riscv-no-aliases < %s -show-encoding \
2# RUN:     | FileCheck -check-prefix=INSTR -check-prefix=FIXUP %s
3# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \
4# RUN:     | llvm-readobj -r | FileCheck -check-prefix=RELOC %s
5
6# Check prefixes:
7# RELOC - Check the relocation in the object.
8# FIXUP - Check the fixup on the instruction.
9# INSTR - Check the instruction is handled properly by the ASMPrinter
10
11.long foo
12# RELOC: R_RISCV_32 foo
13
14.quad foo
15# RELOC: R_RISCV_64 foo
16
17lui t1, %hi(foo)
18# RELOC: R_RISCV_HI20 foo 0x0
19# INSTR: lui t1, %hi(foo)
20# FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20
21
22lui t1, %hi(foo+4)
23# RELOC: R_RISCV_HI20 foo 0x4
24# INSTR: lui t1, %hi(foo+4)
25# FIXUP: fixup A - offset: 0, value: %hi(foo+4), kind: fixup_riscv_hi20
26
27lui t1, %tprel_hi(foo)
28# RELOC: R_RISCV_TPREL_HI20 foo 0x0
29# INSTR: lui t1, %tprel_hi(foo)
30# FIXUP: fixup A - offset: 0, value: %tprel_hi(foo), kind: fixup_riscv_tprel_hi20
31
32lui t1, %tprel_hi(foo+4)
33# RELOC: R_RISCV_TPREL_HI20 foo 0x4
34# INSTR: lui t1, %tprel_hi(foo+4)
35# FIXUP: fixup A - offset: 0, value: %tprel_hi(foo+4), kind: fixup_riscv_tprel_hi20
36
37addi t1, t1, %lo(foo)
38# RELOC: R_RISCV_LO12_I foo 0x0
39# INSTR: addi t1, t1, %lo(foo)
40# FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i
41
42addi t1, t1, %lo(foo+4)
43# RELOC: R_RISCV_LO12_I foo 0x4
44# INSTR: addi t1, t1, %lo(foo+4)
45# FIXUP: fixup A - offset: 0, value: %lo(foo+4), kind: fixup_riscv_lo12_i
46
47addi t1, t1, %tprel_lo(foo)
48# RELOC: R_RISCV_TPREL_LO12_I foo 0x0
49# INSTR: addi t1, t1, %tprel_lo(foo)
50# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo), kind: fixup_riscv_tprel_lo12_i
51
52addi t1, t1, %tprel_lo(foo+4)
53# RELOC: R_RISCV_TPREL_LO12_I foo 0x4
54# INSTR: addi t1, t1, %tprel_lo(foo+4)
55# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo+4), kind: fixup_riscv_tprel_lo12_i
56
57sb t1, %lo(foo)(a2)
58# RELOC: R_RISCV_LO12_S foo 0x0
59# INSTR: sb t1, %lo(foo)(a2)
60# FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s
61
62sb t1, %lo(foo+4)(a2)
63# RELOC: R_RISCV_LO12_S foo 0x4
64# INSTR: sb t1, %lo(foo+4)(a2)
65# FIXUP: fixup A - offset: 0, value: %lo(foo+4), kind: fixup_riscv_lo12_s
66
67sb t1, %tprel_lo(foo)(a2)
68# RELOC: R_RISCV_TPREL_LO12_S foo 0x0
69# INSTR: sb t1, %tprel_lo(foo)(a2)
70# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo), kind: fixup_riscv_tprel_lo12_s
71
72sb t1, %tprel_lo(foo+4)(a2)
73# RELOC: R_RISCV_TPREL_LO12_S foo 0x4
74# INSTR: sb t1, %tprel_lo(foo+4)(a2)
75# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo+4), kind: fixup_riscv_tprel_lo12_s
76
77.L0:
78auipc t1, %pcrel_hi(foo)
79# RELOC: R_RISCV_PCREL_HI20 foo 0x0
80# INSTR: auipc t1, %pcrel_hi(foo)
81# FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20
82
83auipc t1, %pcrel_hi(foo+4)
84# RELOC: R_RISCV_PCREL_HI20 foo 0x4
85# INSTR: auipc t1, %pcrel_hi(foo+4)
86# FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo+4), kind: fixup_riscv_pcrel_hi20
87
88addi t1, t1, %pcrel_lo(.L0)
89# RELOC: R_RISCV_PCREL_LO12_I .L0 0x0
90# INSTR: addi t1, t1, %pcrel_lo(.L0)
91# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_i
92
93sb t1, %pcrel_lo(.L0)(a2)
94# RELOC: R_RISCV_PCREL_LO12_S .L0 0x0
95# INSTR: sb t1, %pcrel_lo(.L0)(a2)
96# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_s
97
98.L1:
99auipc t1, %got_pcrel_hi(foo)
100# RELOC: R_RISCV_GOT_HI20 foo 0x0
101# INSTR: auipc t1, %got_pcrel_hi(foo)
102# FIXUP: fixup A - offset: 0, value: %got_pcrel_hi(foo), kind: fixup_riscv_got_hi20
103
104addi t1, t1, %pcrel_lo(.L1)
105# RELOC: R_RISCV_PCREL_LO12_I .L1 0x0
106# INSTR: addi t1, t1, %pcrel_lo(.L1)
107# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L1), kind: fixup_riscv_pcrel_lo12_i
108
109sb t1, %pcrel_lo(.L1)(a2)
110# RELOC: R_RISCV_PCREL_LO12_S .L1 0x0
111# INSTR: sb t1, %pcrel_lo(.L1)(a2)
112# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L1), kind: fixup_riscv_pcrel_lo12_s
113
114# Check that GOT relocations aren't evaluated to a constant when the symbol is
115# in the same object file.
116.L2:
117auipc t1, %got_pcrel_hi(.L1)
118# RELOC: R_RISCV_GOT_HI20 .L1 0x0
119# INSTR: auipc t1, %got_pcrel_hi(.L1)
120# FIXUP: fixup A - offset: 0, value: %got_pcrel_hi(.L1), kind: fixup_riscv_got_hi20
121
122addi t1, t1, %pcrel_lo(.L2)
123# RELOC: R_RISCV_PCREL_LO12_I .L2 0x0
124# INSTR: addi t1, t1, %pcrel_lo(.L2)
125# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L2), kind: fixup_riscv_pcrel_lo12_i
126
127sb t1, %pcrel_lo(.L2)(a2)
128# RELOC: R_RISCV_PCREL_LO12_S .L2 0x0
129# INSTR: sb t1, %pcrel_lo(.L2)(a2)
130# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L2), kind: fixup_riscv_pcrel_lo12_s
131
132.L3:
133auipc t1, %tls_ie_pcrel_hi(foo)
134# RELOC: R_RISCV_TLS_GOT_HI20 foo 0x0
135# INSTR: auipc t1, %tls_ie_pcrel_hi(foo)
136# FIXUP: fixup A - offset: 0, value: %tls_ie_pcrel_hi(foo), kind: fixup_riscv_tls_got_hi20
137
138addi t1, t1, %pcrel_lo(.L3)
139# RELOC: R_RISCV_PCREL_LO12_I .L3 0x0
140# INSTR: addi t1, t1, %pcrel_lo(.L3)
141# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_i
142
143sb t1, %pcrel_lo(.L3)(a2)
144# RELOC: R_RISCV_PCREL_LO12_S .L3 0x0
145# INSTR: sb t1, %pcrel_lo(.L3)(a2)
146# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_s
147
148.L4:
149auipc t1, %tls_gd_pcrel_hi(foo)
150# RELOC: R_RISCV_TLS_GD_HI20 foo 0x0
151# INSTR: auipc t1, %tls_gd_pcrel_hi(foo)
152# FIXUP: fixup A - offset: 0, value: %tls_gd_pcrel_hi(foo), kind: fixup_riscv_tls_gd_hi20
153
154addi t1, t1, %pcrel_lo(.L4)
155# RELOC: R_RISCV_PCREL_LO12_I .L4 0x0
156# INSTR: addi t1, t1, %pcrel_lo(.L4)
157# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_i
158
159sb t1, %pcrel_lo(.L4)(a2)
160# RELOC: R_RISCV_PCREL_LO12_S .L4 0x0
161# INSTR: sb t1, %pcrel_lo(.L4)(a2)
162# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_s
163
164add t1, t1, tp, %tprel_add(foo)
165# RELOC: R_RISCV_TPREL_ADD foo 0x0
166# INSTR: add t1, t1, tp, %tprel_add(foo)
167# FIXUP: fixup A - offset: 0, value: %tprel_add(foo), kind: fixup_riscv_tprel_add
168
169jal zero, foo
170# RELOC: R_RISCV_JAL
171# INSTR: jal zero, foo
172# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_jal
173
174bgeu a0, a1, foo
175# RELOC: R_RISCV_BRANCH
176# INSTR: bgeu a0, a1, foo
177# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_branch
178