[binutils-gdb] RISC-V/gas: warn about non-boolean unaligned-access attribute

Jan Beulich jbeulich@sourceware.org
Fri Jul 31 11:54:29 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2a59bbe368765ea2defffd81219a0f32c437a5fd

commit 2a59bbe368765ea2defffd81219a0f32c437a5fd
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Jul 31 13:49:24 2026 +0200

    RISC-V/gas: warn about non-boolean unaligned-access attribute
    
    The attribute being a boolean one, values should be solely 0 or 1.
    
    Reviewed-by: Jiawei <jiawei@iscas.ac.cn>

Diff:
---
 gas/config/tc-riscv.c                    | 8 ++++++--
 gas/testsuite/gas/riscv/attribute-warn.d | 7 +++++++
 gas/testsuite/gas/riscv/attribute-warn.l | 2 ++
 gas/testsuite/gas/riscv/attribute-warn.s | 3 +++
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index f1cf2552e17..d4d551b82a0 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -6105,14 +6105,13 @@ s_riscv_attribute (int ignored ATTRIBUTE_UNUSED)
 {
   obj_attr_tag_t tag = obj_attr_process_attribute (OBJ_ATTR_PROC);
   unsigned old_xlen;
-  obj_attribute *attr;
+  const obj_attribute *attr = elf_known_obj_attributes_proc (stdoutput);
 
   explicit_attr = true;
   switch (tag)
     {
     case Tag_RISCV_arch:
       old_xlen = xlen;
-      attr = elf_known_obj_attributes_proc (stdoutput);
       if (!start_assemble)
 	riscv_set_arch (attr[Tag_RISCV_arch].s);
       else
@@ -6138,6 +6137,11 @@ s_riscv_attribute (int ignored ATTRIBUTE_UNUSED)
 		   "any instructions"));
       break;
 
+    case Tag_RISCV_unaligned_access:
+      if (attr[Tag_RISCV_unaligned_access].i > 1)
+	as_warn (_("`unaligned_access' attribute with non-boolean value"));
+      break;
+
     default:
       break;
     }
diff --git a/gas/testsuite/gas/riscv/attribute-warn.d b/gas/testsuite/gas/riscv/attribute-warn.d
new file mode 100644
index 00000000000..d116febabc1
--- /dev/null
+++ b/gas/testsuite/gas/riscv/attribute-warn.d
@@ -0,0 +1,7 @@
+#as: -march-attr
+#readelf: -A
+#warning_output: attribute-warn.l
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
diff --git a/gas/testsuite/gas/riscv/attribute-warn.l b/gas/testsuite/gas/riscv/attribute-warn.l
new file mode 100644
index 00000000000..af05da9280d
--- /dev/null
+++ b/gas/testsuite/gas/riscv/attribute-warn.l
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:2: Warning: `unaligned_access' attribute with non-boolean value
diff --git a/gas/testsuite/gas/riscv/attribute-warn.s b/gas/testsuite/gas/riscv/attribute-warn.s
new file mode 100644
index 00000000000..fdaed386422
--- /dev/null
+++ b/gas/testsuite/gas/riscv/attribute-warn.s
@@ -0,0 +1,3 @@
+	.attribute unaligned_access, 1
+	.attribute unaligned_access, 0x1234
+	.attribute unaligned_access, 0


More information about the Binutils-cvs mailing list