[v2,16/16] RISC-V/gas: .attribute vs .insn

Message ID 010ee05b-d766-4d67-bad8-55246c9757ad@suse.com
State New
Headers
Series RISC-V: assorted fixes and (hopefully) improvements |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich May 15, 2026, 1:37 p.m. UTC
  "... 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>
---
RFC: I can't quite figure why this constraint exists, so there may also be
     the option of relaxing things (up to fully dropping start_assemble).

As to other uses of .attribute, shouldn't redundant conflicting attribute
values at least be warned about?
For stack_align,
- shouldn't the smallest non-zero value be used?
- shouldn't non-power-of-2 values at least be warned about?
For unaligned_access,
- shouldn't values other than 0/1 be warned about?
---
v2: Style correction.
  

Patch

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -4404,6 +4404,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)
 {
@@ -4411,16 +4423,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 */);
 
@@ -5629,6 +5633,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;