blob: 813881573484f136966c296459d672c98280e20c [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components-platform.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#### Platform Testing
10################################################################
11
Minos Galanakis8a980902024-07-26 17:41:03 +010012component_test_malloc_0_null () {
13 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
14 scripts/config.py full
15 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
16
17 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
18 make test
19
20 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
21 # Just the calloc selftest. "make test" ran the others as part of the
22 # test suites.
23 programs/test/selftest calloc
24
25 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
26 # Run a subset of the tests. The choice is a balance between coverage
27 # and time (including time indirectly wasted due to flaky tests).
28 # The current choice is to skip tests whose description includes
29 # "proxy", which is an approximation of skipping tests that use the
30 # UDP proxy, which tend to be slower and flakier.
31 tests/ssl-opt.sh -e 'proxy'
32}
33
34component_test_m32_no_asm () {
35 # Build without assembly, so as to use portable C code (in a 32-bit
36 # build) and not the i386-specific inline assembly.
37 #
38 # Note that we require gcc, because clang Asan builds fail to link for
39 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
40 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
41 scripts/config.py full
42 scripts/config.py unset MBEDTLS_HAVE_ASM
43 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
44 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
45
46 msg "test: i386, make, gcc, no asm (ASan build)"
47 make test
48}
49
50support_test_m32_no_asm () {
51 case $(uname -m) in
52 amd64|x86_64) true;;
53 *) false;;
54 esac
55}
56
57component_test_m32_o2 () {
58 # Build with optimization, to use the i386 specific inline assembly
59 # and go faster for tests.
60 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
61 scripts/config.py full
62 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
63 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
64
65 msg "test: i386, make, gcc -O2 (ASan build)"
66 make test
67
68 msg "test ssl-opt.sh, i386, make, gcc-O2"
69 tests/ssl-opt.sh
70}
71
72support_test_m32_o2 () {
73 support_test_m32_no_asm "$@"
74}
75
76component_test_m32_everest () {
77 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
78 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
79 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
80 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
81
82 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
83 make test
84
85 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
86 tests/ssl-opt.sh -f ECDH
87
88 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
89 # Exclude some symmetric ciphers that are redundant here to gain time.
90 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
91}
92
93support_test_m32_everest () {
94 support_test_m32_no_asm "$@"
95}
96
97component_test_mx32 () {
98 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
99 scripts/config.py full
100 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
101
102 msg "test: 64-bit ILP32, make, gcc"
103 make test
104}
105
106support_test_mx32 () {
107 case $(uname -m) in
108 amd64|x86_64) true;;
109 *) false;;
110 esac
111}
112
Minos Galanakisb5891d52024-08-01 11:55:33 +0100113support_test_aesni () {
114 # Check that gcc targets x86_64 (we can build AESNI), and check for
115 # AESNI support on the host (we can run AESNI).
116 #
117 # The name of this function is possibly slightly misleading, but needs to align
118 # with the name of the corresponding test, component_test_aesni.
119 #
120 # In principle 32-bit x86 can support AESNI, but our implementation does not
121 # support 32-bit x86, so we check for x86-64.
122 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
123 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
124 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
125 (lscpu | grep -qw aes)
126}
127
128component_test_aesni () { # ~ 60s
129 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
130 # fallback. It also tests the logic that is used to select which implementation(s) to build.
131 #
132 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
133 # AESNI detection will fallback to the plain C implementation, so the tests will instead
134 # exercise the plain C impl).
135
136 msg "build: default config with different AES implementations"
137 scripts/config.py set MBEDTLS_AESNI_C
138 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
139 scripts/config.py set MBEDTLS_HAVE_ASM
140
141 # test the intrinsics implementation
142 msg "AES tests, test intrinsics"
143 make clean
144 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
145 # check that we built intrinsics - this should be used by default when supported by the compiler
146 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
147
148 # test the asm implementation
149 msg "AES tests, test assembly"
150 make clean
151 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
152 # check that we built assembly - this should be built if the compiler does not support intrinsics
153 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
154
155 # test the plain C implementation
156 scripts/config.py unset MBEDTLS_AESNI_C
157 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
158 msg "AES tests, plain C"
159 make clean
160 make CC=gcc CFLAGS='-O2 -Werror'
161 # check that there is no AESNI code present
162 ./programs/test/selftest aes | not grep -q "AESNI code"
163 not grep -q "AES note: using AESNI" ./programs/test/selftest
164 grep -q "AES note: built-in implementation." ./programs/test/selftest
165
166 # test the intrinsics implementation
167 scripts/config.py set MBEDTLS_AESNI_C
168 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
169 msg "AES tests, test AESNI only"
170 make clean
171 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
172 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
173 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
174 grep -q "AES note: using AESNI" ./programs/test/selftest
175 not grep -q "AES note: built-in implementation." ./programs/test/selftest
176}
177
178support_test_aesni_m32 () {
179 support_test_m32_no_asm && (lscpu | grep -qw aes)
180}
181
182component_test_aesni_m32 () { # ~ 60s
183 # This tests are duplicated from component_test_aesni for i386 target
184 #
185 # AESNI intrinsic code supports i386 and assembly code does not support it.
186
187 msg "build: default config with different AES implementations"
188 scripts/config.py set MBEDTLS_AESNI_C
189 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
190 scripts/config.py set MBEDTLS_HAVE_ASM
191
192 # test the intrinsics implementation with gcc
193 msg "AES tests, test intrinsics (gcc)"
194 make clean
195 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
196 # check that we built intrinsics - this should be used by default when supported by the compiler
197 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
198 grep -q "AES note: using AESNI" ./programs/test/selftest
199 grep -q "AES note: built-in implementation." ./programs/test/selftest
200 grep -q mbedtls_aesni_has_support ./programs/test/selftest
201
202 scripts/config.py set MBEDTLS_AESNI_C
203 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
204 msg "AES tests, test AESNI only"
205 make clean
206 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
207 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
208 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
209 grep -q "AES note: using AESNI" ./programs/test/selftest
210 not grep -q "AES note: built-in implementation." ./programs/test/selftest
211 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
212}
213
Minos Galanakis1ef3a662024-08-01 11:47:49 +0100214support_test_aesni_m32_clang () {
215 # clang >= 4 is required to build with target attributes
216 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
217}
218
219component_test_aesni_m32_clang () {
220
221 scripts/config.py set MBEDTLS_AESNI_C
222 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
223 scripts/config.py set MBEDTLS_HAVE_ASM
224
225 # test the intrinsics implementation with clang
226 msg "AES tests, test intrinsics (clang)"
227 make clean
228 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
229 # check that we built intrinsics - this should be used by default when supported by the compiler
230 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
231 grep -q "AES note: using AESNI" ./programs/test/selftest
232 grep -q "AES note: built-in implementation." ./programs/test/selftest
233 grep -q mbedtls_aesni_has_support ./programs/test/selftest
234}
235
Minos Galanakisb5891d52024-08-01 11:55:33 +0100236support_build_aes_armce () {
237 # clang >= 11 is required to build with AES extensions
238 [[ $(clang_version) -ge 11 ]]
239}
240
241component_build_aes_armce () {
242 # Test variations of AES with Armv8 crypto extensions
243 scripts/config.py set MBEDTLS_AESCE_C
244 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
245
246 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
247 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
248
249 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
250 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
251
252 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
253 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
254
255 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
256
257 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
258 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
259
260 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
261 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
262
263 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
264 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
265
266 # test for presence of AES instructions
267 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
268 msg "clang, test A32 crypto instructions built"
269 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
270 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
271 msg "clang, test T32 crypto instructions built"
272 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
273 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
274 msg "clang, test aarch64 crypto instructions built"
275 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
276 grep -E 'aes[a-z]+\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
277
278 # test for absence of AES instructions
279 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
280 scripts/config.py unset MBEDTLS_AESCE_C
281 msg "clang, test A32 crypto instructions not built"
282 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
283 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
284 msg "clang, test T32 crypto instructions not built"
285 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
286 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
287 msg "clang, test aarch64 crypto instructions not built"
288 make -B library/../${BUILTIN_SRC_PATH}/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
289 not grep -E 'aes[a-z]+\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.o
290}
291
292support_build_sha_armce () {
293 # clang >= 4 is required to build with SHA extensions
294 [[ $(clang_version) -ge 4 ]]
295}
296
297component_build_sha_armce () {
298 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
299
300
301 # Test variations of SHA256 Armv8 crypto extensions
302 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
303 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
304 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
305 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
306 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
307 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
308
309
310 # test the deprecated form of the config option
311 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
312 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
313 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
314 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
315
316 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
317 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
318 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
319 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
320
321
322 # test the deprecated form of the config option
323 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
324 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
325 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
326 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
327 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
328 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
329
330
331 # examine the disassembly for presence of SHA instructions
332 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
333 scripts/config.py set ${opt}
334 msg "${opt} clang, test A32 crypto instructions built"
335 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
336 grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
337
338 msg "${opt} clang, test T32 crypto instructions built"
339 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
340 grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
341
342 msg "${opt} clang, test aarch64 crypto instructions built"
343 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
344 grep -E 'sha256[a-z0-9]+\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
345 scripts/config.py unset ${opt}
346 done
347
348
349 # examine the disassembly for absence of SHA instructions
350 msg "clang, test A32 crypto instructions not built"
351 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
352 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
353
354 msg "clang, test T32 crypto instructions not built"
355 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
356 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
357
358 msg "clang, test aarch64 crypto instructions not built"
359 make -B library/../${BUILTIN_SRC_PATH}/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
360 not grep -E 'sha256[a-z0-9]+\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.o
361}
362
Minos Galanakis8a980902024-07-26 17:41:03 +0100363component_build_zeroize_checks () {
364 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
365
366 scripts/config.py full
367
368 # Only compile - we're looking for sizeof-pointer-memaccess warnings
369 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
370}
371
Minos Galanakis07404d22024-08-01 11:44:57 +0100372component_build_arm_none_eabi_gcc () {
373 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
374 scripts/config.py baremetal
375 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
376
377 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
378 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
379 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
380 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
381}
382
383component_build_arm_linux_gnueabi_gcc_arm5vte () {
384 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
385 scripts/config.py baremetal
386 # Build for a target platform that's close to what Debian uses
387 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
388 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
389 # Build everything including programs, see for example
390 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
391 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
392
393 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
394 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
395 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
396 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
397}
398
399support_build_arm_linux_gnueabi_gcc_arm5vte () {
400 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
401}
402
403component_build_arm_none_eabi_gcc_arm5vte () {
404 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
405 scripts/config.py baremetal
406 # This is an imperfect substitute for
407 # component_build_arm_linux_gnueabi_gcc_arm5vte
408 # in case the gcc-arm-linux-gnueabi toolchain is not available
409 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
410
411 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
412 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
413 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
414 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
415}
416
417component_build_arm_none_eabi_gcc_m0plus () {
418 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
419 scripts/config.py baremetal_size
420 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
421
422 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
423 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
424 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
425 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
426 for lib in library/*.a; do
427 echo "$lib:"
428 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
429 done
430}
431
432component_build_arm_none_eabi_gcc_no_udbl_division () {
433 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
434 scripts/config.py baremetal
435 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
436 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
437 echo "Checking that software 64-bit division is not required"
438 not grep __aeabi_uldiv library/*.o
439 not grep __aeabi_uldiv ${PSA_CORE_PATH}/*.o
440 not grep __aeabi_uldiv ${BUILTIN_SRC_PATH}/*.o
441}
442
443component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
444 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
445 scripts/config.py baremetal
446 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
447 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
448 echo "Checking that software 64-bit multiplication is not required"
449 not grep __aeabi_lmul library/*.o
450 not grep __aeabi_lmul ${PSA_CORE_PATH}/*.o
451 not grep __aeabi_lmul ${BUILTIN_SRC_PATH}/*.o
452}
453
454component_build_arm_clang_thumb () {
455 # ~ 30s
456
457 scripts/config.py baremetal
458
459 msg "build: clang thumb 2, make"
460 make clean
461 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
462
463 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
464 msg "build: clang thumb 1 -O0, make"
465 make clean
466 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
467
468 msg "build: clang thumb 1 -Os, make"
469 make clean
470 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
471}
472
473component_build_armcc () {
474 msg "build: ARM Compiler 5"
475 scripts/config.py baremetal
476 # armc[56] don't support SHA-512 intrinsics
477 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
478
479 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
480 scripts/config.py unset MBEDTLS_AESCE_C
481
482 # Stop armclang warning about feature detection for A64_CRYPTO.
483 # With this enabled, the library does build correctly under armclang,
484 # but in baremetal builds (as tested here), feature detection is
485 # unavailable, and the user is notified via a #warning. So enabling
486 # this feature would prevent us from building with -Werror on
487 # armclang. Tracked in #7198.
488 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
489
490 scripts/config.py set MBEDTLS_HAVE_ASM
491
492 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
493
494 msg "size: ARM Compiler 5"
495 "$ARMC5_FROMELF" -z library/*.o
496 "$ARMC5_FROMELF" -z ${PSA_CORE_PATH}/*.o
497 "$ARMC5_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o
498
499 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
500
501 # ARM Compiler 6 - Target ARMv7-A
502 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
503
504 # ARM Compiler 6 - Target ARMv7-M
505 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
506
507 # ARM Compiler 6 - Target ARMv7-M+DSP
508 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
509
510 # ARM Compiler 6 - Target ARMv8-A - AArch32
511 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
512
513 # ARM Compiler 6 - Target ARMv8-M
514 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
515
516 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
517 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
518
519 # ARM Compiler 6 - Target Cortex-M0
520 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
521
522 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
523 #
524 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
525 # that we have in our CI
526 scripts/config.py set MBEDTLS_AESCE_C
527 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
528}
529
530support_build_armcc () {
531 armc5_cc="$ARMC5_BIN_DIR/armcc"
532 armc6_cc="$ARMC6_BIN_DIR/armclang"
533 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
534}