[v2] RISC-V: Add support for numbered ISA mapping strings

Message ID LO4P265MB591487CCBB57E75FE05F23AF80C2A@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM
State New
Headers
Series [v2] RISC-V: Add support for numbered ISA mapping strings |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed

Commit Message

Joseph Faulls Sept. 27, 2023, 12:42 p.m. UTC
  The elf psabi allows for mapping symbols to be of the form $x<ISA>.<any>

    opcodes/
            * riscv-dis.c (riscv_get_map_state): allow mapping symbol to
              be suffixed by a unique identifier .<any>

Changes from v1:

  *   Use xmalloc (thanks Jan)
---
opcodes/riscv-dis.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

--
2.34.1
  

Comments

Nelson Chu Sept. 28, 2023, 1:41 a.m. UTC | #1
Okay, although the current GNU assembler won't generate numbered
architecture strings, other tools may generate, so this looks reasonable.

Thanks
Nelson

On Wed, Sep 27, 2023 at 8:42 PM Joseph Faulls <Joseph.Faulls@imgtec.com>
wrote:

> The elf psabi allows for mapping symbols to be of the form $x<ISA>.<any>
>
>
>
>     opcodes/
>
>             * riscv-dis.c (riscv_get_map_state): allow mapping symbol to
>
>               be suffixed by a unique identifier .<any>
>
>
>
> Changes from v1:
>
>    - Use xmalloc (thanks Jan)
>
> ---
>
> opcodes/riscv-dis.c | 18 +++++++++++++++++-
>
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
>
>
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
>
> index c0fd0625a2d..18a5c26f9a6 100644
>
> --- a/opcodes/riscv-dis.c
>
> +++ b/opcodes/riscv-dis.c
>
> @@ -869,7 +869,23 @@ riscv_get_map_state (int n,
>
>      {
>
>        *state = MAP_INSN;
>
>        riscv_release_subset_list (&riscv_subsets);
>
> -      riscv_parse_subset (&riscv_rps_dis, name + 2);
>
> +
>
> +      /* ISA mapping string may be numbered, suffixed with '.n'. Do not
>
> +        consider this as part of the ISA string.  */
>
> +      char *suffix = strchr (name, '.');
>
> +      if (suffix)
>
> +       {
>
> +         int suffix_index = (int)(suffix - name);
>
> +         char *name_substr = xmalloc (suffix_index + 1);
>
> +         strncpy (name_substr, name, suffix_index);
>
> +         name_substr[suffix_index] = '\0';
>
> +         riscv_parse_subset (&riscv_rps_dis, name_substr + 2);
>
> +         free (name_substr);
>
> +       }
>
> +      else
>
> +       {
>
> +         riscv_parse_subset (&riscv_rps_dis, name + 2);
>
> +       }
>
>      }
>
>    else
>
>      return false;
>
> --
>
> 2.34.1
>
  
Joseph Faulls Oct. 12, 2023, 3:46 p.m. UTC | #2
Ping

If this looks good, could someone commit it?

Thanks,
Joe

From: Nelson Chu <nelson@rivosinc.com>
Sent: Thursday, September 28, 2023 2:41 AM
To: Joseph Faulls <Joseph.Faulls@imgtec.com>
Cc: binutils@sourceware.org; jbeulich@suse.com
Subject: [EXTERNAL] Re: [PATCH v2] RISC-V: Add support for numbered ISA mapping strings

Okay, although the current GNU assembler won't generate numbered architecture strings, other tools may generate, so this looks reasonable.

Thanks
Nelson

On Wed, Sep 27, 2023 at 8:42 PM Joseph Faulls <Joseph.Faulls@imgtec.com<mailto:Joseph.Faulls@imgtec.com>> wrote:
The elf psabi allows for mapping symbols to be of the form $x<ISA>.<any>

    opcodes/
            * riscv-dis.c (riscv_get_map_state): allow mapping symbol to
              be suffixed by a unique identifier .<any>

Changes from v1:

  *   Use xmalloc (thanks Jan)
---
opcodes/riscv-dis.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index c0fd0625a2d..18a5c26f9a6 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -869,7 +869,23 @@ riscv_get_map_state (int n,
     {
       *state = MAP_INSN;
       riscv_release_subset_list (&riscv_subsets);
-      riscv_parse_subset (&riscv_rps_dis, name + 2);
+
+      /* ISA mapping string may be numbered, suffixed with '.n'. Do not
+        consider this as part of the ISA string.  */
+      char *suffix = strchr (name, '.');
+      if (suffix)
+       {
+         int suffix_index = (int)(suffix - name);
+         char *name_substr = xmalloc (suffix_index + 1);
+         strncpy (name_substr, name, suffix_index);
+         name_substr[suffix_index] = '\0';
+         riscv_parse_subset (&riscv_rps_dis, name_substr + 2);
+         free (name_substr);
+       }
+      else
+       {
+         riscv_parse_subset (&riscv_rps_dis, name + 2);
+       }
     }
   else
     return false;
--
2.34.1
  
Nelson Chu Oct. 13, 2023, 1:57 a.m. UTC | #3
Committed with indents fixing.

Nelson

On Thu, Oct 12, 2023 at 11:46 PM Joseph Faulls <Joseph.Faulls@imgtec.com>
wrote:

> Ping
>
>
>
> If this looks good, could someone commit it?
>
>
>
> Thanks,
> Joe
>
>
>
> *From:* Nelson Chu <nelson@rivosinc.com>
> *Sent:* Thursday, September 28, 2023 2:41 AM
> *To:* Joseph Faulls <Joseph.Faulls@imgtec.com>
> *Cc:* binutils@sourceware.org; jbeulich@suse.com
> *Subject:* [EXTERNAL] Re: [PATCH v2] RISC-V: Add support for numbered ISA
> mapping strings
>
> Okay, although the current GNU assembler won't generate numbered
> architecture strings, other tools may generate, so this looks reasonable.
>
>
>
> Thanks
>
> Nelson
>
>
>
> On Wed, Sep 27, 2023 at 8:42 PM Joseph Faulls <Joseph.Faulls@imgtec.com>
> wrote:
>
> The elf psabi allows for mapping symbols to be of the form $x<ISA>.<any>
>
>
>
>     opcodes/
>
>             * riscv-dis.c (riscv_get_map_state): allow mapping symbol to
>
>               be suffixed by a unique identifier .<any>
>
>
>
> Changes from v1:
>
>    - Use xmalloc (thanks Jan)
>
> ---
>
> opcodes/riscv-dis.c | 18 +++++++++++++++++-
>
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
>
>
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
>
> index c0fd0625a2d..18a5c26f9a6 100644
>
> --- a/opcodes/riscv-dis.c
>
> +++ b/opcodes/riscv-dis.c
>
> @@ -869,7 +869,23 @@ riscv_get_map_state (int n,
>
>      {
>
>        *state = MAP_INSN;
>
>        riscv_release_subset_list (&riscv_subsets);
>
> -      riscv_parse_subset (&riscv_rps_dis, name + 2);
>
> +
>
> +      /* ISA mapping string may be numbered, suffixed with '.n'. Do not
>
> +        consider this as part of the ISA string.  */
>
> +      char *suffix = strchr (name, '.');
>
> +      if (suffix)
>
> +       {
>
> +         int suffix_index = (int)(suffix - name);
>
> +         char *name_substr = xmalloc (suffix_index + 1);
>
> +         strncpy (name_substr, name, suffix_index);
>
> +         name_substr[suffix_index] = '\0';
>
> +         riscv_parse_subset (&riscv_rps_dis, name_substr + 2);
>
> +         free (name_substr);
>
> +       }
>
> +      else
>
> +       {
>
> +         riscv_parse_subset (&riscv_rps_dis, name + 2);
>
> +       }
>
>      }
>
>    else
>
>      return false;
>
> --
>
> 2.34.1
>
>
  

Patch

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index c0fd0625a2d..18a5c26f9a6 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -869,7 +869,23 @@  riscv_get_map_state (int n,
     {
       *state = MAP_INSN;
       riscv_release_subset_list (&riscv_subsets);
-      riscv_parse_subset (&riscv_rps_dis, name + 2);
+
+      /* ISA mapping string may be numbered, suffixed with '.n'. Do not
+        consider this as part of the ISA string.  */
+      char *suffix = strchr (name, '.');
+      if (suffix)
+       {
+         int suffix_index = (int)(suffix - name);
+         char *name_substr = xmalloc (suffix_index + 1);
+         strncpy (name_substr, name, suffix_index);
+         name_substr[suffix_index] = '\0';
+         riscv_parse_subset (&riscv_rps_dis, name_substr + 2);
+         free (name_substr);
+       }
+      else
+       {
+         riscv_parse_subset (&riscv_rps_dis, name + 2);
+       }
     }
   else
     return false;