From 7993652656d5beeff805a8017566784adfdd36a1 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 27 Mar 2023 23:14:41 -0700 Subject: [PATCH] sha1.c: fix arm64 build with clang 12 and earlier clang 12 and earlier only defined the SHA-1 intrinsics when __ARM_FEATURE_CRYPTO is defined. --- src/sha1.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/sha1.c b/src/sha1.c index 2b7aab05..fbbfdc18 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -407,19 +407,26 @@ sha1_blocks_x86_sha(u32 h[5], const void *data, size_t num_blocks) (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5)) /* - * With clang 15.0 and earlier, arm_neon.h has a bug where it only defines the - * SHA-1 intrinsics when SHA-2 is enabled in the main target. This prevents - * them from being used in target attribute functions. Work around this by - * defining __ARM_FEATURE_SHA2. - * - * And yes, the feature it wants is indeed *SHA-2*, not SHA-1. + * clang's arm_neon.h used to have a bug where it only defined the SHA-1 + * intrinsics when CRYPTO (clang 12 and earlier) or SHA2 (clang 13 and 14) is + * enabled in the main target. This prevents them from being used in target + * attribute functions. Work around this by defining the macros ourselves. */ -#if defined(__clang__) && __clang_major__ <= 15 && !defined(__ARM_FEATURE_SHA2) -# define __ARM_FEATURE_SHA2 1 -# define USED_SHA2_FEATURE_WORKAROUND +#if defined(__clang__) && __clang_major__ <= 15 +# ifndef __ARM_FEATURE_CRYPTO +# define __ARM_FEATURE_CRYPTO 1 +# define DEFINED_ARM_FEATURE_CRYPTO +# endif +# ifndef __ARM_FEATURE_SHA2 +# define __ARM_FEATURE_SHA2 1 +# define DEFINED_ARM_FEATURE_SHA2 +# endif #endif #include -#ifdef USED_SHA2_FEATURE_WORKAROUND +#ifdef DEFINED_ARM_FEATURE_CRYPTO +# undef __ARM_FEATURE_CRYPTO +#endif +#ifdef DEFINED_ARM_FEATURE_SHA2 # undef __ARM_FEATURE_SHA2 #endif -- 2.43.0