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