[PATCH] riscv: Add option to specify disassembler arch

Nelson Chu nelson@rivosinc.com
Tue Apr 22 05:22:01 GMT 2025


The dis-assembler 'max' option may not work as expected when there are
overlapped encodings and the elf architecture attribute doesn't have those
extensions.  I think the only case that causes the problem is - we use the
'.insn' directives to encode the non-supported instruction (extensions) by
the old assembler, but even the new dis-assembler supports those new
extensions, it still cannot dump them correctly since the elf attribute
won't have those new extensions.

There was a proposal from Tsukasa OI, which should be similar to this
patch, to add a new dis-assembler option for users to specify which
architecture string they want to use,
https://inbox.sourceware.org/binutils/CAPpQWtA8MNT8p9q7Epb2TbCaEFtJLUFLYW72BkXaEXhyA2RscA@mail.gmail.com/

So yes, generally I (and I think most of the people) agree to add a new
dis-assembler option for this.  Just a minor stuff as follows ...

On Tue, Mar 25, 2025 at 9:50 PM Marek Pikuła <m.pikula@partner.samsung.com>
wrote:

> @@ -1564,6 +1589,7 @@ typedef enum
>  {
>    RISCV_OPTION_ARG_NONE = -1,
>    RISCV_OPTION_ARG_PRIV_SPEC,
> +  RISCV_OPTION_ARG_DEFAULT_ARCH,
>
>    RISCV_OPTION_ARG_COUNT
>  } riscv_option_arg_t;
> @@ -1585,7 +1611,13 @@ static struct
>      RISCV_OPTION_ARG_NONE },
>    { "priv-spec=",
>      N_("Print the CSR according to the chosen privilege spec."),
> -    RISCV_OPTION_ARG_PRIV_SPEC }
> +    RISCV_OPTION_ARG_PRIV_SPEC },
> +  { "default-arch=",
> +    N_("Set a default ISA subset if not possible to deduce from ELF."),
> +    RISCV_OPTION_ARG_DEFAULT_ARCH },
> +  { "default-arch-force",
> +    N_("Force usage of default-arch instead of taking it from ELF."),
> +    RISCV_OPTION_ARG_NONE }
>  };
>
>  /* Build the structure representing valid RISCV disassembler options.
> @@ -1617,6 +1649,9 @@ disassembler_options_riscv (void)
>        /* The array we return must be NULL terminated.  */
>        args[RISCV_OPTION_ARG_PRIV_SPEC].values[i] = NULL;
>
> +      args[RISCV_OPTION_ARG_DEFAULT_ARCH].name = "ARCH";
> +      args[RISCV_OPTION_ARG_DEFAULT_ARCH].values = NULL;
> +
>        /* The array we return must be NULL terminated.  */
>        args[num_args].name = NULL;
>        args[num_args].values = NULL;
>

1. Rename 'default-arch' to 'arch', to keep it compatible with assembler?

2. The 'default-arch-force' option isn't really needed'.  We parse the elf
architecture attribute in the riscv_init_disasm_info, and then parse the
dis-assembler option in the parse_riscv_dis_options, which means we can
just add the code to parse the dis-assembler 'arch=' option.  I think the
duplicate parsing should be fine, but if people care, then just extracting
the elf architecture parsing from riscv_init_disasm_info to the place after
parse_riscv_dis_options should be fine.

Thanks
Nelson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250422/7b595f1a/attachment.htm>


More information about the Binutils mailing list