Move ALIGN32 and ALIGN64 into common.h, and fix for clang-cl.exe
authorTom Cosgrove <tom.cosgrove@arm.com>
Fri, 1 Sep 2023 07:41:11 +0000 (08:41 +0100)
committerPauli <pauli@openssl.org>
Sun, 3 Sep 2023 22:44:21 +0000 (08:44 +1000)
clang-cl.exe defines __clang__ and _MSC_VER but not __GNUC__, so a clang-
specific guard is needed to get the correct ALIGNxx versions.

Fixes #21914

Change-Id: Icdc047b182ad1ba61c7b1b06a1e951eda1a0c33d

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21921)

crypto/bn/rsaz_exp.c
crypto/ec/ecp_nistz256.c
crypto/ec/ecp_sm2p256.c
include/internal/common.h

index e44eae43be8df6593d60de06e77c29b365e81d36..844140720ccb14e0096ce06366d1520305538c65 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <openssl/opensslconf.h>
+#include "internal/common.h"
 #include "rsaz_exp.h"
 
 #ifndef RSAZ_ENABLED
@@ -31,16 +32,8 @@ void rsaz_1024_scatter5_avx2(void *tbl, const void *val, int i);
 void rsaz_1024_gather5_avx2(void *val, const void *tbl, int i);
 void rsaz_1024_red2norm_avx2(void *norm, const void *red);
 
-#if defined(__GNUC__)
-# define ALIGN64        __attribute__((aligned(64)))
-#elif defined(_MSC_VER)
-# define ALIGN64        __declspec(align(64))
-#elif defined(__SUNPRO_C)
-# define ALIGN64
+#if defined(__SUNPRO_C)
 # pragma align 64(one,two80)
-#else
-/* not fatal, might hurt performance a little */
-# define ALIGN64
 #endif
 
 ALIGN64 static const BN_ULONG one[40] = {
index 44d9054a1719865bd7a6ee983e37eaab8253eac1..8addb1e40c08bdf5a183db4152eef5dd603e2fe5 100644 (file)
 # define TOBN(hi,lo)    ((BN_ULONG)hi<<32|lo)
 #endif
 
-#if defined(__GNUC__)
-# define ALIGN32        __attribute((aligned(32)))
-#elif defined(_MSC_VER)
-# define ALIGN32        __declspec(align(32))
-#else
-# define ALIGN32
-#endif
-
 #define ALIGNPTR(p,N)   ((unsigned char *)p+N-(size_t)p%N)
 #define P256_LIMBS      (256/BN_BITS2)
 
index 49fab47187a5bdcbf75bc6c1b803a967e3e34b15..6ec42455299b31772c53f07e923a510f57a9cc7b 100644 (file)
 #include <openssl/err.h>
 #include "crypto/bn.h"
 #include "ec_local.h"
+#include "internal/common.h"
 #include "internal/constant_time.h"
 
-#if defined(__GNUC__)
-# define ALIGN32 __attribute((aligned(32)))
-# define ALIGN64 __attribute((aligned(64)))
-#elif defined(_MSC_VER)
-# define ALIGN32 __declspec(align(32))
-# define ALIGN64 __declspec(align(64))
-#else
-# define ALIGN32
-# define ALIGN64
-#endif
-
 #define P256_LIMBS (256 / BN_BITS2)
 
 #if !defined(OPENSSL_NO_SM2_PRECOMP)
index 204e7c3eecd376d12c1be11573dd288ee6a791ad..ce4a4e3086021cf98c09d11cda219214df43512b 100644 (file)
 # include "internal/e_os.h" /* ossl_inline in many files */
 # include "internal/nelem.h"
 
-#if defined(__GNUC__) || defined(__clang__)
-    #define likely(x) __builtin_expect(!!(x), 1)
-    #define unlikely(x) __builtin_expect(!!(x), 0)
-#else
-    #define likely(x) x
-    #define unlikely(x) x
-#endif
+# if defined(__GNUC__) || defined(__clang__)
+#  define likely(x)     __builtin_expect(!!(x), 1)
+#  define unlikely(x)   __builtin_expect(!!(x), 0)
+# else
+#  define likely(x)     x
+#  define unlikely(x)   x
+# endif
 
-#ifdef NDEBUG
-# define ossl_assert(x) ((x) != 0)
-#else
+# if defined(__GNUC__) || defined(__clang__)
+#  define ALIGN32       __attribute((aligned(32)))
+#  define ALIGN64       __attribute((aligned(64)))
+# elif defined(_MSC_VER)
+#  define ALIGN32       __declspec(align(32))
+#  define ALIGN64       __declspec(align(64))
+# else
+#  define ALIGN32
+#  define ALIGN64
+# endif
+
+# ifdef NDEBUG
+#  define ossl_assert(x) ((x) != 0)
+# else
 __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
                                               const char *file, int line)
 {
@@ -38,10 +49,10 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
     return expr;
 }
 
-# define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
+#  define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
                                          __FILE__, __LINE__)
 
-#endif
+# endif
 
 /* Check if |pre|, which must be a string literal, is a prefix of |str| */
 #define HAS_PREFIX(str, pre) (strncmp(str, pre "", sizeof(pre) - 1) == 0)