[PATCH v3 12/13] RISC-V/bfd: warn about non-boolean unaligned-access attribute
Jan Beulich
jbeulich@suse.com
Mon Jun 22 09:15:06 GMT 2026
On 22.06.2026 11:02, Jiawei wrote:
> On 2026/6/19 19:52, Jan Beulich wrote:
>> The attribute being a boolean one, incoming values should be solely 0 or
>> 1. Convert other non-zero values to 1.
>> ---
>> v3: New.
>>
>> --- a/bfd/elfxx-riscv.c
>> +++ b/bfd/elfxx-riscv.c
>> @@ -3777,6 +3777,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;
>> }
>>
>> @@ -3865,7 +3882,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:
>
> LGTM.
>
> Checking the copied attributes for the first input
> object is necessary, since otherwise a non-boolean unaligned_access
> value from
> the first object would be carried into the output unchanged.
>
> One very small wording thought: the gas-side diagnostic uses
> `unaligned_access', while this one uses `unaligned access'. Either is fine
> with me, using the same spelling might make the diagnostics more
> consistent, but this does not need to block the patch.
Oh, thanks for noticing. I've added in the underscores, also for the subsequent
stack-align patch.
> Reviewed-by: Jiawei jiawei@iscas.ac.cn
Thanks.
Jan
More information about the Binutils
mailing list