You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Link Time Optimization (LTO) is a program memory usage optimization mechanism performed by compiler at link time. At compile timecompiler creates special intermediate representation 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.
3
+
Link Time Optimization (LTO) is a program memory usage optimization mechanism that the compiler performs at link time. At compile time, the compiler creates a special intermediate representation of all translation units. It then optimizes them as a single unit at link time, which uses less memory than non-LTO builds.
4
4
5
5
## Using LTO in Mbed OS
6
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.
7
+
The Mbed OS build system implements LTO as an optional profile extension in `tools\profiles\extensions\lto.json`. Enabling LTO amends the build profile with LTO flags. LTO performs heavy memory optimizations that break debugging, so we don't recommend enabling it in debug or develop profiles.
8
8
9
-
To enable LTO retype `--profile` option with LTO file path `tools\profiles\extensions\lto.json`
9
+
To enable LTO, retype the `--profile` option with LTO file path `tools\profiles\extensions\lto.json`.
10
10
11
-
<spanclass="notes">**Note**: For profile extensions you have to put full path relative to the project's root folder.</span>
11
+
<spanclass="notes">**Note**: For profile extensions you have to put the full path relative to the project's root folder.</span>
12
+
13
+
To enable LTO with the `release` profile:
12
14
13
-
To enable LTO together with `release` profile for MbedOS example :
<spanclass="notes">**Note**: In LTO buildscompiler produce bytecode/bitcode instead of regular object code. And it's hard to analyse this output by object code analysis tools.</span>
41
+
<spanclass="notes">**Note**: In LTO builds, the compiler produces bytecode/bitcode instead of regular object code. It's hard to analyze this output with object code analysis tools.</span>
42
42
43
43
## Limitations
44
44
45
45
- LTO slows down build process.
46
46
- It’s very hard to control memory placement when using LTO.
47
-
- LTO perform heavy memory optimizations what breaks debugging.
48
-
- In LTO buildscompiler produce bytecode/bitcode instead of regular object code. And it's hard to analyse this output with object code analysis tools.
49
-
- LTO could causes increases to the stack space needed due to cross-object inlining.
47
+
- LTO performs heavy memory optimizations that break debugging.
48
+
- In LTO builds, the compiler produce bytecode/bitcode instead of regular object code. It's hard to analyze this output with object code analysis tools.
49
+
- LTO could cause increases to the stack space needed due to cross-object inlining.
50
50
51
-
### ARM
51
+
### Arm
52
52
53
53
- No bitcode libraries: armlink only supports bitcode objects on the command line. It does not support bitcode objects coming from libraries. armlink gives an error message if it encounters a file containing bitcode while loading from a library.
54
54
- Partial Linking is not supported with LTO as it only works with elf objects not bitcode files.
@@ -57,10 +57,10 @@ LTO profile build results for [mbed-cloud-client-example](https://github.com/ARM
57
57
58
58
### IAR
59
59
60
-
- There is no LTO available for IAR compiler.
60
+
- There is no LTO available for the IAR compiler.
61
61
62
62
### GCC_ARM
63
63
64
-
- 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, e.g. a platformspecific error during the final link stage on Windows hosts with GCC8
65
-
- 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.
66
-
- There is a bug in all gcc versions causing that LTO removes C functions declared as weak in assembler (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966). MbedOS build system provides fix for this. In case of exporting MbedOS project to other buildsystem the problem will emerge. This can be fixed by changing the order of object files in the linker command. Objects providing the weak symbols and compiled from assembly must be listed before the objects providing the strong symbols.
64
+
- The minimal required version of `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, for example a platform-specific error during the final link stage on Windows hosts with GCC8.
65
+
- 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 `section ".section_name" will not fit in region "region_name"` type errors.
66
+
- There is a bug in all GCC versions causing that LTO removes C functions declared as weak in assembler (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966). The Mbed OS build system provides a fix for this. In case of exporting Mbed OS project to other build system the problem will emerge. This can be fixed by changing the order of object files in the linker command. Objects providing the weak symbols and compiled from assembly must be listed before the objects providing the strong symbols.
0 commit comments