]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V/gas: .attribute vs .insn
authorJan Beulich <jbeulich@suse.com>
Fri, 31 Jul 2026 11:49:06 +0000 (13:49 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 31 Jul 2026 11:49:06 +0000 (13:49 +0200)
"... 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.

Reviewed-by: Jiawei <jiawei@iscas.ac.cn>
gas/config/tc-riscv.c

index 5567c33e88c8d61b6f4244a97e09fc8a04f6503a..f1cf2552e17a803b03ee4d36e4144dd4151a235e 100644 (file)
@@ -4650,6 +4650,18 @@ riscv_ip_hardcode (char *str,
   return NULL;
 }
 
+/* The architecture and privileged elf attributes should be set before
+   assembling.  */
+static bool
+start_assembly (void)
+{
+  start_assemble = 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 = BFD_RELOC_UNUSED;
 
-  /* The architecture and privileged elf attributes should be set
-     before assembling.  */
-  if (!start_assemble)
-    {
-      start_assemble = true;
-
-      riscv_set_abi_by_arch ();
-      if (!riscv_set_default_priv_spec (NULL))
-       return;
-    }
+  if (!start_assemble && !start_assembly())
+    return;
 
   riscv_mapping_state (MAP_INSN, 0, false/* fr_align_code */);
 
@@ -5875,6 +5879,9 @@ s_riscv_insn (int x ATTRIBUTE_UNUSED)
   bfd_reloc_code_real_type imm_reloc = BFD_RELOC_UNUSED;
   char save_c;
 
+  if (!start_assemble && !start_assembly())
+    return;
+
   while (!is_end_of_stmt (*input_line_pointer))
     ++input_line_pointer;