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 <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti
2026-01-28 00:02:41 +01:00
parent be0c788105
commit 32ef705024

View File

@@ -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
/*