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

Message ID 822a807f-ed59-4307-a108-3372f6a4c912@suse.com
State New
Headers
Series RISC-V: assorted fixes and (hopefully) improvements |

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

Jan Beulich July 24, 2026, 10:06 a.m. UTC
  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

Nelson Chu July 27, 2026, 4:17 a.m. UTC | #1
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:
>
  

Patch

--- 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: