Skip to content

Commit

Permalink
RISC-V: Fix .option arch compatibility with zc*
Browse files Browse the repository at this point in the history
This fixes an issue whereby .option arch with the zc extensions can
result in gas refusing to accept otherwise valid instructions because
the base C extension is not enabled.
  • Loading branch information
simonpcook authored and Mary Bennett committed Oct 2, 2023
1 parent 25ea490 commit 4c301b7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gas/config/tc-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5126,6 +5126,8 @@ s_riscv_option (int x ATTRIBUTE_UNUSED)
riscv_update_subset (&riscv_rps_as, "-c");
riscv_reset_subsets_list_arch_str ();
riscv_set_rvc (false);
if (riscv_subset_supports (&riscv_rps_as, "zca"))
riscv_set_rvc (true);
}
else if (strcmp (name, "pic") == 0)
riscv_opts.pic = true;
Expand Down
12 changes: 12 additions & 0 deletions gas/testsuite/gas/riscv/zc-zca-option-march.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#as: -march=rv32i
#source: zc-zca-option-march.s
#objdump: -d -Mno-aliases

.*:[ ]+file format .*


Disassembly of section .text:

0+000 <testcase>:
[ ]+0:[ ]+0001[ ]+c.addi[ ]+zero,0
#...
6 changes: 6 additions & 0 deletions gas/testsuite/gas/riscv/zc-zca-option-march.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.attribute 5, "rv32i"
.option rvc
.option arch, +zca
.option norvc
testcase:
c.nop
46 changes: 46 additions & 0 deletions gas/testsuite/gas/riscv/zc-zcmt-emit-jal-relax.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.macro PADDIING_32_BYTES
.option push
.option arch, -zcmt
.option arch, -zca
nop
nop
nop
nop
nop
nop
nop
nop
.option pop
.endm

.macro PADDIING_256_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
.endm

.macro PADDIING_2048_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
.endm

.option relax
target:
c.bnez s0, target
jal Far
c.bnez s0, Far
PADDIING_2048_BYTES
PADDIING_2048_BYTES
Far:
ret
50 changes: 50 additions & 0 deletions gas/testsuite/gas/riscv/zc-zcmt-relax-c-branch.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.macro PADDIING_32_BYTES
.option push
.option arch, -zcmt
.option arch, -zca
nop
nop
nop
nop
nop
nop
nop
nop
.option pop
.endm

.macro PADDIING_256_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
PADDIING_32_BYTES
.endm

.macro PADDIING_2048_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
PADDIING_256_BYTES
.endm

.option norelax
target:
c.beqz s0, C_BRANCH_RANGE
C_BRANCH_RANGE:
c.bnez s0, EXPAND_TO_BRANCH
PADDIING_256_BYTES
EXPAND_TO_BRANCH:
c.bnez s0, FLIP_C_BRANCH_AND_JUMP
PADDIING_2048_BYTES
PADDIING_2048_BYTES
FLIP_C_BRANCH_AND_JUMP:
c.beqz s0, -4
ret

0 comments on commit 4c301b7

Please sign in to comment.