Skip to content

Commit 26a37d3

Browse files
LTO documentation
1 parent 5b2e1f8 commit 26a37d3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Link Time Optimization
2+
3+
Link Time Optimization (LTO) is a program memory usage optimization mechanism performed by compiler at link time. At compile time compiler creates special intermediate represention of all translation units and then optimize them as a single unit at link time resulting in much better optimization comparing to non-LTO builds.
4+
5+
## Using LTO in Mbed OS
6+
7+
In Mbed OS build system LTO is implemented as an optional profile extension placed in `tools\profiles\extensions\lto.json`. When enabled, build profile is amended with LTO flags. LTO perform heavy memory optimizations what breaks debugging, so it's not recommended to enable it in debug/develop profiles.
8+
9+
To enable LTO retype `--profile` option with LTO file path `tools\profiles\extensions\lto.json`
10+
11+
<span class="notes">**Note**: For profile extensions you have to put full path relative to Mbed OS root folder.</span>
12+
13+
To enable LTO together with `release` profile:
14+
```
15+
mbed compile -t TOOLCHAIN -m TARGET --profile release --profile tools/profiles/extensions/lto.json
16+
```
17+
18+
<span class="notes">**Note**: In LTO builds compiler produce bytecode/bitcode instead of regular object code. And it's hard to analyse this output by object code analysis tools.</span>
19+
20+
## Limitations
21+
22+
### IAR
23+
24+
- There is no LTO available for IAR compiler.
25+
26+
### GCC_ARM
27+
28+
- The minimal required version of the `GCC_ARM` is now the GNU Arm Embedded Toolchain Version 9-2019-q4-major. Earlier `GCC_ARM` versions can cause various issues when the `-flto` flag is used.
29+
- The `noinline` attribute has to be used for every function that must be placed into a specific section (specified with a `section(".section_name")` attribute). In general, when a function is considered for inlining, the `section` attribute is always ignored. However, with the link-time optimizer enabled, the chances for inlining are much higher because the inliner works across multiple translation units. As a result, the output sections' sizes change compared to a non-lto build. `This may lead to a section ".section_name" will not fit in region "region_name"` type errors.

0 commit comments

Comments
 (0)