Move clang bug workaround to the head of file

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
Jerry Yu 2023-02-16 16:56:22 +08:00
parent 383cbf42a0
commit a135deeece
2 changed files with 49 additions and 22 deletions

View file

@ -22,8 +22,31 @@
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
#if defined(__aarch64__) && !defined(__ARM_FEATURE_CRYPTO) && \
defined(__clang__) && __clang_major__ < 18 && __clang_major__ > 3
/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
*
* The intrinsic declaration are guarded with ACLE predefined macros in clang,
* and those macros are only enabled with command line. Define the macros can
* enable those declaration and avoid compile error on it.
*/
#define __ARM_FEATURE_CRYPTO 1
#pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
#define MBEDTLS_POP_TARGET_PRAGMA
#endif /* __aarch64__ && __clang__ &&
!__ARM_FEATURE_CRYPTO && __clang_major__ < 18 && __clang_major__ > 3 */
#include "common.h"
#if defined(MBEDTLS_POP_TARGET_PRAGMA) && \
!(defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) || \
defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY))
#if defined(__clang__)
#pragma clang attribute pop
#endif
#undef MBEDTLS_POP_TARGET_PRAGMA
#endif
#if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C)
#include "mbedtls/sha256.h"
@ -42,16 +65,6 @@
# if defined(__clang__)
# if __clang_major__ < 4
# error "A more recent Clang is required for MBEDTLS_SHA256_USE_A64_CRYPTO_*"
# elif __clang_major__ < 18
/* TODO: Re-consider above after https://reviews.llvm.org/D131064
* merged.
*
* The intrinsic declaration are guarded with ACLE predefined macros
* in clang, and those macros are only enabled with command line.
* Define the macros can enable those declaration and avoid compile
* error on it.
*/
# define __ARM_FEATURE_CRYPTO 1
# endif
# pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
# define MBEDTLS_POP_TARGET_PRAGMA
@ -398,7 +411,6 @@ int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx,
#endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */
#if !defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT)
#define mbedtls_internal_sha256_process_many_c mbedtls_internal_sha256_process_many
#define mbedtls_internal_sha256_process_c mbedtls_internal_sha256_process

View file

@ -22,8 +22,34 @@
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
#if defined(__aarch64__) && !defined(__ARM_FEATURE_SHA512) && \
defined(__clang__) && __clang_major__ < 18 && \
__clang_major__ >= 13 && __clang_minor__ > 0 && __clang_patchlevel__ > 0
/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
*
* The intrinsic declaration are guarded with ACLE predefined macros in clang,
* and those macros are only enabled with command line. Define the macros can
* enable those declaration and avoid compile error on it.
*/
#define __ARM_FEATURE_SHA512 1
#pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
#define MBEDTLS_POP_TARGET_PRAGMA
#endif /* __aarch64__ && __clang__ &&
!__ARM_FEATURE_SHA512 && __clang_major__ < 18 &&
__clang_major__ >= 13 && __clang_minor__ > 0 &&
__clang_patchlevel__ > 0 */
#include "common.h"
#if defined(MBEDTLS_POP_TARGET_PRAGMA) && \
!(defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY))
#if defined(__clang__)
#pragma clang attribute pop
#endif
#undef MBEDTLS_POP_TARGET_PRAGMA
#endif
#if defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA384_C)
#include "mbedtls/sha512.h"
@ -68,17 +94,6 @@
__clang_patchlevel__ == 0)
/* We implement the intrinsics with inline assembler, so don't error */
# else
# if __clang_major__ < 18
/* TODO: Re-consider above after https://reviews.llvm.org/D131064
* merged.
*
* The intrinsic declaration are guarded with ACLE predefined macros
* in clang, and those macros are only enabled with command line.
* Define the macros can enable those declaration and avoid compile
* error on it.
*/
# define __ARM_FEATURE_SHA512 1
# endif
# pragma clang attribute push (__attribute__((target("sha3"))), apply_to=function)
# define MBEDTLS_POP_TARGET_PRAGMA
# endif