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

Kito Cheng kito.cheng@sifive.com
Fri Nov 20 14:26:08 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.
---
 bfd/cpu-riscv.c                          |  2 ++
 gas/testsuite/gas/riscv/mapping-suffix.d | 14 ++++++++++++++
 gas/testsuite/gas/riscv/mapping-suffix.s |  9 +++++++++
 opcodes/riscv-dis.c                      |  4 ++--
 4 files changed, 27 insertions(+), 2 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..85b425aa6a5 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")
+	  || !strncmp (name, "$d.", 3)
 	  || !strcmp (name, "$x")
+	  || !strncmp (name, "$x.", 3)
 	  || !strncmp (name, "$xrv", 4));
 }
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..77ed4160641 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1326,9 +1326,9 @@ riscv_update_map_state (int n,
     return;
 
   name = bfd_asymbol_name(info->symtab[n]);
-  if (strcmp (name, "$d") == 0)
+  if (strcmp (name, "$d") == 0 || strncmp (name, "$d.", 3) == 0)
     *state = MAP_DATA;
-  else if (strcmp (name, "$x") == 0)
+  else if (strcmp (name, "$x") == 0 || strncmp (name, "$x.", 3) == 0)
     {
       *state = MAP_INSN;
       riscv_dis_parse_subset (info, pd->default_arch);
-- 
2.54.0



More information about the Binutils mailing list