From 7237965193554f4207abd8822fbb3bff48632f02 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 23 Mar 2023 01:07:16 -0700 Subject: [PATCH] sha1.c: fix arm64 build with clang 16 Reported at https://wimlib.net/forums/viewtopic.php?p=1480#p1480 --- src/sha1.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/sha1.c b/src/sha1.c index 70ddfdc5..2b7aab05 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -407,13 +407,14 @@ sha1_blocks_x86_sha(u32 h[5], const void *data, size_t num_blocks) (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5)) /* - * clang's 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. + * 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. */ -#if defined(__clang__) && !defined(__ARM_FEATURE_SHA2) +#if defined(__clang__) && __clang_major__ <= 15 && !defined(__ARM_FEATURE_SHA2) # define __ARM_FEATURE_SHA2 1 # define USED_SHA2_FEATURE_WORKAROUND #endif @@ -458,8 +459,13 @@ sha1_blocks_x86_sha(u32 h[5], const void *data, size_t num_blocks) #define HAVE_SHA1_BLOCKS_ARM_CE static void #ifdef __clang__ - __attribute__((target("crypto"))) + /* + * clang has the SHA-1 instructions under "sha2". "crypto" used to work + * too, but only in clang 15 and earlier. So, use "sha2" here. + */ + __attribute__((target("sha2"))) #else + /* gcc wants "+crypto". "+sha2" doesn't work. */ __attribute__((target("+crypto"))) #endif sha1_blocks_arm_ce(u32 h[5], const void *data, size_t num_blocks) -- 2.43.0