* [3.6] Fix alignment problems with IAR and Zephyr

Since __packed is a reserved keyword for IAR compilers, and
Zephyr defines it to attribute(__packed__), some typedef constructs
in mbedtls does not work with attribute(packed), only with the
keyword packed.

This fix temporary undefs the macro and restores it after the typedefs.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
This commit is contained in:
Lars-Ove Karlsson
2025-06-02 13:08:23 +02:00
committed by Lars-Ove Karlsson
parent 9576d65f0f
commit 595b0b577b

View File

@@ -51,10 +51,27 @@
* This results in a single load / store instruction (if unaligned access is supported).
* According to that document, this is only supported on certain architectures.
*/
#define UINT_UNALIGNED
#define UINT_UNALIGNED
/* Some products, like Zephyr, defines __packed as a macro for attribute(packed) and
* that does not work with typedefs, so if __packed is defined, undef it for the
* typedefs and restore it afterwards.
*/
#ifdef __packed
#pragma push_macro("__packed")
#undef __packed
#define MBEDTLS_IAR_PACKED_MACRO_USED
#endif
typedef uint16_t __packed mbedtls_uint16_unaligned_t;
typedef uint32_t __packed mbedtls_uint32_unaligned_t;
typedef uint64_t __packed mbedtls_uint64_unaligned_t;
#ifdef MBEDTLS_IAR_PACKED_MACRO_USED
#undef MBEDTLS_IAR_PACKED_MACRO_USED
#pragma pop_macro("__packed")
#endif
#elif defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 40504) && \
((MBEDTLS_GCC_VERSION < 60300) || (!defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)))
/*