[PATCH] RISC-V: Checking 'm' extension when using RVV.

Jiawei jiawei@iscas.ac.cn
Tue Jan 21 15:23:31 GMT 2025


This patch add a new extension check when using `v` extension, it
currently should also enable `m` extension to make sure vector length
caculate correct.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_parse_check_conflicts): New check.

gas/ChangeLog:

	* testsuite/gas/riscv/march-fail-rv64i_v.d: New test.
	* testsuite/gas/riscv/march-fail-rv64i_v.l: New test.

---
 bfd/elfxx-riscv.c                            | 10 +++++++++-
 gas/testsuite/gas/riscv/march-fail-rv64i_v.d |  4 ++++
 gas/testsuite/gas/riscv/march-fail-rv64i_v.l |  3 +++
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gas/testsuite/gas/riscv/march-fail-rv64i_v.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-rv64i_v.l

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index c9e4b03b17d..150838d3d24 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -2123,7 +2123,15 @@ riscv_parse_check_conflicts (riscv_parse_subset_t *rps)
 	(_("`xtheadvector' is conflict with the `v' extension"));
       no_conflict = false;
     }
-
+  /* We might use a multiplication to calculate the scalable vector length at
+     runtime.  Therefore, require the M extension.  */
+  if (riscv_lookup_subset (rps->subset_list, "v", &subset)
+      && !riscv_lookup_subset (rps->subset_list, "m", &subset))
+    {
+      rps->error_handler
+	(_("Currently the 'v' implementation requires the 'm' extension"));
+      no_conflict = false;
+    }
   bool support_zve = false;
   bool support_zvl = false;
   riscv_subset_t *s = rps->subset_list->head;
diff --git a/gas/testsuite/gas/riscv/march-fail-rv64i_v.d b/gas/testsuite/gas/riscv/march-fail-rv64i_v.d
new file mode 100644
index 00000000000..4d14bb4f9a9
--- /dev/null
+++ b/gas/testsuite/gas/riscv/march-fail-rv64i_v.d
@@ -0,0 +1,4 @@
+#as: -march=rv64i_v
+#source: empty.s
+#error_output: march-fail-rv64i_v.l
+
diff --git a/gas/testsuite/gas/riscv/march-fail-rv64i_v.l b/gas/testsuite/gas/riscv/march-fail-rv64i_v.l
new file mode 100644
index 00000000000..5386a942ec5
--- /dev/null
+++ b/gas/testsuite/gas/riscv/march-fail-rv64i_v.l
@@ -0,0 +1,3 @@
+Assembler messages:
+Error: Currently the 'v' implementation requires the 'm' extension
+
-- 
2.43.0



More information about the Binutils mailing list