From 2f2c04956dead5d508a4b9af808a1e6892dd225b Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Thu, 16 Feb 2023 14:24:46 +0800 Subject: [PATCH] Add GCC options pop Reduce the scope of target pragma to meet behavior of clang. Signed-off-by: Jerry Yu --- library/sha256.c | 6 ++++++ library/sha512.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/library/sha256.c b/library/sha256.c index 49a233d63f..81c011b338 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -57,7 +57,9 @@ # if __GNUC__ < 6 /* TODO: check sha256 compatible for GCC */ # error "A more recent GCC is required for MBEDTLS_SHA256_USE_A64_CRYPTO_*" # else +# pragma GCC push_options # pragma GCC target ("arch=armv8-a+crypto") +# define MBEDTLS_POP_TARGET_PRAGMA # endif # else # error "Only GCC and Clang supported for MBEDTLS_SHA256_USE_A64_CRYPTO_*" @@ -381,7 +383,11 @@ int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx, } #if defined(MBEDTLS_POP_TARGET_PRAGMA) +#if defined(__clang__) #pragma clang attribute pop +#elif defined(__GNUC__) +#pragma GCC pop_options +#endif #undef MBEDTLS_POP_TARGET_PRAGMA #endif diff --git a/library/sha512.c b/library/sha512.c index 827c08f34f..df8c5a9c1d 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -86,7 +86,9 @@ # if __GNUC__ < 8 # error "A more recent GCC is required for MBEDTLS_SHA512_USE_A64_CRYPTO_*" # else +# pragma GCC push_options # pragma GCC target ("arch=armv8.2-a+sha3") +# define MBEDTLS_POP_TARGET_PRAGMA # endif # else # error "Only GCC and Clang supported for MBEDTLS_SHA512_USE_A64_CRYPTO_*" @@ -567,7 +569,11 @@ int mbedtls_internal_sha512_process_a64_crypto(mbedtls_sha512_context *ctx, } #if defined(MBEDTLS_POP_TARGET_PRAGMA) +#if defined(__clang__) #pragma clang attribute pop +#elif defined(__GNUC__) +#pragma GCC pop_options +#endif #undef MBEDTLS_POP_TARGET_PRAGMA #endif