From 2e068cef0938ee60d50a879045934bbc9d66a364 Mon Sep 17 00:00:00 2001 From: Matthias Schulz Date: Thu, 9 Nov 2023 15:25:52 +0100 Subject: [PATCH 1/4] fixes invalid default choice of thumb assembler syntax. Signed-off-by: Matthias Schulz --- library/constant_time_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index f0b2fc02f0..aff48cfbbe 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -123,7 +123,7 @@ static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x) * For gcc, restore divided syntax afterwards - otherwise old versions of gcc * seem to apply unified syntax globally, which breaks other asm code. */ -#if !defined(__clang__) +#if !defined(__clang__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 9) #define RESTORE_ASM_SYNTAX ".syntax divided \n\t" #else #define RESTORE_ASM_SYNTAX From ca8981c1eec5c5d43bca19e8011d9ba71a5cebbc Mon Sep 17 00:00:00 2001 From: Matthias Schulz Date: Mon, 13 Nov 2023 10:04:19 +0100 Subject: [PATCH 2/4] Added proposed fixes Signed-off-by: Matthias Schulz --- library/constant_time_impl.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index aff48cfbbe..57bb52e3d9 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -120,10 +120,12 @@ static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x) * On Thumb 2 and Arm, both compilers are happy with the "s" suffix, * although we don't actually care about setting the flags. * - * For gcc, restore divided syntax afterwards - otherwise old versions of gcc + * For old versions of gcc excluding 4.8 and 4.9 (see #8516 for details), + * restore divided syntax afterwards - otherwise old versions of gcc * seem to apply unified syntax globally, which breaks other asm code. */ -#if !defined(__clang__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 9) +#if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__thumb__) && !defined(__thumb2__) && \ + (__GNUC__ < 11) && !((__GNUC__ == 4) && ((__GNUC_MINOR__ == 8) || (__GNUC_MINOR__ == 9))) #define RESTORE_ASM_SYNTAX ".syntax divided \n\t" #else #define RESTORE_ASM_SYNTAX From 35842f52f2b6eb0245cb246c841bcb63d69d918e Mon Sep 17 00:00:00 2001 From: Matthias Schulz Date: Mon, 13 Nov 2023 13:57:05 +0100 Subject: [PATCH 3/4] Simplified check. Signed-off-by: Matthias Schulz --- library/constant_time_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index 57bb52e3d9..cd93767c66 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -125,7 +125,7 @@ static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x) * seem to apply unified syntax globally, which breaks other asm code. */ #if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__thumb__) && !defined(__thumb2__) && \ - (__GNUC__ < 11) && !((__GNUC__ == 4) && ((__GNUC_MINOR__ == 8) || (__GNUC_MINOR__ == 9))) + (__GNUC__ < 11) && !defined(__ARM_ARCH_2__) #define RESTORE_ASM_SYNTAX ".syntax divided \n\t" #else #define RESTORE_ASM_SYNTAX From e94525bd176de9384dbe7b5229a94b029011b334 Mon Sep 17 00:00:00 2001 From: Matthias Schulz Date: Mon, 13 Nov 2023 14:01:02 +0100 Subject: [PATCH 4/4] Updated comments. Signed-off-by: Matthias Schulz --- library/constant_time_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index cd93767c66..18a967b52a 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -120,9 +120,9 @@ static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x) * On Thumb 2 and Arm, both compilers are happy with the "s" suffix, * although we don't actually care about setting the flags. * - * For old versions of gcc excluding 4.8 and 4.9 (see #8516 for details), - * restore divided syntax afterwards - otherwise old versions of gcc - * seem to apply unified syntax globally, which breaks other asm code. + * For old versions of gcc (see #8516 for details), restore divided + * syntax afterwards - otherwise old versions of gcc seem to apply + * unified syntax globally, which breaks other asm code. */ #if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__thumb__) && !defined(__thumb2__) && \ (__GNUC__ < 11) && !defined(__ARM_ARCH_2__)