[v4,11/12] RISC-V/bfd: warn about non-boolean unaligned-access attribute
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
The attribute being a boolean one, incoming values should be solely 0 or
1. Convert other non-zero values to 1.
Reviewed-by: Jiawei jiawei@iscas.ac.cn
---
v4: Add underscore in diagnostic.
v3: New.
Comments
LGTM, thanks.
Nelson
On Fri, Jul 24, 2026 at 6:06 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> The attribute being a boolean one, incoming values should be solely 0 or
> 1. Convert other non-zero values to 1.
>
> Reviewed-by: Jiawei jiawei@iscas.ac.cn
> ---
> v4: Add underscore in diagnostic.
> v3: New.
>
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -3892,6 +3892,23 @@ riscv_merge_attributes (bfd *ibfd, struc
> initialized. */
> out_attr[0].i = 1;
>
> + for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
> + {
> + switch (i)
> + {
> + case Tag_RISCV_unaligned_access:
> + if (out_attr[i].i <= 1)
> + break;
> +
> + _bfd_error_handler
> + (_("warning: %pB uses non-boolean `unaligned_access' attribute; "
> + "converting to boolean"),
> + ibfd);
> + out_attr[i].i = 1;
> + break;
> + }
> + }
> +
> return true;
> }
>
> @@ -3980,7 +3997,12 @@ riscv_merge_attributes (bfd *ibfd, struc
> break;
>
> case Tag_RISCV_unaligned_access:
> - out_attr[i].i |= in_attr[i].i;
> + if (in_attr[i].i > 1)
> + _bfd_error_handler
> + (_("warning: %pB uses non-boolean `unaligned_access' attribute; "
> + "converting to boolean"),
> + ibfd);
> + out_attr[i].i |= !!in_attr[i].i;
> break;
>
> case Tag_RISCV_stack_align:
>
@@ -3892,6 +3892,23 @@ riscv_merge_attributes (bfd *ibfd, struc
initialized. */
out_attr[0].i = 1;
+ for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+ {
+ switch (i)
+ {
+ case Tag_RISCV_unaligned_access:
+ if (out_attr[i].i <= 1)
+ break;
+
+ _bfd_error_handler
+ (_("warning: %pB uses non-boolean `unaligned_access' attribute; "
+ "converting to boolean"),
+ ibfd);
+ out_attr[i].i = 1;
+ break;
+ }
+ }
+
return true;
}
@@ -3980,7 +3997,12 @@ riscv_merge_attributes (bfd *ibfd, struc
break;
case Tag_RISCV_unaligned_access:
- out_attr[i].i |= in_attr[i].i;
+ if (in_attr[i].i > 1)
+ _bfd_error_handler
+ (_("warning: %pB uses non-boolean `unaligned_access' attribute; "
+ "converting to boolean"),
+ ibfd);
+ out_attr[i].i |= !!in_attr[i].i;
break;
case Tag_RISCV_stack_align: