xref: /llvm-project/lld/test/ELF/riscv-pcrel-hilo.s (revision c532ba4edd7ad7675ba450ba43268aa9e7bda46b)
1# REQUIRES: riscv
2
3# RUN: llvm-mc -filetype=obj -triple=riscv32-unknown-elf -mattr=-relax %s -o %t.rv32.o
4# RUN: llvm-mc -filetype=obj -triple=riscv64-unknown-elf -mattr=-relax %s -o %t.rv64.o
5
6# RUN: ld.lld %t.rv32.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv32
7# RUN: ld.lld %t.rv64.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv64
8# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32 | FileCheck %s
9# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64 | FileCheck %s
10# RUN: ld.lld -pie %t.rv32.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv32
11# RUN: ld.lld -pie %t.rv64.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv64
12# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32 | FileCheck %s
13# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64 | FileCheck %s
14# CHECK:      auipc   a0, 0x0
15# CHECK-NEXT: addi    a0, a0, 0xc
16# CHECK-NEXT: sw      zero, 0xc(a0)
17# CHECK:      auipc   a0, 0x0
18# CHECK-NEXT: addi    a0, a0, -0xc
19# CHECK-NEXT: sw      zero, -0xc(a0)
20
21# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -o %t.rv32.limits
22# RUN: ld.lld %t.rv64.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -o %t.rv64.limits
23# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
24# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
25# LIMITS:      auipc   a0, 0x7ffff
26# LIMITS-NEXT: addi    a0, a0, 0x7ff
27# LIMITS-NEXT: sw      zero, 0x7ff(a0)
28# LIMITS:      auipc   a0, 0x80000
29# LIMITS-NEXT: addi    a0, a0, -0x800
30# LIMITS-NEXT: sw      zero, -0x800(a0)
31
32# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o %t
33# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s
34# ERROR: relocation R_RISCV_PCREL_HI20 out of range: 524288 is not in [-524288, 524287]; references 'foo'
35# ERROR: relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references 'bar'
36
37.global _start
38_start:
39    auipc   a0, %pcrel_hi(foo)
40    addi    a0, a0, %pcrel_lo(_start)
41    sw      x0, %pcrel_lo(_start)(a0)
42.L1:
43    auipc   a0, %pcrel_hi(bar)
44    addi    a0, a0, %pcrel_lo(.L1)
45    sw      x0, %pcrel_lo(.L1)(a0)
46