Re: [PATCH v4 11/12] RISC-V/bfd: warn about non-boolean unaligned-access attribute

Nelson Chu <[email protected]> Mon, 27 Jul 2026 12:17:43 +0800
Newsgroups gmane.comp.gnu.binutils
Message-ID <CAHT-pJzqtvZ2ssTNGYv4y+bQ_Z6AvNi=v4ZS45q8hhCUaqbtDg@mail.gmail.com>
LGTM, thanks.

Nelson

On Fri, Jul 24, 2026 at 6:06 PM Jan Beulich <[email protected]> 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 [email protected]
> ---
> 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:
>