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