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