[PATCH v3 1/2] RISC-V: Fix abort when displaying .dword
Charlie Jenkins
charlie@rivosinc.com
Wed Feb 19 21:20:18 GMT 2025
In the normal case an instruction won't be split into 5, 6, or 7 byte
sections. However a .dword disassembled with -D can cause an instruction
to split across the 6 byte boundary. 6 byte instructions were not
supported so riscv_disassemble_data() would abort.
If data is encountered that is not a power of two, dump all of the data
with a .<N>byte directive.
Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Fixes: 6a04e8230707 ("RISC-V: Fix display of partial instructions")
---
gas/testsuite/gas/riscv/dis-partial-insn-word.d | 2 +-
opcodes/riscv-dis.c | 19 ++++++++++---------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/gas/testsuite/gas/riscv/dis-partial-insn-word.d b/gas/testsuite/gas/riscv/dis-partial-insn-word.d
index 2f52153075e77361a3dd3f1e3071949eb89c6fe6..0bb43fca2e22d0e2363c70032b988dfc96fe3585 100644
--- a/gas/testsuite/gas/riscv/dis-partial-insn-word.d
+++ b/gas/testsuite/gas/riscv/dis-partial-insn-word.d
@@ -8,4 +8,4 @@
Disassembly of section .text:
0+000 <target>:
-[ ]+0:[ ]+000013[ ]+.word[ ]+0x000013
+[ ]+0:[ ]+000013[ ]+.3byte[ ]+0x13
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 3956f588f8f749935b23e6a4dc4fab95ef66d013..d02723ed38ff368e9ce0a48e49d8f87820551a50 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1317,14 +1317,6 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
(*info->fprintf_styled_func)
(info->stream, dis_style_immediate, "0x%04x", (unsigned) data);
break;
- case 3:
- info->bytes_per_line = 7;
- (*info->fprintf_styled_func)
- (info->stream, dis_style_assembler_directive, ".word");
- (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
- (*info->fprintf_styled_func)
- (info->stream, dis_style_immediate, "0x%06x", (unsigned) data);
- break;
case 4:
info->bytes_per_line = 8;
(*info->fprintf_styled_func)
@@ -1344,7 +1336,16 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
(unsigned long long) data);
break;
default:
- abort ();
+ /* Arbitrary data so just print the bits in the shape of an .<N>byte
+ directive. */
+ info->bytes_per_line = info->bytes_per_chunk;
+ (*info->fprintf_styled_func)
+ (info->stream, dis_style_assembler_directive, ".%dbyte", info->bytes_per_chunk);
+ (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
+ (*info->fprintf_styled_func)
+ (info->stream, dis_style_immediate, "0x%0llx",
+ (unsigned long long) data);
+ break;
}
return info->bytes_per_chunk;
}
--
2.43.0
More information about the Binutils
mailing list