public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Make riscv_is_mapping_symbol stricter
@ 2023-12-01  2:47 Patrick O'Neill
  2023-12-01  3:40 ` Nelson Chu
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick O'Neill @ 2023-12-01  2:47 UTC (permalink / raw)
  To: binutils; +Cc: kito.cheng, nelson, Patrick O'Neill

riscv_is_mapping_symbol currently accepts any symbol that starts with $x
or $d. This patch makes the check more strict, requiring exactly $x, $d,
or $xrv. It also makes use of this stricter mapping in
riscv_is_valid_mapping_symbol.

ChangeLog:

	* bfd/cpu-riscv.c (riscv_elf_is_mapping_symbols): Match only
	strings that are exactly $x, $d, or $xrv.
	* opcodes/riscv-dis.c (riscv_is_valid_mapping_symbol): Use
	riscv_elf_is_mapping_symbols.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
---
Tested using rv64gcv make report-linux and make report-binutils-linux.
---
 bfd/cpu-riscv.c     | 5 +++--
 opcodes/riscv-dis.c | 4 +---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/bfd/cpu-riscv.c b/bfd/cpu-riscv.c
index a478797da69..79a82a599e2 100644
--- a/bfd/cpu-riscv.c
+++ b/bfd/cpu-riscv.c
@@ -147,6 +147,7 @@ riscv_get_priv_spec_class_from_numbers (unsigned int major,
 bool
 riscv_elf_is_mapping_symbols (const char *name)
 {
-  return (!strncmp (name, "$d", 2)
-         || !strncmp (name, "$x", 2));
+  return (!strcmp (name, "$x")
+         || !strcmp (name, "$d")
+         || !strncmp (name, "$xrv", 4));
 }
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index f7f4c0750ed..829070d809d 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -930,9 +930,7 @@ riscv_is_valid_mapping_symbol (int n,
     return false;

   name = bfd_asymbol_name(info->symtab[n]);
-  return (strcmp (name, "$x") == 0
-         || strcmp (name, "$d") == 0
-         || strncmp (name, "$xrv", 4) == 0);
+  return riscv_elf_is_mapping_symbols (name);
 }

 /* Check the sorted symbol table (sorted by the symbol value), find the
--
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] RISC-V: Make riscv_is_mapping_symbol stricter
  2023-12-01  2:47 [PATCH] RISC-V: Make riscv_is_mapping_symbol stricter Patrick O'Neill
@ 2023-12-01  3:40 ` Nelson Chu
  0 siblings, 0 replies; 2+ messages in thread
From: Nelson Chu @ 2023-12-01  3:40 UTC (permalink / raw)
  To: Patrick O'Neill; +Cc: binutils, kito.cheng

[-- Attachment #1: Type: text/plain, Size: 2105 bytes --]

Since we should call riscv_elf_is_mapping_symbols uniformly to check if the
symbol is a mapping symbol or not, this patch looks good to me.  Committed.

Thanks
Nelson

On Fri, Dec 1, 2023 at 10:47 AM Patrick O'Neill <patrick@rivosinc.com>
wrote:

> riscv_is_mapping_symbol currently accepts any symbol that starts with $x
> or $d. This patch makes the check more strict, requiring exactly $x, $d,
> or $xrv. It also makes use of this stricter mapping in
> riscv_is_valid_mapping_symbol.
>
> ChangeLog:
>
>         * bfd/cpu-riscv.c (riscv_elf_is_mapping_symbols): Match only
>         strings that are exactly $x, $d, or $xrv.
>         * opcodes/riscv-dis.c (riscv_is_valid_mapping_symbol): Use
>         riscv_elf_is_mapping_symbols.
>
> Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
> ---
> Tested using rv64gcv make report-linux and make report-binutils-linux.
> ---
>  bfd/cpu-riscv.c     | 5 +++--
>  opcodes/riscv-dis.c | 4 +---
>  2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/bfd/cpu-riscv.c b/bfd/cpu-riscv.c
> index a478797da69..79a82a599e2 100644
> --- a/bfd/cpu-riscv.c
> +++ b/bfd/cpu-riscv.c
> @@ -147,6 +147,7 @@ riscv_get_priv_spec_class_from_numbers (unsigned int
> major,
>  bool
>  riscv_elf_is_mapping_symbols (const char *name)
>  {
> -  return (!strncmp (name, "$d", 2)
> -         || !strncmp (name, "$x", 2));
> +  return (!strcmp (name, "$x")
> +         || !strcmp (name, "$d")
> +         || !strncmp (name, "$xrv", 4));
>  }
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
> index f7f4c0750ed..829070d809d 100644
> --- a/opcodes/riscv-dis.c
> +++ b/opcodes/riscv-dis.c
> @@ -930,9 +930,7 @@ riscv_is_valid_mapping_symbol (int n,
>      return false;
>
>    name = bfd_asymbol_name(info->symtab[n]);
> -  return (strcmp (name, "$x") == 0
> -         || strcmp (name, "$d") == 0
> -         || strncmp (name, "$xrv", 4) == 0);
> +  return riscv_elf_is_mapping_symbols (name);
>  }
>
>  /* Check the sorted symbol table (sorted by the symbol value), find the
> --
> 2.34.1
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-01  3:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01  2:47 [PATCH] RISC-V: Make riscv_is_mapping_symbol stricter Patrick O'Neill
2023-12-01  3:40 ` Nelson Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).