@@ -1237,87 +1237,57 @@ typedef struct w64wrapper {
12371237 #ifndef WOLFSSL_USE_ALIGN
12381238 #define WOLFSSL_USE_ALIGN
12391239 #endif
1240- #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM || USE_INTEL_SPEEDUP || WOLFSSL_AFALG_XILINX */
1241-
1242- #ifdef WOLFSSL_USE_ALIGN
1243- #if !defined(ALIGN16)
1244- #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || \
1245- defined (__llvm__)
1246- #define ALIGN16 __attribute__ ( (aligned (16 )))
1247- #elif defined (_MSC_VER)
1248- /* disable align warning, we want alignment ! */
1249- #pragma warning (disable: 4324 )
1250- #define ALIGN16 __declspec (align (16 ))
1251- #else
1252- #define ALIGN16
1253- #endif
1254- #endif /* !ALIGN16 */
1255-
1256- #if !defined (ALIGN32)
1257- #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || \
1258- defined (__llvm__)
1259- #define ALIGN32 __attribute__ ( (aligned (32 )))
1260- #elif defined (_MSC_VER)
1261- /* disable align warning, we want alignment ! */
1262- #pragma warning (disable: 4324 )
1263- #define ALIGN32 __declspec (align (32 ))
1264- #else
1265- #define ALIGN32
1266- #endif
1267- #endif /* !ALIGN32 */
1268-
1269- #if !defined(ALIGN64)
1270- #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || \
1271- defined (__llvm__)
1272- #define ALIGN64 __attribute__ ( (aligned (64 )))
1273- #elif defined (_MSC_VER)
1274- /* disable align warning, we want alignment ! */
1275- #pragma warning (disable: 4324 )
1276- #define ALIGN64 __declspec (align (64 ))
1277- #else
1278- #define ALIGN64
1279- #endif
1280- #endif /* !ALIGN64 */
1281-
1282- #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || \
1283- defined (__llvm__)
1284- #define ALIGN128 __attribute__ ( (aligned (128 )))
1240+ #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM || USE_INTEL_SPEEDUP || \
1241+ * WOLFSSL_AFALG_XILINX */
1242+
1243+ /* Helpers for memory alignment */
1244+ #ifndef XALIGNED
1245+ #if defined(__GNUC__) || defined(__llvm__) || \
1246+ defined (__IAR_SYSTEMS_ICC__)
1247+ #define XALIGNED (x) __attribute__ ( (aligned (x)))
1248+ #elif defined (__KEIL__)
1249+ #define XALIGNED (x) __align(x)
12851250 #elif defined (_MSC_VER)
12861251 /* disable align warning, we want alignment ! */
12871252 #pragma warning (disable: 4324 )
1288- #define ALIGN128 __declspec (align (128 ))
1253+ #define XALIGNED (x) __declspec (align (x ))
12891254 #else
1290- #define ALIGN128
1255+ #define XALIGNED ( x ) /* null expansion */
12911256 #endif
1257+ #endif
12921258
1293- # if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || \
1294- defined (__llvm__)
1295- #define ALIGN256 __attribute__ ( (aligned ( 256 )))
1296- #elif defined (_MSC_VER)
1297- /* disable align warning, we want alignment ! */
1298- #pragma warning (disable: 4324 )
1299- #define ALIGN256 __declspec (align ( 256 ) )
1259+ /* Only use alignment in wolfSSL/wolfCrypt if WOLFSSL_USE_ALIGN is set */
1260+ # ifdef WOLFSSL_USE_ALIGN
1261+ /* For IAR ARM the maximum variable alignment on stack is 8-bytes.
1262+ * Variables declared outside stack (like static globals) can have
1263+ * higher alignment. */
1264+ # if defined(__ICCARM__ )
1265+ #define WOLFSSL_ALIGN ( x ) XALIGNED( 8 )
13001266 #else
1301- #define ALIGN256
1267+ #define WOLFSSL_ALIGN ( x ) XALIGNED(x)
13021268 #endif
1303-
13041269 #else
1305- #ifndef ALIGN16
1306- #define ALIGN16
1307- #endif
1308- #ifndef ALIGN32
1309- #define ALIGN32
1310- #endif
1311- #ifndef ALIGN64
1312- #define ALIGN64
1313- #endif
1314- #ifndef ALIGN128
1315- #define ALIGN128
1316- #endif
1317- #ifndef ALIGN256
1318- #define ALIGN256
1319- #endif
1320- #endif /* WOLFSSL_USE_ALIGN */
1270+ #define WOLFSSL_ALIGN (x ) /* null expansion */
1271+ #endif
1272+
1273+ #ifndef ALIGN8
1274+ #define ALIGN8 WOLFSSL_ALIGN (8 )
1275+ #endif
1276+ #ifndef ALIGN16
1277+ #define ALIGN16 WOLFSSL_ALIGN (16 )
1278+ #endif
1279+ #ifndef ALIGN32
1280+ #define ALIGN32 WOLFSSL_ALIGN (32 )
1281+ #endif
1282+ #ifndef ALIGN64
1283+ #define ALIGN64 WOLFSSL_ALIGN (64 )
1284+ #endif
1285+ #ifndef ALIGN128
1286+ #define ALIGN128 WOLFSSL_ALIGN (128 )
1287+ #endif
1288+ #ifndef ALIGN256
1289+ #define ALIGN256 WOLFSSL_ALIGN (256 )
1290+ #endif
13211291
13221292 #if !defined(PEDANTIC_EXTENSION)
13231293 #if defined(__GNUC__)
0 commit comments