1# RUN: llvm-mc -triple riscv32 -riscv-no-aliases < %s -show-encoding \
2# RUN:     | FileCheck -check-prefix=CHECK-FIXUP %s
3# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
4# RUN:     | llvm-objdump -riscv-no-aliases -d - \
5# RUN:     | FileCheck -check-prefix=CHECK-INSTR %s
6# RUN: llvm-mc -filetype=obj -triple=riscv32 %s \
7# RUN:     | llvm-readobj -r | FileCheck %s -check-prefix=CHECK-REL
8
9# Checks that fixups that can be resolved within the same object file are
10# applied correctly
11
12.LBB0:
13lui t1, %hi(val)
14# CHECK-FIXUP: fixup A - offset: 0, value: %hi(val), kind: fixup_riscv_hi20
15# CHECK-INSTR: lui t1, 74565
16
17lw a0, %lo(val)(t1)
18# CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_i
19# CHECK-INSTR: lw a0, 1656(t1)
20addi a1, t1, %lo(val)
21# CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_i
22# CHECK-INSTR: addi a1, t1, 1656
23sw a0, %lo(val)(t1)
24# CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_s
25# CHECK-INSTR: sw a0, 1656(t1)
26
27jal zero, .LBB0
28# CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_jal
29# CHECK-INSTR: jal zero, -16
30jal zero, .LBB2
31# CHECK-FIXUP: fixup A - offset: 0, value: .LBB2, kind: fixup_riscv_jal
32# CHECK-INSTR: jal zero, 330996
33beq a0, a1, .LBB0
34# CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_branch
35# CHECK-INSTR: beq a0, a1, -24
36blt a0, a1, .LBB1
37# CHECK-FIXUP: fixup A - offset: 0, value: .LBB1, kind: fixup_riscv_branch
38# CHECK-INSTR: blt a0, a1, 1108
39
40.fill 1104
41
42.LBB1:
43
44.fill 329876
45addi zero, zero, 0
46.LBB2:
47
48.set val, 0x12345678
49
50# CHECK-REL-NOT: R_RISCV
51
52# Testing the function call offset could resovled by assembler
53# when the function and the callsite within the same compile unit
54# and the linker relaxation is disabled.
55func:
56.fill 100
57call func
58# CHECK-FIXUP: fixup A - offset: 0, value: func, kind: fixup_riscv_call
59# CHECK-INSTR: auipc   ra, 0
60# CHECK-INSTR: jalr    ra, ra, -100
61
62.fill 10000
63call func
64# CHECK-FIXUP: fixup A - offset: 0, value: func, kind: fixup_riscv_call
65# CHECK-INSTR: auipc   ra, 1048574
66# CHECK-INSTR: jalr    ra, ra, -1916
67
68.fill 20888
69call func
70# CHECK-FIXUP: fixup A - offset: 0, value: func, kind: fixup_riscv_call
71# CHECK-INSTR: auipc   ra, 1048568
72# CHECK-INSTR: jalr    ra, ra, 1764
73