]> wimlib.net Git - wimlib/commitdiff
sha1.c: fix arm64 build with clang 12 and earlier
authorEric Biggers <ebiggers3@gmail.com>
Tue, 28 Mar 2023 06:14:41 +0000 (23:14 -0700)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 28 Mar 2023 06:14:41 +0000 (23:14 -0700)
clang 12 and earlier only defined the SHA-1 intrinsics when
__ARM_FEATURE_CRYPTO is defined.

src/sha1.c

index 2b7aab05a50d8220ac6f95a17faa0a32a7cfde19..fbbfdc18d1bdde0a64bd57981c37e3cdb1aa4665 100644 (file)
@@ -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 <arm_neon.h>
-#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