From 62be45644904b97f4a316ce708379243b269bdbe Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 18 Dec 2023 18:34:50 +0000 Subject: [PATCH 01/11] Use clang by default Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index aa70f22e2cae..435d72a30228 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -174,6 +174,10 @@ pre_initialize_variables () { if [ -z "${MAKEFLAGS+set}" ]; then export MAKEFLAGS="-j$(all_sh_nproc)" fi + # if CC is not set, use clang by default to improve build times + if [ -z "${CC+set}" ]; then + export CC="clang" + fi # Include more verbose output for failing tests run by CMake or make export CTEST_OUTPUT_ON_FAILURE=1 From e0a2f6d08d4d760dbb01228c3a0b6ec716ab74f5 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 18 Dec 2023 19:53:25 +0000 Subject: [PATCH 02/11] Ensure clang is present Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 435d72a30228..9d9bb531e4e8 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -174,9 +174,9 @@ pre_initialize_variables () { if [ -z "${MAKEFLAGS+set}" ]; then export MAKEFLAGS="-j$(all_sh_nproc)" fi - # if CC is not set, use clang by default to improve build times - if [ -z "${CC+set}" ]; then - export CC="clang" + # if CC is not set, use clang by default (if present) to improve build times + if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then + export CC=$(type -p clang) fi # Include more verbose output for failing tests run by CMake or make From b0660c22d9ad2b056bdb1a4ed6612821f508f831 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 18 Dec 2023 19:55:40 +0000 Subject: [PATCH 03/11] Ensure test_psa_compliance uses gcc Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 9d9bb531e4e8..1ac4d0882871 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3582,9 +3582,10 @@ component_test_zeroize () { } component_test_psa_compliance () { + # The arch tests build with gcc, so require use of gcc here to link properly msg "build: make, default config + CMAC, libmbedcrypto.a only" scripts/config.py set MBEDTLS_CMAC_C - make -C library libmbedcrypto.a + CC=gcc make -C library libmbedcrypto.a msg "unit test: test_psa_compliance.py" ./tests/scripts/test_psa_compliance.py From 5b00fb111f8032f26c0f4e79d0f6507ef82daf87 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 18 Dec 2023 22:29:56 +0000 Subject: [PATCH 04/11] Use gcc in test_psa_compliance Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 1ac4d0882871..05d413ba17a2 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -3588,7 +3588,7 @@ component_test_psa_compliance () { CC=gcc make -C library libmbedcrypto.a msg "unit test: test_psa_compliance.py" - ./tests/scripts/test_psa_compliance.py + CC=gcc ./tests/scripts/test_psa_compliance.py } support_test_psa_compliance () { From b046b9a96bc0ba45af2662db17dc679e5688ba70 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 19 Dec 2023 11:33:55 +0000 Subject: [PATCH 05/11] Enable -O2 in depends.py Signed-off-by: Dave Rodgman --- tests/scripts/depends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/depends.py b/tests/scripts/depends.py index 6c2e6d6e3b9d..c6a438ee362f 100755 --- a/tests/scripts/depends.py +++ b/tests/scripts/depends.py @@ -392,7 +392,7 @@ def config_symbols_matching(self, regexp): def __init__(self, options, conf): """Gather data about the library and establish a list of domains to test.""" - build_command = [options.make_command, 'CFLAGS=-Werror'] + build_command = [options.make_command, 'CFLAGS=-Werror -O2'] build_and_test = [build_command, [options.make_command, 'test']] self.all_config_symbols = set(conf.settings.keys()) # Find hash modules by name. From 374b1884680a3c2ccab75576ccb63d64266a6d27 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 4 Jan 2024 10:30:57 +0000 Subject: [PATCH 06/11] Don't specify gcc unless the test requires it Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 05d413ba17a2..3eba418d1233 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1661,7 +1661,7 @@ component_test_default_no_deprecated () { # configuration leaves something consistent. msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s scripts/config.py set MBEDTLS_DEPRECATED_REMOVED - make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' + make CFLAGS='-O -Werror -Wall -Wextra' msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s make test @@ -1670,7 +1670,7 @@ component_test_default_no_deprecated () { component_test_full_no_deprecated () { msg "build: make, full_no_deprecated config" # ~ 30s scripts/config.py full_no_deprecated - make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' + make CFLAGS='-O -Werror -Wall -Wextra' msg "test: make, full_no_deprecated config" # ~ 5s make test @@ -1684,7 +1684,7 @@ component_test_full_no_deprecated_deprecated_warning () { scripts/config.py full_no_deprecated scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED scripts/config.py set MBEDTLS_DEPRECATED_WARNING - make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' + make CFLAGS='-O -Werror -Wall -Wextra' msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s make test @@ -1697,14 +1697,14 @@ component_test_full_deprecated_warning () { scripts/config.py full scripts/config.py set MBEDTLS_DEPRECATED_WARNING # Expect warnings from '#warning' directives in check_config.h. - make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs + make CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features. # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set. # Expect warnings from '#warning' directives in check_config.h and # from the use of deprecated functions in test suites. - make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests + make CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s make test @@ -1866,7 +1866,7 @@ component_build_no_pk_rsa_alt_support () { scripts/config.py set MBEDTLS_X509_CRT_WRITE_C # Only compile - this is primarily to test for compile issues - make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' + make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' } component_test_no_use_psa_crypto_full_cmake_asan() { @@ -2623,7 +2623,7 @@ component_test_memory_buffer_allocator_backtrace () { scripts/config.py set MBEDTLS_PLATFORM_MEMORY scripts/config.py set MBEDTLS_MEMORY_BACKTRACE scripts/config.py set MBEDTLS_MEMORY_DEBUG - CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release . + cmake -DCMAKE_BUILD_TYPE:String=Release . make msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE" @@ -2634,7 +2634,7 @@ component_test_memory_buffer_allocator () { msg "build: default config with memory buffer allocator" scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.py set MBEDTLS_PLATFORM_MEMORY - CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release . + cmake -DCMAKE_BUILD_TYPE:String=Release . make msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C" @@ -2749,7 +2749,7 @@ component_test_ssl_alloc_buffer_and_mfl () { scripts/config.py set MBEDTLS_MEMORY_DEBUG scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH - CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release . + cmake -DCMAKE_BUILD_TYPE:String=Release . make msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH" @@ -2849,7 +2849,7 @@ component_test_malloc_0_null () { component_test_aes_fewer_tables () { msg "build: default config with AES_FEWER_TABLES enabled" scripts/config.py set MBEDTLS_AES_FEWER_TABLES - make CC=gcc CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-Werror -Wall -Wextra' msg "test: AES_FEWER_TABLES" make test @@ -2858,7 +2858,7 @@ component_test_aes_fewer_tables () { component_test_aes_rom_tables () { msg "build: default config with AES_ROM_TABLES enabled" scripts/config.py set MBEDTLS_AES_ROM_TABLES - make CC=gcc CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-Werror -Wall -Wextra' msg "test: AES_ROM_TABLES" make test @@ -2868,7 +2868,7 @@ component_test_aes_fewer_tables_and_rom_tables () { msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled" scripts/config.py set MBEDTLS_AES_FEWER_TABLES scripts/config.py set MBEDTLS_AES_ROM_TABLES - make CC=gcc CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-Werror -Wall -Wextra' msg "test: AES_FEWER_TABLES + AES_ROM_TABLES" make test @@ -3549,7 +3549,7 @@ component_build_zeroize_checks () { scripts/config.py full # Only compile - we're looking for sizeof-pointer-memaccess warnings - make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess" + make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess" } From ce04f2473782317ef2fb81d9700f7c8f734efe95 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 4 Jan 2024 10:34:31 +0000 Subject: [PATCH 07/11] Add -O2 to some CFLAGS which were not setting it Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 3eba418d1233..da96040036a8 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -2849,7 +2849,7 @@ component_test_malloc_0_null () { component_test_aes_fewer_tables () { msg "build: default config with AES_FEWER_TABLES enabled" scripts/config.py set MBEDTLS_AES_FEWER_TABLES - make CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-O2 -Werror -Wall -Wextra' msg "test: AES_FEWER_TABLES" make test @@ -2858,7 +2858,7 @@ component_test_aes_fewer_tables () { component_test_aes_rom_tables () { msg "build: default config with AES_ROM_TABLES enabled" scripts/config.py set MBEDTLS_AES_ROM_TABLES - make CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-O2 -Werror -Wall -Wextra' msg "test: AES_ROM_TABLES" make test @@ -2868,7 +2868,7 @@ component_test_aes_fewer_tables_and_rom_tables () { msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled" scripts/config.py set MBEDTLS_AES_FEWER_TABLES scripts/config.py set MBEDTLS_AES_ROM_TABLES - make CFLAGS='-Werror -Wall -Wextra' + make CFLAGS='-O2 -Werror -Wall -Wextra' msg "test: AES_FEWER_TABLES + AES_ROM_TABLES" make test @@ -3103,7 +3103,7 @@ support_test_m32_everest () { component_test_mx32 () { msg "build: 64-bit ILP32, make, gcc" # ~ 30s scripts/config.py full - make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32' + make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32' msg "test: 64-bit ILP32, make, gcc" make test @@ -3130,7 +3130,7 @@ component_test_have_int32 () { scripts/config.py unset MBEDTLS_HAVE_ASM scripts/config.py unset MBEDTLS_AESNI_C scripts/config.py unset MBEDTLS_PADLOCK_C - make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32' + make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32' msg "test: gcc, force 32-bit bignum limbs" make test @@ -3141,7 +3141,7 @@ component_test_have_int64 () { scripts/config.py unset MBEDTLS_HAVE_ASM scripts/config.py unset MBEDTLS_AESNI_C scripts/config.py unset MBEDTLS_PADLOCK_C - make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64' + make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64' msg "test: gcc, force 64-bit bignum limbs" make test From 9d2c67f8e2b78e51bcb23f80141964f0a7a00363 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 19 Dec 2023 14:07:15 +0000 Subject: [PATCH 08/11] Use gcc in test_full_deprecated_warning Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index da96040036a8..67d4a0daa7ad 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1697,14 +1697,16 @@ component_test_full_deprecated_warning () { scripts/config.py full scripts/config.py set MBEDTLS_DEPRECATED_WARNING # Expect warnings from '#warning' directives in check_config.h. - make CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs + # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to + # display #warning messages without them being treated as errors. + make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features. # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set. # Expect warnings from '#warning' directives in check_config.h and # from the use of deprecated functions in test suites. - make CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests + make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s make test From e42c23569b4857d97e7985fe462db45cba763829 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 19 Dec 2023 16:08:19 +0000 Subject: [PATCH 09/11] Don't use full path for setting CC Signed-off-by: Dave Rodgman --- tests/scripts/all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 67d4a0daa7ad..df26cb1599a6 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -176,7 +176,7 @@ pre_initialize_variables () { fi # if CC is not set, use clang by default (if present) to improve build times if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then - export CC=$(type -p clang) + export CC="clang" fi # Include more verbose output for failing tests run by CMake or make From 52c294acb42a292e224f303a8454bee8a156b06b Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 4 Jan 2024 11:37:17 +0000 Subject: [PATCH 10/11] backport MBEDTLS_MAYBE_UNUSED Signed-off-by: Dave Rodgman --- library/common.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/common.h b/library/common.h index bf18d725ccff..49e2c97ea049 100644 --- a/library/common.h +++ b/library/common.h @@ -350,4 +350,31 @@ static inline const unsigned char *mbedtls_buffer_offset_const( #define MBEDTLS_STATIC_ASSERT(expr, msg) #endif +/* Suppress compiler warnings for unused functions and variables. */ +#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__has_attribute) +# if __has_attribute(unused) +# define MBEDTLS_MAYBE_UNUSED __attribute__((unused)) +# endif +#endif +#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__GNUC__) +# define MBEDTLS_MAYBE_UNUSED __attribute__((unused)) +#endif +#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__IAR_SYSTEMS_ICC__) && defined(__VER__) +/* IAR does support __attribute__((unused)), but only if the -e flag (extended language support) + * is given; the pragma always works. + * Unfortunately the pragma affects the rest of the file where it is used, but this is harmless. + * Check for version 5.2 or later - this pragma may be supported by earlier versions, but I wasn't + * able to find documentation). + */ +# if (__VER__ >= 5020000) +# define MBEDTLS_MAYBE_UNUSED _Pragma("diag_suppress=Pe177") +# endif +#endif +#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(_MSC_VER) +# define MBEDTLS_MAYBE_UNUSED __pragma(warning(suppress:4189)) +#endif +#if !defined(MBEDTLS_MAYBE_UNUSED) +# define MBEDTLS_MAYBE_UNUSED +#endif + #endif /* MBEDTLS_LIBRARY_COMMON_H */ From 0fd07d5e10ae57ba96800ccc8dd8ad10aa56dcda Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 4 Jan 2024 11:37:35 +0000 Subject: [PATCH 11/11] Mark test function with MBEDTLS_MAYBE_UNUSED Signed-off-by: Dave Rodgman --- tests/suites/test_suite_ecp.function | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function index b1340614567b..443bc0861bfe 100644 --- a/tests/suites/test_suite_ecp.function +++ b/tests/suites/test_suite_ecp.function @@ -19,6 +19,7 @@ mbedtls_ecp_point_init(x); /* Auxiliary function to compare two mbedtls_ecp_group objects. */ +MBEDTLS_MAYBE_UNUSED inline static int mbedtls_ecp_group_cmp(mbedtls_ecp_group *grp1, mbedtls_ecp_group *grp2) {