[v4,12/12] RISC-V/bfd: warn about non-power-of-2 stack-align 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
Only power-of-2 values are sensible for alignment. Reject other values.
While there also drop a redundant part of a related conditional.
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:
>
> Only power-of-2 values are sensible for alignment. Reject other values.
>
> While there also drop a redundant part of a related conditional.
>
> Reviewed-by: Jiawei jiawei@iscas.ac.cn
> ---
> v4: Add underscore in diagnostic.
> v3: New.
>
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -3906,6 +3906,17 @@ riscv_merge_attributes (bfd *ibfd, struc
> ibfd);
> out_attr[i].i = 1;
> break;
> +
> + case Tag_RISCV_stack_align:
> + if (!(out_attr[i].i & (out_attr[i].i - 1)))
> + break;
> +
> + _bfd_error_handler
> + (_("warning: %pB uses non-power-of-2 `stack_align' attribute; "
> + "ignoring"),
> + ibfd);
> + out_attr[i].i = 0;
> + break;
> }
> }
>
> @@ -4006,10 +4017,14 @@ riscv_merge_attributes (bfd *ibfd, struc
> break;
>
> case Tag_RISCV_stack_align:
> - if (out_attr[i].i == 0)
> + if ((in_attr[i].i & (in_attr[i].i - 1)) != 0)
> + _bfd_error_handler
> + (_("warning: %pB uses non-power-of-2 `stack_align' attribute; "
> + "ignoring"),
> + ibfd);
> + else if (out_attr[i].i == 0)
> out_attr[i].i = in_attr[i].i;
> else if (in_attr[i].i != 0
> - && out_attr[i].i != 0
> && out_attr[i].i != in_attr[i].i)
> {
> _bfd_error_handler
>
@@ -3906,6 +3906,17 @@ riscv_merge_attributes (bfd *ibfd, struc
ibfd);
out_attr[i].i = 1;
break;
+
+ case Tag_RISCV_stack_align:
+ if (!(out_attr[i].i & (out_attr[i].i - 1)))
+ break;
+
+ _bfd_error_handler
+ (_("warning: %pB uses non-power-of-2 `stack_align' attribute; "
+ "ignoring"),
+ ibfd);
+ out_attr[i].i = 0;
+ break;
}
}
@@ -4006,10 +4017,14 @@ riscv_merge_attributes (bfd *ibfd, struc
break;
case Tag_RISCV_stack_align:
- if (out_attr[i].i == 0)
+ if ((in_attr[i].i & (in_attr[i].i - 1)) != 0)
+ _bfd_error_handler
+ (_("warning: %pB uses non-power-of-2 `stack_align' attribute; "
+ "ignoring"),
+ ibfd);
+ else if (out_attr[i].i == 0)
out_attr[i].i = in_attr[i].i;
else if (in_attr[i].i != 0
- && out_attr[i].i != 0
&& out_attr[i].i != in_attr[i].i)
{
_bfd_error_handler