aboutsummaryrefslogtreecommitdiff
path: root/opcodes/riscv-dis.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2023-11-24 09:53:15 +0100
committerJan Beulich <jbeulich@suse.com>2023-11-24 09:53:15 +0100
commit27b33966b18ed8bf1701a60999448224b1d28273 (patch)
tree2d6ad5e3535f234553e9afacf7f4d18eb9ca2560 /opcodes/riscv-dis.c
parent6c0c7d489bdf106d90b300aeb8d042c7b1ad3d2b (diff)
downloadgdb-27b33966b18ed8bf1701a60999448224b1d28273.zip
gdb-27b33966b18ed8bf1701a60999448224b1d28273.tar.gz
gdb-27b33966b18ed8bf1701a60999448224b1d28273.tar.bz2
RISC-V: disallow x0 with certain macro-insns
While for some of the macro insns using x0 is kind of okay, as they would merely resolve to a sequence of hint insns (and hence not cause misbehavior at runtime), several of them have the degenerate AUIPC followed by a load, store, or branch using other than the designated symbol as address and hence causing runtime issues. Refuse to assemble those, leveraging that the matching function so far wasn't really used for macro insns: NULL is now allowed, indicating a match (which imo is preferable over converting match_never() to match_always()), while other matching functions now (also) used for macro insns need to avoid calling match_opcode(). Note that for LA the restriction is slightly too strict: In non-PIC mode using x0 would be okay-ish as per above (as it's just LLA there). Yet libopcodes doesn't know what mode gas is presently assembling for, so we want to err on the safe side. Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Diffstat (limited to 'opcodes/riscv-dis.c')
-rw-r--r--opcodes/riscv-dis.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 2d7c154..6fa9855 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -787,6 +787,9 @@ riscv_disassemble_insn (bfd_vma memaddr,
for (; op->name; op++)
{
+ /* Ignore macro insns. */
+ if (op->pinfo == INSN_MACRO)
+ continue;
/* Does the opcode match? */
if (! (op->match_func) (op, word))
continue;