[PATCH 8/9] clang: efi payload: Silence unaligned access warning
Heinrich Schuchardt
xypron.glpk at gmx.de
Thu Apr 6 08:16:43 CEST 2023
On 4/6/23 01:48, Tom Rini wrote:
> When building with clang we see this warning:
> field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
>
> Which is correct and true as EFI payloads are by specification allowed
> to do unaligned access. And so to silence the warning here and only
> here, we make use of #pragma to push/pop turning off the warning.
>
> Signed-off-by: Tom Rini <trini at konsulko.com>
> ---
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> ---
> include/efi_api.h | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/include/efi_api.h b/include/efi_api.h
> index dc6e5ce236c9..f3bcbf593bea 100644
> --- a/include/efi_api.h
> +++ b/include/efi_api.h
> @@ -1168,9 +1168,21 @@ struct efi_key_descriptor {
> u16 affected_attribute;
> } __packed;
>
> +/* The warniing:
> + * field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
> + * is intentional due to EFI requiring unaligned access to be supported.
> + */
> struct efi_hii_keyboard_layout {
> u16 layout_length;
> +#ifdef CONFIG_CC_IS_CLANG
> +#pragma clang diagnostic push
> +#pragma clang diagnostic ignored "-Wunaligned-access"
> +#endif
> efi_guid_t guid;
> +#ifdef CONFIG_CC_IS_CLANG
> +#pragma clang diagnostic pop
> +#endif
I don't think that the clang warning should be suppressed. We should
replace efi_guid_t by u8[16] instead. This will force us to take the
missing alignment into account when accessing the component in future.
- efi_guid_t guid;
+ u8 guid[16];
Best regards
Heinrich
> +
> u32 layout_descriptor_string_offset;
> u8 descriptor_count;
> struct efi_key_descriptor descriptors[];
More information about the U-Boot
mailing list