blob: ec0d0858635776b0d0e3745e4e9395e990b5e342 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# 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 Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Compiler Testing
10################################################################
11
Minos Galanakis9ebb8822024-07-26 15:21:14 +010012support_build_tfm_armcc () {
13 support_build_armcc
14}
15
Minos Galanakisf78447f2024-07-26 20:49:51 +010016component_build_tfm_armcc () {
Minos Galanakis9ebb8822024-07-26 15:21:14 +010017 # 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 Galanakis9ebb8822024-07-26 15:21:14 +010024test_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.
41if [[ $(uname) != "Linux" ]]; then
42 component_test_clang_opt () {
43 scripts/config.py full
44 test_build_opt 'full config' clang -O0 -Os -O2
45 }
46fi
47
48component_test_clang_latest_opt () {
49 scripts/config.py full
50 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
51}
52
53support_test_clang_latest_opt () {
54 type "$CLANG_LATEST" >/dev/null 2>/dev/null
55}
56
57component_test_clang_earliest_opt () {
58 scripts/config.py full
59 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
60}
61
62support_test_clang_earliest_opt () {
63 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
64}
65
66component_test_gcc_latest_opt () {
67 scripts/config.py full
68 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
69}
70
71support_test_gcc_latest_opt () {
72 type "$GCC_LATEST" >/dev/null 2>/dev/null
73}
74
75component_test_gcc_earliest_opt () {
76 scripts/config.py full
77 test_build_opt 'full config' "$GCC_EARLIEST" -O0
78}
79
80support_test_gcc_earliest_opt () {
81 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
82}
83
Minos Galanakis9ebb8822024-07-26 15:21:14 +010084component_build_mingw () {
85 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
86 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
87
88 # note Make tests only builds the tests, but doesn't run them
89 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
90 make WINDOWS_BUILD=1 clean
91
92 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
93 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
94 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
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 #
99 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
100 make WINDOWS_BUILD=1 clean
101}
102
Minos Galanakisf78447f2024-07-26 20:49:51 +0100103support_build_mingw () {
Minos Galanakis9ebb8822024-07-26 15:21:14 +0100104 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
105 [0-5]*|"") false;;
106 *) true;;
107 esac
108}
109
110component_test_zeroize () {
111 # Test that the function mbedtls_platform_zeroize() is not optimized away by
112 # different combinations of compilers and optimization flags by using an
113 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
114 # system in all cases that the script fails, so we must manually search the
115 # output to check whether the pass string is present and no failure strings
116 # were printed.
117
118 # Don't try to disable ASLR. We don't care about ASLR here. We do care
119 # about a spurious message if Gdb tries and fails, so suppress that.
120 gdb_disable_aslr=
121 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
122 gdb_disable_aslr='set disable-randomization off'
123 fi
124
125 for optimization_flag in -O2 -O3 -Ofast -Os; do
126 for compiler in clang gcc; do
127 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
128 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
129 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
130 grep "The buffer was correctly zeroized" test_zeroize.log
131 not grep -i "error" test_zeroize.log
132 rm -f test_zeroize.log
133 make clean
134 done
135 done
136}