Mbed-TLS / mbedtls

An open source, portable, easy to use, readable and flexible TLS library, and reference implementation of the PSA Cryptography API. Releases are on a varying cadence, typically around 3 - 6 months between releases.
https://www.trustedfirmware.org/projects/mbed-tls/
Other
5.54k stars 2.6k forks source link

Code Size Optimisation: Epic Summary (23Q2) #7358

Open tom-cosgrove-arm opened 1 year ago

tom-cosgrove-arm commented 1 year ago

Summary of Requirements

Epic Summary

Note: we refer to "code size" throughout, but are including the size of initialised data, i.e. the total flash memory required

Useful Information

We primarily care about Armv8-M or Armv8.1-M (Thumb and Thumb-2 instructions, not Aarch64/A64). TF-M takes measurements for an521 platform, i.e. Cortex-M33, so that's what we will use.

We care about the TF-M SMALL and MEDIUM configurations.

Compiler options should be -Os, as used by TF-M. (Ask them about -Oz)

Target compiler is Armclang v6.19 with (TF-M) build type MinSizeRel.

For changes that are size/performance trade-offs, this needs to be documented as part of any pull request, and the performance reduction included in the review.

The TF-M v1.70 release notes with sizes of Mbed TLS libmbedcrypto are at https://tf-m-user-guide.trustedfirmware.org/releases/1.7.0.html

Kanban to track progress: https://github.com/orgs/Mbed-TLS/projects/7

Building TF-M

$ git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git

$ cd trusted-firmware-m

$ mkdir build && cd build

$ /usr/local/ArmCompilerforEmbedded6.19/bin/suite_exec $SHELL

$ cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake -DTFM_PROFILE=profile_medium -DCMAKE_BUILD_TYPE=MinSizeRel -DTEST_S=ON -DTEST_NS=ON

$ cmake --build .
tom-cosgrove-arm commented 1 year ago

Compiler options should be -Os, as used by TF-M. (Ask them about -Oz)

TF-M uses MinSizeRel for which the default optimisation level is -Os.

On ArmClang they have modified MinSizeRel to use -Oz, but with gcc still use -Os (gcc11 doesn't support -Oz - gcc12 will, but he highest version of gcc supported by TF-M is 11.3.1)

@dave-rodgman @tom-daubney-arm @yanrayw ^