Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-compiler.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 6 | # This file contains test components that are executed by all.sh |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 7 | |
| 8 | ################################################################ |
| 9 | #### Compiler Testing |
| 10 | ################################################################ |
| 11 | |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 12 | support_build_tfm_armcc () { |
| 13 | support_build_armcc |
| 14 | } |
| 15 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 16 | component_build_tfm_armcc () { |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 17 | # test the TF-M configuration can build cleanly with various warning flags enabled |
| 18 | cp configs/config-tfm.h "$CONFIG_H" |
Harry Ramsey | 94c386a | 2025-01-16 16:08:34 +0000 | [diff] [blame] | 19 | cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H" |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 20 | |
| 21 | msg "build: TF-M config, armclang armv7-m thumb2" |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 22 | helper_armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../framework/tests/include/spe" |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 25 | test_build_opt () { |
| 26 | info=$1 cc=$2; shift 2 |
| 27 | $cc --version |
| 28 | for opt in "$@"; do |
| 29 | msg "build/test: $cc $opt, $info" # ~ 30s |
| 30 | make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror" |
| 31 | # We're confident enough in compilers to not run _all_ the tests, |
| 32 | # but at least run the unit tests. In particular, runs with |
| 33 | # optimizations use inline assembly whereas runs with -O0 |
| 34 | # skip inline assembly. |
| 35 | make test # ~30s |
| 36 | make clean |
| 37 | done |
| 38 | } |
| 39 | |
| 40 | # For FreeBSD we invoke the function by name so this condition is added |
| 41 | # to disable the existing test_clang_opt function for linux. |
| 42 | if [[ $(uname) != "Linux" ]]; then |
| 43 | component_test_clang_opt () { |
| 44 | scripts/config.py full |
| 45 | test_build_opt 'full config' clang -O0 -Os -O2 |
| 46 | } |
| 47 | fi |
| 48 | |
| 49 | component_test_clang_latest_opt () { |
| 50 | scripts/config.py full |
| 51 | test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2 |
| 52 | } |
| 53 | |
| 54 | support_test_clang_latest_opt () { |
| 55 | type "$CLANG_LATEST" >/dev/null 2>/dev/null |
| 56 | } |
| 57 | |
| 58 | component_test_clang_earliest_opt () { |
| 59 | scripts/config.py full |
Gilles Peskine | 20de806 | 2024-06-19 16:30:36 +0200 | [diff] [blame] | 60 | test_build_opt 'full config' "$CLANG_EARLIEST" -O2 |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | support_test_clang_earliest_opt () { |
| 64 | type "$CLANG_EARLIEST" >/dev/null 2>/dev/null |
| 65 | } |
| 66 | |
| 67 | component_test_gcc_latest_opt () { |
| 68 | scripts/config.py full |
| 69 | test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2 |
| 70 | } |
| 71 | |
| 72 | support_test_gcc_latest_opt () { |
| 73 | type "$GCC_LATEST" >/dev/null 2>/dev/null |
| 74 | } |
| 75 | |
| 76 | component_test_gcc_earliest_opt () { |
| 77 | scripts/config.py full |
Gilles Peskine | 20de806 | 2024-06-19 16:30:36 +0200 | [diff] [blame] | 78 | test_build_opt 'full config' "$GCC_EARLIEST" -O2 |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | support_test_gcc_earliest_opt () { |
| 82 | type "$GCC_EARLIEST" >/dev/null 2>/dev/null |
| 83 | } |
| 84 | |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 85 | component_build_mingw () { |
| 86 | msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s |
Gilles Peskine | d860f28 | 2024-06-19 16:34:29 +0200 | [diff] [blame] | 87 | make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 88 | |
| 89 | # note Make tests only builds the tests, but doesn't run them |
Gilles Peskine | d860f28 | 2024-06-19 16:34:29 +0200 | [diff] [blame] | 90 | make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 91 | make WINDOWS_BUILD=1 clean |
| 92 | |
| 93 | msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s |
Gilles Peskine | d860f28 | 2024-06-19 16:34:29 +0200 | [diff] [blame] | 94 | make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 lib programs |
| 95 | make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 tests |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 96 | make WINDOWS_BUILD=1 clean |
| 97 | |
| 98 | msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s |
| 99 | ./scripts/config.py unset MBEDTLS_AESNI_C # |
Gilles Peskine | d860f28 | 2024-06-19 16:34:29 +0200 | [diff] [blame] | 100 | make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 101 | make WINDOWS_BUILD=1 clean |
| 102 | } |
| 103 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 104 | support_build_mingw () { |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 105 | case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in |
| 106 | [0-5]*|"") false;; |
| 107 | *) true;; |
| 108 | esac |
| 109 | } |
| 110 | |
Minos Galanakis | bf47cf7 | 2024-08-01 12:35:25 +0100 | [diff] [blame] | 111 | component_build_zeroize_checks () { |
| 112 | msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()" |
| 113 | |
| 114 | scripts/config.py full |
| 115 | |
| 116 | # Only compile - we're looking for sizeof-pointer-memaccess warnings |
Harry Ramsey | 2a75a60 | 2025-02-17 15:52:58 +0000 | [diff] [blame^] | 117 | make CFLAGS="'-DTF_PSA_CRYPTO_USER_CONFIG_FILE=\"$TF_PSA_CRYPTO_ROOT_DIR/tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess" |
Minos Galanakis | bf47cf7 | 2024-08-01 12:35:25 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Minos Galanakis | 9ebb882 | 2024-07-26 15:21:14 +0100 | [diff] [blame] | 120 | component_test_zeroize () { |
| 121 | # Test that the function mbedtls_platform_zeroize() is not optimized away by |
| 122 | # different combinations of compilers and optimization flags by using an |
| 123 | # auxiliary GDB script. Unfortunately, GDB does not return error values to the |
| 124 | # system in all cases that the script fails, so we must manually search the |
| 125 | # output to check whether the pass string is present and no failure strings |
| 126 | # were printed. |
| 127 | |
| 128 | # Don't try to disable ASLR. We don't care about ASLR here. We do care |
| 129 | # about a spurious message if Gdb tries and fails, so suppress that. |
| 130 | gdb_disable_aslr= |
| 131 | if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then |
| 132 | gdb_disable_aslr='set disable-randomization off' |
| 133 | fi |
| 134 | |
| 135 | for optimization_flag in -O2 -O3 -Ofast -Os; do |
| 136 | for compiler in clang gcc; do |
| 137 | msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()" |
| 138 | make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag" |
| 139 | gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log |
| 140 | grep "The buffer was correctly zeroized" test_zeroize.log |
| 141 | not grep -i "error" test_zeroize.log |
| 142 | rm -f test_zeroize.log |
| 143 | make clean |
| 144 | done |
| 145 | done |
| 146 | } |