Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IAR alignment issues if __packed has been redefined into a macro. #152

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion core/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,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)))
/*
Expand Down