From 120f29deef25846e8e36cab930fa9229be1c598c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 1 Sep 2021 19:51:19 +0200 Subject: [PATCH 1/2] New configuration preset baremetal_size The baremetal configuration includes debugging features whose size is not particularly interesting. Create a new preset for use when benchmarking code size which excludes debugging features that increase the size of non-debugging modules. Signed-off-by: Gilles Peskine --- scripts/config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/config.py b/scripts/config.py index 6d5edc7c0..85f38ef42 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -272,6 +272,21 @@ def baremetal_adapter(name, active, section): return True return include_in_full(name) and keep_in_baremetal(name) +# This set contains options that are mostly for debugging or test purposes, +# and therefore should be excluded when doing code size measurements. +# Options that are their own module (such as MBEDTLS_ERROR_C) are not listed +# and therefore will be included when doing code size measurements. +EXCLUDE_FOR_SIZE = frozenset([ + 'MBEDTLS_DEBUG_C', # large code size increase in TLS + 'MBEDTLS_SELF_TEST', # increases the size of many modules + 'MBEDTLS_TEST_HOOKS', # only useful with the hosted test framework, increases code size +]) + +def baremetal_size_adapter(name, active, section): + if name in EXCLUDE_FOR_SIZE: + return False + return baremetal_adapter(name, active, section) + def include_in_crypto(name): """Rules for symbols in a crypto configuration.""" if name.startswith('MBEDTLS_X509_') or \ @@ -484,6 +499,9 @@ if __name__ == '__main__': add_adapter('baremetal', baremetal_adapter, """Like full, but exclude features that require platform features such as file input-output.""") + add_adapter('baremetal_size', baremetal_size_adapter, + """Like baremetal, but exclude debugging features. + Useful for code size measurements.""") add_adapter('full', full_adapter, """Uncomment most features. Exclude alternative implementations and platform support From e36fe81e34b701a089262bb3cbdeb284ea08c86f Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 1 Sep 2021 20:00:33 +0200 Subject: [PATCH 2/2] Change our code size reference job to use baremetal_size In build_arm_none_eabi_gcc_m0plus, use baremetal_size instead of baremetal as the configuration, i.e. exclude debugging features. This job is the only one switching to baremetal_size because it's our primary point of reference for code size evolution, and which is the only job where we display the code size built with -Os so it's presumably the only job for which we really care about a meaningful code size report. Signed-off-by: Gilles Peskine --- tests/scripts/all.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index a664df219..6d24147d6 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -2366,16 +2366,16 @@ component_test_no_x509_info () { } component_build_arm_none_eabi_gcc () { - msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s + msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s scripts/config.py baremetal 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 - msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" + msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o } component_build_arm_linux_gnueabi_gcc_arm5vte () { - msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s + msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s scripts/config.py baremetal # Build for a target platform that's close to what Debian uses # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort). @@ -2384,7 +2384,7 @@ component_build_arm_linux_gnueabi_gcc_arm5vte () { # https://github.com/ARMmbed/mbedtls/pull/3449#issuecomment-675313720 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' - msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1" + msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug" ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o } support_build_arm_linux_gnueabi_gcc_arm5vte () { @@ -2392,23 +2392,23 @@ support_build_arm_linux_gnueabi_gcc_arm5vte () { } component_build_arm_none_eabi_gcc_arm5vte () { - msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s + msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s scripts/config.py baremetal # This is an imperfect substitute for # component_build_arm_linux_gnueabi_gcc_arm5vte # in case the gcc-arm-linux-gnueabi toolchain is not available 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 - msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1" + msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug" ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o } component_build_arm_none_eabi_gcc_m0plus () { - msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s - scripts/config.py baremetal + msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s + scripts/config.py baremetal_size 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 - msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os" + msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size" ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o }