[v2,03/11] RISC-V: Make mapping symbol checking consistent

Message ID c52af18da452a844c5fddf64b9b8e7b53f208111.1669610611.git.research_trasio@irq.a4lg.com
State Accepted
Headers
Series RISC-V: Requirements for disassembler optimizations batch 1 |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Tsukasa OI Nov. 28, 2022, 4:43 a.m. UTC
  From: Tsukasa OI <research_trasio@irq.a4lg.com>

There were two places where the mapping symbols are checked but had
different conditions.

-    riscv_get_map_state:          "$d" or starts with "$x"
-    riscv_elf_is_mapping_symbols: Starts with either "$x" or "$d"

Considering recent mapping symbol proposal, it's better to make symbol
checking consistent (whether the symbol _starts_ with "$[xd]").

It only checks prefix "$xrv" (mapping symbol with ISA string) only when the
prefix "$x" is matched.

opcodes/ChangeLog:

	* riscv-dis.c (riscv_get_map_state): Change the condition for
	consistency.
---
 opcodes/riscv-dis.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
  

Patch

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 768b44ee6003..f6fdd5badfe6 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -834,16 +834,17 @@  riscv_get_map_state (int n,
     return false;
 
   name = bfd_asymbol_name(info->symtab[n]);
-  if (strcmp (name, "$x") == 0)
-    *state = MAP_INSN;
-  else if (strcmp (name, "$d") == 0)
-    *state = MAP_DATA;
-  else if (strncmp (name, "$xrv", 4) == 0)
+  if (startswith (name, "$x"))
     {
+      if (startswith (name + 2, "rv"))
+	{
+	  riscv_release_subset_list (&riscv_subsets);
+	  riscv_parse_subset (&riscv_rps_dis, name + 2);
+	}
       *state = MAP_INSN;
-      riscv_release_subset_list (&riscv_subsets);
-      riscv_parse_subset (&riscv_rps_dis, name + 2);
     }
+  else if (startswith (name, "$d"))
+    *state = MAP_DATA;
   else
     return false;