quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

components-compiler.sh (6920B)


      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 
      6 # This file contains test components that are executed by all.sh
      7 
      8 ################################################################
      9 #### Compiler Testing
     10 ################################################################
     11 
     12 support_build_tfm_armcc () {
     13     support_build_armcc
     14 }
     15 
     16 component_build_tfm_armcc () {
     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     helper_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../framework/tests/include/spe"
     22 }
     23 
     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" -O2
     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 # Prepare for a non-regression for https://github.com/Mbed-TLS/mbedtls/issues/9814 :
     76 # test with GCC 15.
     77 # Eventually, $GCC_LATEST will be GCC 15 or above, and we can remove this
     78 # separate component.
     79 # For the time being, we don't make $GCC_LATEST be GCC 15 on the CI
     80 # platform, because that would break branches where #9814 isn't fixed yet.
     81 support_test_gcc15_drivers_opt () {
     82     if type gcc-15 >/dev/null 2>/dev/null; then
     83         GCC_15=gcc-15
     84     elif [ -x /usr/local/gcc-15/bin/gcc-15 ]; then
     85         GCC_15=/usr/local/gcc-15/bin/gcc-15
     86     else
     87         return 1
     88     fi
     89 }
     90 component_test_gcc15_drivers_opt () {
     91     msg "build: GCC 15: full + test drivers dispatching to builtins"
     92     scripts/config.py full
     93     scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
     94     loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
     95     loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
     96     loc_cflags="${loc_cflags} -I../framework/tests/include -O2"
     97     # Allow a warning that we don't yet comply to.
     98     # https://github.com/Mbed-TLS/mbedtls/issues/9944
     99     loc_cflags="${loc_cflags} -Wno-error=unterminated-string-initialization"
    100 
    101     make CC=$GCC_15 CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
    102 
    103     msg "test: GCC 15: full + test drivers dispatching to builtins"
    104     make test
    105 }
    106 
    107 component_test_gcc_earliest_opt () {
    108     scripts/config.py full
    109     test_build_opt 'full config' "$GCC_EARLIEST" -O2
    110 }
    111 
    112 support_test_gcc_earliest_opt () {
    113     type "$GCC_EARLIEST" >/dev/null 2>/dev/null
    114 }
    115 
    116 component_build_mingw () {
    117     msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
    118     make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs
    119 
    120     # note Make tests only builds the tests, but doesn't run them
    121     make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests
    122     make WINDOWS_BUILD=1 clean
    123 
    124     msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
    125     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
    126     make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 tests
    127     make WINDOWS_BUILD=1 clean
    128 
    129     msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
    130     ./scripts/config.py unset MBEDTLS_AESNI_C #
    131     make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
    132     make WINDOWS_BUILD=1 clean
    133 }
    134 
    135 support_build_mingw () {
    136     case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
    137         [0-5]*|"") false;;
    138         *) true;;
    139     esac
    140 }
    141 
    142 component_build_zeroize_checks () {
    143     msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
    144 
    145     scripts/config.py full
    146 
    147     # Only compile - we're looking for sizeof-pointer-memaccess warnings
    148     make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
    149 }
    150 
    151 component_test_zeroize () {
    152     # Test that the function mbedtls_platform_zeroize() is not optimized away by
    153     # different combinations of compilers and optimization flags by using an
    154     # auxiliary GDB script. Unfortunately, GDB does not return error values to the
    155     # system in all cases that the script fails, so we must manually search the
    156     # output to check whether the pass string is present and no failure strings
    157     # were printed.
    158 
    159     # Don't try to disable ASLR. We don't care about ASLR here. We do care
    160     # about a spurious message if Gdb tries and fails, so suppress that.
    161     gdb_disable_aslr=
    162     if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
    163         gdb_disable_aslr='set disable-randomization off'
    164     fi
    165 
    166     for optimization_flag in -O2 -O3 -Ofast -Os; do
    167         for compiler in clang gcc; do
    168             msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
    169             make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
    170             gdb -ex "$gdb_disable_aslr" -x $FRAMEWORK/tests/programs/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
    171             grep "The buffer was correctly zeroized" test_zeroize.log
    172             not grep -i "error" test_zeroize.log
    173             rm -f test_zeroize.log
    174             make clean
    175         done
    176     done
    177 }