[PATCH v4 09/12] RISC-V/gas: warn about non-boolean unaligned-access attribute
Nelson Chu
nelson.chu1990@gmail.com
Mon Jul 27 03:57:34 GMT 2026
On Fri, Jul 24, 2026 at 6:05 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> The attribute being a boolean one, values should be solely 0 or 1.
>
> Reviewed-by: Jiawei <jiawei@iscas.ac.cn>
> ---
> Shouldn't settings accumulate, much like what riscv_merge_attributes()
> does?
> ---
I remember the initial idea was simple: file-level settings
necessarily apply to the entire file, and only by intervening with
function-level directives can specific code segments be exempted from
those settings. So for the other elf non-architecture and
non-priv-spec attributes are relatively straightforward, as they don't
actually affect the assembly (if I recall correctly). I think the
accumulated/non-accumulated settings of these settings are fine, if
you think accumulating these settings (I meant non-architecture and
non-priv-spec) is better then let's do it.
Nelson
> v2: New.
>
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -6105,14 +6105,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
> @@ -6138,6 +6137,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
>
More information about the Binutils
mailing list