From da3c206ebde6c29904fb46a61ec7534f90c0d08e Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Tue, 28 Nov 2023 14:28:03 +0800 Subject: [PATCH 1/5] fix build warning with arm64 gcc 5.4 GCC 5.4 reports below warning on Arm64 ``` warning: 'vst1q_u8' is static but used in inline function 'mbedtls_xor' which is not static ``` This inline function miss `static`, others have the keyword Signed-off-by: Jerry Yu --- library/common.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/common.h b/library/common.h index c20f6b260..ec30a7da1 100644 --- a/library/common.h +++ b/library/common.h @@ -165,7 +165,10 @@ static inline const unsigned char *mbedtls_buffer_offset_const( * \param b Pointer to input (buffer of at least \p n bytes) * \param n Number of bytes to process. */ -inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned char *b, size_t n) +static inline void mbedtls_xor(unsigned char *r, + const unsigned char *a, + const unsigned char *b, + size_t n) { size_t i = 0; #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) From 5b96b819803d69b2be8b7afb65d500f92faeb98f Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 29 Nov 2023 10:25:00 +0800 Subject: [PATCH 2/5] Revert "fix build warning with arm64 gcc 5.4" This reverts commit da3c206ebde6c29904fb46a61ec7534f90c0d08e. Signed-off-by: Jerry Yu --- library/common.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/common.h b/library/common.h index ec30a7da1..c20f6b260 100644 --- a/library/common.h +++ b/library/common.h @@ -165,10 +165,7 @@ static inline const unsigned char *mbedtls_buffer_offset_const( * \param b Pointer to input (buffer of at least \p n bytes) * \param n Number of bytes to process. */ -static inline void mbedtls_xor(unsigned char *r, - const unsigned char *a, - const unsigned char *b, - size_t n) +inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned char *b, size_t n) { size_t i = 0; #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) From 71fada10e5b05e328d3a7ae75ea5a0edaf9d271a Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 29 Nov 2023 10:38:07 +0800 Subject: [PATCH 3/5] Guards neon path Old GCC(<7.3) reports warning in NEON path Signed-off-by: Jerry Yu --- library/common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/common.h b/library/common.h index c20f6b260..78d71fda2 100644 --- a/library/common.h +++ b/library/common.h @@ -169,7 +169,9 @@ inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned { size_t i = 0; #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) -#if defined(__ARM_NEON) +#if defined(__ARM_NEON) && \ + (defined(__GNUC__) && !defined(__clang__) && \ + __GNUC__ >= 7 && __GNUC_MINOR__ >= 3) for (; (i + 16) <= n; i += 16) { uint8x16_t v1 = vld1q_u8(a + i); uint8x16_t v2 = vld1q_u8(b + i); From e743aa74b50470e6b1d4df55766f0fefb80b942b Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 29 Nov 2023 15:54:32 +0800 Subject: [PATCH 4/5] add non-gcc arm_neon support Signed-off-by: Jerry Yu --- library/common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/common.h b/library/common.h index 78d71fda2..cc58bf4f6 100644 --- a/library/common.h +++ b/library/common.h @@ -170,8 +170,8 @@ inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned size_t i = 0; #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) #if defined(__ARM_NEON) && \ - (defined(__GNUC__) && !defined(__clang__) && \ - __GNUC__ >= 7 && __GNUC_MINOR__ >= 3) + (!defined(MBEDTLS_COMPILER_IS_GCC) || \ + (defined(MBEDTLS_COMPILER_IS_GCC) && __GNUC__ >= 7 && __GNUC_MINOR__ >= 3)) for (; (i + 16) <= n; i += 16) { uint8x16_t v1 = vld1q_u8(a + i); uint8x16_t v2 = vld1q_u8(b + i); From 92787e42c42433b6a9cde0dd5a79b5baf011815a Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 29 Nov 2023 16:30:38 +0800 Subject: [PATCH 5/5] fix wrong gcc version check Signed-off-by: Jerry Yu --- library/common.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/library/common.h b/library/common.h index cc58bf4f6..bd5a0c392 100644 --- a/library/common.h +++ b/library/common.h @@ -23,6 +23,15 @@ #include #endif /* __ARM_NEON */ + +#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \ + && !defined(__llvm__) && !defined(__INTEL_COMPILER) +/* Defined if the compiler really is gcc and not clang, etc */ +#define MBEDTLS_COMPILER_IS_GCC +#define MBEDTLS_GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#endif + /** Helper to define a function as static except when building invasive tests. * * If a function is only used inside its own source file and should be @@ -171,7 +180,7 @@ inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned #if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) #if defined(__ARM_NEON) && \ (!defined(MBEDTLS_COMPILER_IS_GCC) || \ - (defined(MBEDTLS_COMPILER_IS_GCC) && __GNUC__ >= 7 && __GNUC_MINOR__ >= 3)) + (defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION >= 70300)) for (; (i + 16) <= n; i += 16) { uint8x16_t v1 = vld1q_u8(a + i); uint8x16_t v2 = vld1q_u8(b + i); @@ -326,12 +335,6 @@ static inline void mbedtls_xor_no_simd(unsigned char *r, #define MBEDTLS_ASSUME(x) do { } while (0) #endif -#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \ - && !defined(__llvm__) && !defined(__INTEL_COMPILER) -/* Defined if the compiler really is gcc and not clang, etc */ -#define MBEDTLS_COMPILER_IS_GCC -#endif - /* For gcc -Os, override with -O2 for a given function. * * This will not affect behaviour for other optimisation settings, e.g. -O0.