[PATCH v2 17/16] RISC-V: warn about non-boolean unaligned-access attribute
Jiawei
jiawei@iscas.ac.cn
Sat Jun 6 22:11:23 GMT 2026
LGTM.
At 2026/6/5 17:29, Jan Beulich wrote:
> The attribute being a boolean one, values should be solely 0 or 1.
> ---
> Should libbfd's riscv_merge_attributes() also emit a warning?
>
> Shouldn't settings accumulate, much like what riscv_merge_attributes()
> does?
> ---
> v2: New.
Regarding the questions in the note, I think libbfd's
riscv_merge_attributes() should probably diagnose this as well, since input
objects may come from tools other than gas. That looks like a useful
follow-up.
I also think accumulating unaligned_access settings would be more consistent
with what riscv_merge_attributes() does. Since this is a file-level
"may use unaligned access" property, once a value of 1 has been seen, a
later
attribute value of 0 should probably not clear it.
Both of these seem orthogonal to this gas-side warning, though, so I do not
think they need to block this patch.
>
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -5859,14 +5859,13 @@ s_riscv_attribute (int ignored ATTRIBUTE
> {
> 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
> @@ -5892,6 +5891,11 @@ s_riscv_attribute (int ignored ATTRIBUTE
> "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; } --- /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_\"].*
> --- /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
> --- /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
Reviewed-by: Jiawei <jiawei@iscas.ac.cn>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260607/0ab84ec3/attachment.htm>
More information about the Binutils
mailing list