From ef2aa0ecad3cbdf400f3878e92cf6416fb16d38b Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 9 Jun 2023 11:29:50 +0100 Subject: [PATCH 1/5] Fix "unterminated '#pragma clang attribute push'" in sha256/sha512.c If we're built with MBEDTLS_SHAxxx_USE_A64_CRYPTO_IF_PRESENT but don't have a way to detect the crypto extensions required, the code turns off _IF_PRESENT and falls back to C only (with a warning). This was done after the attributes are pushed, and the pop is done only #if defined(xxx_IF_PRESENT), so this commit fixes that. Signed-off-by: Tom Cosgrove --- ChangeLog.d/fix-unterminated-pragma-clang-attribute-push.txt | 4 ++++ library/sha256.c | 4 ++-- library/sha512.c | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 ChangeLog.d/fix-unterminated-pragma-clang-attribute-push.txt diff --git a/ChangeLog.d/fix-unterminated-pragma-clang-attribute-push.txt b/ChangeLog.d/fix-unterminated-pragma-clang-attribute-push.txt new file mode 100644 index 000000000..7fcb5ec29 --- /dev/null +++ b/ChangeLog.d/fix-unterminated-pragma-clang-attribute-push.txt @@ -0,0 +1,4 @@ +Bugfix + * Fix "unterminated '#pragma clang attribute push'" in sha256/sha512.c when + built with MBEDTLS_SHAxxx_USE_A64_CRYPTO_IF_PRESENT but don't have a + way to detect the crypto extensions required. A warning is still issued. diff --git a/library/sha256.c b/library/sha256.c index 08822f441..169229c88 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -399,6 +399,8 @@ int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx, SHA256_BLOCK_SIZE) ? 0 : -1; } +#endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */ + #if defined(MBEDTLS_POP_TARGET_PRAGMA) #if defined(__clang__) #pragma clang attribute pop @@ -408,8 +410,6 @@ int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx, #undef MBEDTLS_POP_TARGET_PRAGMA #endif -#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 diff --git a/library/sha512.c b/library/sha512.c index 67acfee48..b8b24854d 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -569,6 +569,8 @@ int mbedtls_internal_sha512_process_a64_crypto(mbedtls_sha512_context *ctx, SHA512_BLOCK_SIZE) ? 0 : -1; } +#endif /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */ + #if defined(MBEDTLS_POP_TARGET_PRAGMA) #if defined(__clang__) #pragma clang attribute pop @@ -578,8 +580,6 @@ int mbedtls_internal_sha512_process_a64_crypto(mbedtls_sha512_context *ctx, #undef MBEDTLS_POP_TARGET_PRAGMA #endif -#endif /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */ - #if !defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) #define mbedtls_internal_sha512_process_many_c mbedtls_internal_sha512_process_many From 46ed3a9834811d49b57fc4480b7bd7d1f8c2b32d Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 9 Jun 2023 12:21:53 +0100 Subject: [PATCH 2/5] Add an all.sh build test that catches the unterminated pragmas Signed-off-by: Tom Cosgrove --- tests/scripts/all.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 8242f88bc..b7bf85421 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3962,6 +3962,11 @@ component_build_armcc () { # ARM Compiler 6 - Target Cortex-M0 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0" + + # Check that we handle "No mechanism to detect A64_CRYPTO found" properly + scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT + scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT + armc6_build_test "-Wno-#warnings -O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto" } support_build_armcc () { armc5_cc="$ARMC5_BIN_DIR/armcc" From 579e6e9a0567ae3d8e9313522ebdfd166a648b2f Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 9 Jun 2023 13:01:21 +0100 Subject: [PATCH 3/5] Merge the two ARM Compiler 6 - Target ARMv8.2-A - AArch64 builds Signed-off-by: Tom Cosgrove --- tests/scripts/all.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index b7bf85421..b1f8f0fcf 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3954,16 +3954,14 @@ component_build_armcc () { # ARM Compiler 6 - Target ARMv8-M armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main" - # ARM Compiler 6 - Target ARMv8.2-A - AArch64 - armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto" - # ARM Compiler 6 - Target Cortex-M0 - no optimisation armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0" # ARM Compiler 6 - Target Cortex-M0 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0" - # Check that we handle "No mechanism to detect A64_CRYPTO found" properly + # ARM Compiler 6 - Target ARMv8.2-A - AArch64, and + # check that we handle "No mechanism to detect A64_CRYPTO found" properly scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT armc6_build_test "-Wno-#warnings -O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto" From 730addc203111e066873ca671d4aeeb45e3eb4e3 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 9 Jun 2023 14:20:18 +0100 Subject: [PATCH 4/5] Fix armc5-bin-dir and armc6-bin-dir options to all.sh ARMC5_BIN_DIR and ARMC6_BIN_DIR were set in pre_parse_command_line() and used by support_build_armcc() which is called by pre_initialize_variables() to determines SUPPORTED_COMPONENTS. As pre_initialize_variables() is called before pre_parse_command_line(), support_build_armcc() failed to use the directories set on the command line. However, we can't call pre_parse_command_line() before pre_initialize_variables() since the former needs SUPPORTED_COMPONENTS! Fix the circular dependency by parsing the command line twice, with the first pass only to get these directories. Signed-off-by: Tom Cosgrove --- tests/scripts/all.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index b1f8f0fcf..7772da9ac 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -411,6 +411,18 @@ check_tools() done } +pre_parse_command_line_for_dirs () { + # Make an early pass through the options given, so we can set directories + # for Arm compilers, before SUPPORTED_COMPONENTS is determined. + while [ $# -gt 0 ]; do + case "$1" in + --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";; + --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";; + esac + shift + done +} + pre_parse_command_line () { COMMAND_LINE_COMPONENTS= all_except=0 @@ -427,8 +439,8 @@ pre_parse_command_line () { --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";; --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";; --armcc) no_armcc=;; - --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";; - --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";; + --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs + --armc6-bin-dir) shift; ;; # assignment to ARMC6_BIN_DIR done in pre_parse_command_line_for_dirs --error-test) error_test=$((error_test + 1));; --except) all_except=1;; --force|-f) FORCE=1;; @@ -4447,6 +4459,7 @@ run_component () { # Preliminary setup pre_check_environment +pre_parse_command_line_for_dirs "$@" pre_initialize_variables pre_parse_command_line "$@" From 6ec39cacaaed4f7dfdbc9a4ae30e6be18e3f4347 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Fri, 9 Jun 2023 15:34:31 +0100 Subject: [PATCH 5/5] Remove the all.sh test for this, since armclang on CI is too old Signed-off-by: Tom Cosgrove --- tests/scripts/all.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 7772da9ac..78179a83f 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3966,18 +3966,16 @@ component_build_armcc () { # ARM Compiler 6 - Target ARMv8-M armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main" + # ARM Compiler 6 - Target ARMv8.2-A - AArch64 + armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto" + # ARM Compiler 6 - Target Cortex-M0 - no optimisation armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0" # ARM Compiler 6 - Target Cortex-M0 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0" - - # ARM Compiler 6 - Target ARMv8.2-A - AArch64, and - # check that we handle "No mechanism to detect A64_CRYPTO found" properly - scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT - scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT - armc6_build_test "-Wno-#warnings -O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto" } + support_build_armcc () { armc5_cc="$ARMC5_BIN_DIR/armcc" armc6_cc="$ARMC6_BIN_DIR/armclang"