[PATCH v2] RISC-V: Recognize $x.<any> and $d.<any> mapping symbols

Kito Cheng kito.cheng@sifive.com
Fri Nov 20 14:46:04 GMT 2026


From: Jerry Zhang Jian <jerry.zhangjian@sifive.com>

The psABI allows a ".<any>" suffix on the $x and $d mapping symbols,
and clang emits $x.<n>.  objdump only handled the bare names, so it
kept the previous ISA or state and printed the symbols as labels.

Use startswith() for these checks, and for the existing $xrv one too.
---
Changes since v1:
- Use startswith(), and convert the existing $xrv checks too.

 bfd/cpu-riscv.c                          |  4 +++-
 gas/testsuite/gas/riscv/mapping-suffix.d | 14 ++++++++++++++
 gas/testsuite/gas/riscv/mapping-suffix.s |  9 +++++++++
 opcodes/riscv-dis.c                      |  6 +++---
 4 files changed, 29 insertions(+), 4 deletions(-)
 create mode 100644 gas/testsuite/gas/riscv/mapping-suffix.d
 create mode 100644 gas/testsuite/gas/riscv/mapping-suffix.s

diff --git a/bfd/cpu-riscv.c b/bfd/cpu-riscv.c
index 26ba1550e14..d3c4e0996bc 100644
--- a/bfd/cpu-riscv.c
+++ b/bfd/cpu-riscv.c
@@ -117,6 +117,8 @@ bool
 riscv_elf_is_mapping_symbols (const char *name)
 {
   return (!strcmp (name, "$d")
+	  || startswith (name, "$d.")
 	  || !strcmp (name, "$x")
-	  || !strncmp (name, "$xrv", 4));
+	  || startswith (name, "$x.")
+	  || startswith (name, "$xrv"));
 }
diff --git a/gas/testsuite/gas/riscv/mapping-suffix.d b/gas/testsuite/gas/riscv/mapping-suffix.d
new file mode 100644
index 00000000000..ce3afbe74aa
--- /dev/null
+++ b/gas/testsuite/gas/riscv/mapping-suffix.d
@@ -0,0 +1,14 @@
+#as:
+#source: mapping-suffix.s
+#objdump: -d
+
+.*:[ 	]+file format .*
+
+
+Disassembly of section .text:
+
+0+000 <.text>:
+[ 	]+[0-9a-f]+:[ 	]+00000013[ 	]+nop
+[ 	]+[0-9a-f]+:[ 	]+0001[ 	]+nop
+[ 	]+[0-9a-f]+:[ 	]+0001[ 	]+nop
+[ 	]+[0-9a-f]+:[ 	]+00000013[ 	]+\.word[ 	]+0x00000013
diff --git a/gas/testsuite/gas/riscv/mapping-suffix.s b/gas/testsuite/gas/riscv/mapping-suffix.s
new file mode 100644
index 00000000000..766f513a885
--- /dev/null
+++ b/gas/testsuite/gas/riscv/mapping-suffix.s
@@ -0,0 +1,9 @@
+# gas never emits $x.<any> or $d.<any>, so define them as labels.
+	.attribute arch, "rv32ic"
+	.option norvc
+	.insn 4, 0x00000013
+$x.0:
+	.insn 2, 0x0001
+	.insn 2, 0x0001
+$d.1:
+	.insn 4, 0x00000013
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 5672e3f5d88..45f894c0ca0 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1326,14 +1326,14 @@ riscv_update_map_state (int n,
     return;
 
   name = bfd_asymbol_name(info->symtab[n]);
-  if (strcmp (name, "$d") == 0)
+  if (strcmp (name, "$d") == 0 || startswith (name, "$d."))
     *state = MAP_DATA;
-  else if (strcmp (name, "$x") == 0)
+  else if (strcmp (name, "$x") == 0 || startswith (name, "$x."))
     {
       *state = MAP_INSN;
       riscv_dis_parse_subset (info, pd->default_arch);
     }
-  else if (strncmp (name, "$xrv", 4) == 0)
+  else if (startswith (name, "$xrv"))
     {
       *state = MAP_INSN;
 
-- 
2.54.0



More information about the Binutils mailing list