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+4 --defsym bar=_start -o %t.rv32 7# RUN: ld.lld %t.rv64.o --defsym foo=_start+4 --defsym bar=_start -o %t.rv64 8# RUN: llvm-objdump -d %t.rv32 | FileCheck %s --check-prefix=CHECK-32 9# RUN: llvm-objdump -d %t.rv64 | FileCheck %s --check-prefix=CHECK-64 10# CHECK-32: 6f 00 40 00 j 0x110b8 11# CHECK-32: ef f0 df ff jal 0x110b4 12# CHECK-64: 6f 00 40 00 j 0x11124 13# CHECK-64: ef f0 df ff jal 0x11120 14 15# RUN: ld.lld %t.rv32.o --defsym foo=_start+0xffffe --defsym bar=_start+4-0x100000 -o %t.rv32.limits 16# RUN: ld.lld %t.rv64.o --defsym foo=_start+0xffffe --defsym bar=_start+4-0x100000 -o %t.rv64.limits 17# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS-32 %s 18# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS-64 %s 19# LIMITS-32: 6f f0 ff 7f j 0x1110b2 20# LIMITS-32-NEXT: ef 00 00 80 jal 0xfff110b8 21# LIMITS-64: 6f f0 ff 7f j 0x11111e 22# LIMITS-64-NEXT: ef 00 00 80 jal 0xfffffffffff11124 23 24# RUN: not ld.lld %t.rv32.o --defsym foo=_start+0x100000 --defsym bar=_start+4-0x100002 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s 25# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x100000 --defsym bar=_start+4-0x100002 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s 26# ERROR-RANGE: relocation R_RISCV_JAL out of range: 524288 is not in [-524288, 524287]; references foo 27# ERROR-RANGE: relocation R_RISCV_JAL out of range: -524289 is not in [-524288, 524287]; references bar 28 29# RUN: not ld.lld %t.rv32.o --defsym foo=_start+1 --defsym bar=_start+4+3 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s 30# RUN: not ld.lld %t.rv64.o --defsym foo=_start+1 --defsym bar=_start+4+3 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s 31# ERROR-ALIGN: improper alignment for relocation R_RISCV_JAL: 0x1 is not aligned to 2 bytes 32# ERROR-ALIGN: improper alignment for relocation R_RISCV_JAL: 0x3 is not aligned to 2 bytes 33 34.global _start 35 36_start: 37 jal x0, foo 38 jal x1, bar 39