• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=0 --defsym bar=42 -o %t.rv32
7# RUN: ld.lld %t.rv64.o --defsym foo=0 --defsym bar=42 -o %t.rv64
8# RUN: llvm-objdump -d %t.rv32 | FileCheck %s
9# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
10# CHECK:      37 05 00 00     lui     a0, 0
11# CHECK-NEXT: 13 05 05 00     mv      a0, a0
12# CHECK-NEXT: 23 20 a5 00     sw      a0, 0(a0)
13# CHECK-NEXT: b7 05 00 00     lui     a1, 0
14# CHECK-NEXT: 93 85 a5 02     addi    a1, a1, 42
15# CHECK-NEXT: 23 a5 b5 02     sw      a1, 42(a1)
16
17# RUN: ld.lld %t.rv32.o --defsym foo=0x7ffff7ff --defsym bar=0x7ffff800 -o %t.rv32.limits
18# RUN: ld.lld %t.rv64.o --defsym foo=0x7ffff7ff --defsym bar=0xffffffff7ffff800 -o %t.rv64.limits
19# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
20# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
21# LIMITS:      37 f5 ff 7f     lui     a0, 524287
22# LIMITS-NEXT: 13 05 f5 7f     addi    a0, a0, 2047
23# LIMITS-NEXT: a3 2f a5 7e     sw      a0, 2047(a0)
24# LIMITS-NEXT: b7 05 00 80     lui     a1, 524288
25# LIMITS-NEXT: 93 85 05 80     addi    a1, a1, -2048
26# LIMITS-NEXT: 23 a0 b5 80     sw      a1, -2048(a1)
27
28# RUN: not ld.lld %t.rv64.o --defsym foo=0x7ffff800 --defsym bar=0xffffffff7ffff7ff -o /dev/null 2>&1 | FileCheck --check-prefix ERROR %s
29# ERROR: relocation R_RISCV_HI20 out of range: 524288 is not in [-524288, 524287]; references foo
30# ERROR: relocation R_RISCV_HI20 out of range: -524289 is not in [-524288, 524287]; references bar
31
32.global _start
33
34_start:
35    lui     a0, %hi(foo)
36    addi    a0, a0, %lo(foo)
37    sw      a0, %lo(foo)(a0)
38    lui     a1, %hi(bar)
39    addi    a1, a1, %lo(bar)
40    sw      a1, %lo(bar)(a1)
41