RISC-V: PR29342, Fix RV32 disassembler address computation
authorTsukasa OI <research_trasio@irq.a4lg.com>
Sat, 27 Aug 2022 00:11:00 +0000 (00:11 +0000)
committerNelson Chu <nelson@rivosinc.com>
Fri, 2 Sep 2022 04:06:27 +0000 (12:06 +0800)
commit48525554d5222d98953202b9252ff65fdead58a4
tree87d8509f91fa6f04acc478418a129838f0c20722
parente9f7ba21f08a264f813140eb6221e9d9670dc12f
RISC-V: PR29342, Fix RV32 disassembler address computation

If either the base register is `zero', `tp' or `gp' and XLEN is 32, an
incorrectly sign-extended address is produced when printing.  This commit
fixes this by fitting an address into a 32-bit value on RV32.

Besides, H. Peter Anvin discovered that we have wrong address computation
for JALR instruction (the initial bug is back in 2018).  This commit also
fixes that based on the idea of Palmer Dabbelt.

gas/
pr29342
* testsuite/gas/riscv/lla32.d: Reflect RV32 address computation fix.
* testsuite/gas/riscv/dis-addr-overflow.s: New testcase.
* testsuite/gas/riscv/dis-addr-overflow-32.d: Likewise.
* testsuite/gas/riscv/dis-addr-overflow-64.d: Likewise.
opcodes/
pr29342
* riscv-dis.c (maybe_print_address): Fit address into 32-bit on RV32.
(print_insn_args): Fix JALR address by adding EXTRACT_ITYPE_IMM.
gas/testsuite/gas/riscv/dis-addr-overflow-32.d [new file with mode: 0644]
gas/testsuite/gas/riscv/dis-addr-overflow-64.d [new file with mode: 0644]
gas/testsuite/gas/riscv/dis-addr-overflow.s [new file with mode: 0644]
gas/testsuite/gas/riscv/lla32.d
opcodes/riscv-dis.c