[binutils-gdb] RISC-V/gas: .attribute vs .insn

Jan Beulich via Binutils-cvs <[email protected]> Fri, 31 Jul 2026 11:54:24 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8b67c66bea0f=
bfd84fff8cfee905eb576eda9b2b

commit 8b67c66bea0fbfd84fff8cfee905eb576eda9b2b
Author: Jan Beulich <[email protected]>
Date:   Fri Jul 31 13:49:06 2026 +0200

    RISC-V/gas: .attribute vs .insn
   =20
    "... before any instruction", as the diagnostic from s_riscv_attribute()
    says, presumably ought to include also insns resulting from .insn. Make=
 a
    small helper function.
   =20
    Reviewed-by: Jiawei <[email protected]>

Diff:
---
 gas/config/tc-riscv.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 5567c33e88c..f1cf2552e17 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -4650,6 +4650,18 @@ riscv_ip_hardcode (char *str,
   return NULL;
 }
=20
+/* The architecture and privileged elf attributes should be set before
+   assembling.  */
+static bool
+start_assembly (void)
+{
+  start_assemble =3D true;
+
+  riscv_set_abi_by_arch ();
+
+  return riscv_set_default_priv_spec (NULL);
+}
+
 void
 md_assemble (char *str)
 {
@@ -4657,16 +4669,8 @@ md_assemble (char *str)
   expressionS imm_expr;
   bfd_reloc_code_real_type imm_reloc =3D BFD_RELOC_UNUSED;
=20
-  /* The architecture and privileged elf attributes should be set
-     before assembling.  */
-  if (!start_assemble)
-    {
-      start_assemble =3D true;
-
-      riscv_set_abi_by_arch ();
-      if (!riscv_set_default_priv_spec (NULL))
-       return;
-    }
+  if (!start_assemble && !start_assembly())
+    return;
=20
   riscv_mapping_state (MAP_INSN, 0, false/* fr_align_code */);
=20
@@ -5875,6 +5879,9 @@ s_riscv_insn (int x ATTRIBUTE_UNUSED)
   bfd_reloc_code_real_type imm_reloc =3D BFD_RELOC_UNUSED;
   char save_c;
=20
+  if (!start_assemble && !start_assembly())
+    return;
+
   while (!is_end_of_stmt (*input_line_pointer))
     ++input_line_pointer;