Skip to the content.

triceConfig.h Project Image Size Optimization

1. Table of Contence

Table of Contents
    - [`triceConfig.h` Project Image Size Optimization](#triceconfigh-project-image-size-optimization) - [1. Table of Contence](#1-table-of-contence) - [2. Code Optimization `-o3` or `-oz` (if supported)](#2-code-optimization--o3-or--oz-if-supported) - [3. Compiler Independent Setting](#3-compiler-independent-setting) - [4. Linker Option `--split-sections` (if supported)](#4-linker-option---split-sections-if-supported) - [5. Linker Optimization `-flto` (if supported)](#5-linker-optimization--flto-if-supported) - [5.1. ARMCC compiler v5 "Linker Feedback"](#51-armcc-compiler-v5-linker-feedback) - [5.2. ARMCLANG compiler v6 "Link-Time Optimization"](#52-armclang-compiler-v6-link-time-optimization) - [5.3. GCC](#53-gcc) - [5.4. Other IDE´s and compilers](#54-other-ides-and-compilers) - [6. STM32F030 Example Project - Different Builds](#6-stm32f030-example-project---different-builds) - [6.1. ARMCC compiler v5](#61-armcc-compiler-v5)

You can reduce trice code size by different means.

2. Code Optimization -o3 or -oz (if supported)

3. Compiler Independent Setting

Maybe the following is a bit unhandy but it decreases the code amount, build time and the image size.

When having lots of program memory simply let all values be 1. With specific linker optimization unused functions can get stripped out automatically.

4. Linker Option --split-sections (if supported)

5. Linker Optimization -flto (if supported)

5.1. ARMCC compiler v5 “Linker Feedback”

5.3. GCC

With GCC use the -flto CLI switch directly.

LLVM ARM Clang

This compiler is much faster and creates the smallest images. Right now it uses the GCC libs and linker.

5.4. Other IDE´s and compilers

Please check the manuals and create a pull request or simply let me know.

6. STM32F030 Example Project - Different Builds

6.1. ARMCC compiler v5

Compiler Linker Result Comment
o0   Code=46942 RO-data=266 RW-data=176 ZI-data=4896 very big
o1   Code=22582 RO-data=258 RW-data=168 ZI-data=4896  
o3   Code=21646 RO-data=258 RW-data=168 ZI-data=4896  
o0 split sections Code= 7880 RO-data=268 RW-data=156 ZI-data=4892 for debugging
o1 split sections Code= 5404 RO-data=260 RW-data=148 ZI-data=4892 for debugging
o3 split sections Code= 4996 RO-data=260 RW-data=148 ZI-data=4892 good balance
o0 flto Code= 8150 RO-data=266 RW-data=176 ZI-data=4896 builds slower
o1 flto Code= 5210 RO-data=258 RW-data=148 ZI-data=4892 builds slower
o3 flto Code= 4818 RO-data=258 RW-data=148 ZI-data=4892 builds slower, smallest image