Skip to content

Commit 00100b5

Browse files
committedApr 9, 2019
[RISCV] Rewrite tests to use llvm-mc/llvm-objdump
Previously the tests in lld for RISC-V were given in yaml format as LLVM's RISC-V assembler support was incomplete. Now that the assembler/disassembler has matured we can rewrite all tests to use LLVM's tools. Differential Revision: https://reviews.llvm.org/D60415 llvm-svn: 357996
1 parent 949570c commit 00100b5

11 files changed

+179
-651
lines changed
 

‎lld/test/ELF/riscv-branch.test

-118
This file was deleted.

‎lld/test/ELF/riscv-call.test

-94
This file was deleted.

‎lld/test/ELF/riscv-hi20-lo12.test

-85
This file was deleted.

‎lld/test/ELF/riscv-jal-error.test

-92
This file was deleted.

‎lld/test/ELF/riscv-jal.test

-160
This file was deleted.

‎lld/test/ELF/riscv-pcrel-hilo.test

-102
This file was deleted.

‎test/ELF/riscv-branch.s

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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
9+
# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
10+
# CHECK: 63 02 00 00 beqz zero, 4
11+
# CHECK: e3 1e 00 fe bnez zero, -4
12+
#
13+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0xffe --defsym bar=_start+4-0x1000 -o %t.rv32.limits
14+
# RUN: ld.lld %t.rv64.o --defsym foo=_start+0xffe --defsym bar=_start+4-0x1000 -o %t.rv64.limits
15+
# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
16+
# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
17+
# LIMITS: e3 0f 00 7e beqz zero, 4094
18+
# LIMITS-NEXT: 63 10 00 80 bnez zero, -4096
19+
20+
# RUN: not ld.lld %t.rv32.o --defsym foo=_start+0x1000 --defsym bar=_start+4-0x1002 -o %t 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s
21+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x1000 --defsym bar=_start+4-0x1002 -o %t 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s
22+
# ERROR-RANGE: relocation R_RISCV_BRANCH out of range: 2048 is not in [-2048, 2047]
23+
# ERROR-RANGE-NEXT: relocation R_RISCV_BRANCH out of range: -2049 is not in [-2048, 2047]
24+
25+
# RUN: not ld.lld %t.rv32.o --defsym foo=_start+1 --defsym bar=_start-1 -o %t 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s
26+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+1 --defsym bar=_start-1 -o %t 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s
27+
# ERROR-ALIGN: improper alignment for relocation R_RISCV_BRANCH: 0x1 is not aligned to 2 bytes
28+
29+
.global _start
30+
_start:
31+
beq x0, x0, foo
32+
bne x0, x0, bar

‎test/ELF/riscv-call.s

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+8 --defsym bar=_start -o %t.rv32
7+
# RUN: ld.lld %t.rv64.o --defsym foo=_start+8 --defsym bar=_start -o %t.rv64
8+
# RUN: llvm-objdump -d %t.rv32 | FileCheck %s
9+
# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
10+
# CHECK: 97 00 00 00 auipc ra, 0
11+
# CHECK-NEXT: e7 80 80 00 jalr ra, ra, 8
12+
# CHECK: 97 00 00 00 auipc ra, 0
13+
# CHECK-NEXT: e7 80 80 ff jalr ra, ra, -8
14+
15+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+8-0x80000800 -o %t.rv32.limits
16+
# RUN: ld.lld %t.rv64.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+8-0x80000800 -o %t.rv64.limits
17+
# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
18+
# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
19+
# LIMITS: 97 f0 ff 7f auipc ra, 524287
20+
# LIMITS-NEXT: e7 80 f0 7f jalr ra, ra, 2047
21+
# LIMITS-NEXT: 97 00 00 80 auipc ra, 524288
22+
# LIMITS-NEXT: e7 80 00 80 jalr ra, ra, -2048
23+
24+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+8-0x80000801 -o %t
25+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+8-0x80000801 -o %t 2>&1 | FileCheck --check-prefix=ERROR %s
26+
# ERROR: relocation R_RISCV_CALL out of range: 524288 is not in [-524288, 524287]
27+
# ERROR-NEXT: relocation R_RISCV_CALL out of range: -524289 is not in [-524288, 524287]
28+
29+
.global _start
30+
_start:
31+
call foo
32+
call bar

