[PATCH 1/2] RISC-V: Fix abort when displaying .dword

Jiawei jiawei@iscas.ac.cn
Wed Feb 12 05:27:07 GMT 2025


在 2025/2/12 13:08, Charlie Jenkins 写道:
> 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.
>
> Forcing instructions to be at most 4 bytes causes other unintented
> side-effects, so instead add entries to the switch statement to handle
> instructions that are 5, 6, or 7 bytes.
>
> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> Fixes: 6a04e8230707 ("RISC-V: Fix display of partial instructions")
> ---
>   opcodes/riscv-dis.c | 29 ++++++++++++++++++++++++++++-
>   1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
> index 367004d3341e46a5f72253cd70c7c2941912e84d..21bcbd32c7f226d13f1637ad192d8fe3c52e0d7a 100644
> --- a/opcodes/riscv-dis.c
> +++ b/opcodes/riscv-dis.c
> @@ -1325,6 +1325,33 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
>   	(info->stream, dis_style_immediate, "0x%08lx",
>   	 (unsigned long) data);
>         break;
> +    case 5:
> +      info->bytes_per_line = 8;
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_assembler_directive, ".dword");
> +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_immediate, "0x%010lx",
> +	 (unsigned long) data);
> +      break;
> +    case 6:
> +      info->bytes_per_line = 8;
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_assembler_directive, ".dword");
> +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_immediate, "0x%012lx",
> +	 (unsigned long) data);
> +      break;
> +    case 7:
> +      info->bytes_per_line = 8;
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_assembler_directive, ".dword");
> +      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
> +      (*info->fprintf_styled_func)
> +	(info->stream, dis_style_immediate, "0x%014lx",
> +	 (unsigned long) data);
> +      break;
>       case 8:
>         info->bytes_per_line = 8;
>         (*info->fprintf_styled_func)
> @@ -1332,7 +1359,7 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
>         (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
>         (*info->fprintf_styled_func)
>   	(info->stream, dis_style_immediate, "0x%016llx",
> -	 (unsigned long long) data);
> +	 (unsigned long) data);
>         break;
>       default:
>         abort ();

LGTM, thanks.

Jiawei



More information about the Binutils mailing list