From 32ef7050244d61a51d2b794fd3bf8c7cbef4b41e Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Wed, 28 Jan 2026 00:02:41 +0100 Subject: [PATCH] library: alignment: add "may_alias" attribute to mbedtls_uintXX_unaligned_t structs Tell the GCC compiler that pointers to types "mbedtls_uintXX_unaligned_t" (where XX is 16, 32 or 64) might alias with other types. This helps at high optimizations level (i.e. "-O3") so that the compiler does not mess up with instruction reordering and memory accesses. Signed-off-by: Valerio Setti --- library/alignment.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alignment.h b/library/alignment.h index bbe459ed54..3c107d8695 100644 --- a/library/alignment.h +++ b/library/alignment.h @@ -88,13 +88,13 @@ typedef uint64_t __packed mbedtls_uint64_unaligned_t; #define UINT_UNALIGNED_STRUCT typedef struct { uint16_t x; -} __attribute__((packed)) mbedtls_uint16_unaligned_t; +} __attribute__((packed, may_alias)) mbedtls_uint16_unaligned_t; typedef struct { uint32_t x; -} __attribute__((packed)) mbedtls_uint32_unaligned_t; +} __attribute__((packed, may_alias)) mbedtls_uint32_unaligned_t; typedef struct { uint64_t x; -} __attribute__((packed)) mbedtls_uint64_unaligned_t; +} __attribute__((packed, may_alias)) mbedtls_uint64_unaligned_t; #endif /*