‎test/ELF/riscv-hi20-lo12.s

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 %t 2>&1 | FileCheck --check-prefix ERROR %s
29+
# ERROR: relocation R_RISCV_HI20 out of range: 524288 is not in [-524288, 524287]
30+
# ERROR-NEXT: relocation R_RISCV_HI20 out of range: -524289 is not in [-524288, 524287]
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)

‎test/ELF/riscv-jal.s

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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
9+
# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
10+
# CHECK: 6f 00 40 00 j 4
11+
# CHECK: ef f0 df ff jal -4
12+
13+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0xffffe --defsym bar=_start+4-0x100000 -o %t.rv32.limits
14+
# RUN: ld.lld %t.rv64.o --defsym foo=_start+0xffffe --defsym bar=_start+4-0x100000 -o %t.rv64.limits
15+
# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
16+
# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
17+
# LIMITS: 6f f0 ff 7f j 1048574
18+
# LIMITS-NEXT: ef 00 00 80 jal -1048576
19+
20+
# RUN: not ld.lld %t.rv32.o --defsym foo=_start+0x100000 --defsym bar=_start+4-0x100002 -o %t 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s
21+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x100000 --defsym bar=_start+4-0x100002 -o %t 2>&1 | FileCheck --check-prefix=ERROR-RANGE %s
22+
# ERROR-RANGE: relocation R_RISCV_JAL out of range: 524288 is not in [-524288, 524287]
23+
# ERROR-RANGE-NEXT: relocation R_RISCV_JAL out of range: -524289 is not in [-524288, 524287]
24+
25+
# RUN: not ld.lld %t.rv32.o --defsym foo=_start+1 --defsym bar=_start+4+3 -o %t 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s
26+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+1 --defsym bar=_start+4+3 -o %t 2>&1 | FileCheck --check-prefix=ERROR-ALIGN %s
27+
# ERROR-ALIGN: improper alignment for relocation R_RISCV_JAL: 0x1 is not aligned to 2 bytes
28+
# ERROR-ALIGN-NEXT: improper alignment for relocation R_RISCV_JAL: 0x3 is not aligned to 2 bytes
29+
30+
.global _start
31+
32+
_start:
33+
jal x0, foo
34+
jal x1, bar

‎test/ELF/riscv-pcrel-hilo.s

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 %t.rv32 | FileCheck %s
9+
# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
10+
# CHECK: 17 05 00 00 auipc a0, 0
11+
# CHECK-NEXT: 13 05 c5 00 addi a0, a0, 12
12+
# CHECK-NEXT: 23 26 05 00 sw zero, 12(a0)
13+
# CHECK: 17 05 00 00 auipc a0, 0
14+
# CHECK-NEXT: 13 05 45 ff addi a0, a0, -12
15+
# CHECK-NEXT: 23 2a 05 fe sw zero, -12(a0)
16+
17+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -o %t.rv32.limits
18+
# RUN: ld.lld %t.rv64.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -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: 17 f5 ff 7f auipc a0, 524287
22+
# LIMITS-NEXT: 13 05 f5 7f addi a0, a0, 2047
23+
# LIMITS-NEXT: a3 2f 05 7e sw zero, 2047(a0)
24+
# LIMITS: 17 05 00 80 auipc a0, 524288
25+
# LIMITS-NEXT: 13 05 05 80 addi a0, a0, -2048
26+
# LIMITS-NEXT: 23 20 05 80 sw zero, -2048(a0)
27+
28+
# RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o %t
29+
# RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o %t 2>&1 | FileCheck --check-prefix=ERROR %s
30+
# ERROR: relocation R_RISCV_PCREL_HI20 out of range: 524288 is not in [-524288, 524287]
31+
# ERROR-NEXT: relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]
32+
33+
.global _start
34+
_start:
35+
auipc a0, %pcrel_hi(foo)
36+
addi a0, a0, %pcrel_lo(_start)
37+
sw x0, %pcrel_lo(_start)(a0)
38+
.L1:
39+
auipc a0, %pcrel_hi(bar)
40+
addi a0, a0, %pcrel_lo(.L1)
41+
sw x0, %pcrel_lo(.L1)(a0)

0 commit comments

Comments
 (0)
Please sign in to comment.