[PATCH 1/1] RISC-V: Correct as --dump-config output for --target=rv64*

Xiao Zeng zengxiao@eswincomputing.com
Mon Jan 6 01:15:32 GMT 2025


gas/ChangeLog:

	* config/tc-riscv.c (riscv_target_format): Correct as
	--dump-config output for --target=rv64*.

Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
---
 gas/config/tc-riscv.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index a915c8b4995..35d19ac4e5d 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -734,6 +734,18 @@ riscv_check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED,
 const char *
 riscv_target_format (void)
 {
+  /* When as --dump-config is used, xlen is not initialized, resulting in
+     bfd-target being set to elf32-*riscv even with --target=rv64*.  */
+  if (xlen == 0)
+    {
+      if (strcmp (default_arch, "riscv32") == 0)
+	xlen = 32;
+      else if (strcmp (default_arch, "riscv64") == 0)
+	xlen = 64;
+      else
+	as_bad ("unknown default architecture `%s'", default_arch);
+    }
+
   if (target_big_endian)
     return xlen == 64 ? "elf64-bigriscv" : "elf32-bigriscv";
   else
-- 
2.17.1



More information about the Binutils mailing list