2.4.3. Link time optimization
Link time optimization (LTO) optimizes code across all translation units by using intermediate representation at link time. This results in smaller, faster executable files and libraries. LTO also analyzes source at compile time more thoroughly, improving GCC diagnostics for coding errors.
- Known issues
LTO has the following known issues:
Violating the One Definition Rule (ODR) produces a
-WodrwarningViolations of the ODR resulting in undefined behavior produce a
-Wodrwarning. This usually points to a bug in your program. The-Wodrwarning is enabled by default.LTO causes increased memory consumption
The compiler consumes more memory when it processes the translation units the program consists of. On systems with limited memory, disable LTO or lower the parallelism level when building your program.
GCC removes seemingly unused functions
GCC might remove functions it considers unused because the compiler is unable to recognize which symbols an asm() statement references. A compilation error might occur as a result. To prevent this, add
__attribute__((used))to the symbols you use in your program.Compiling with the
-fPICoption causes errorsBecause GCC does not parse the contents of asm() statements, compiling your code with the
-fPICcommand-line option can cause errors. To prevent this, use the-fno-ltooption when compiling your translation unit. More information is available at LTO FAQ {mdash}; Symbol usage from assembly language.Implementing symbol versioning by using the
.symverdirective in an asm() statement is not compatible with LTO. However, it is possible to implement symbol versioning using thesymverattribute. For example:__attribute__ ((_symver_ ("<symbol>@VERS_1"))) void <symbol>_v1 (void) { }