LTO abbreviates Link-Time Optimization. LTO is a phase of optimization applied to a compiled program at the linkage step, with the advantage that all of the compiled object files comprising the program can then be analysed together. Conventional optimization is performed by the compiler alone, which can generate and optimize only one object file at a time.
Questions tagged [lto]
156 questions
4
votes
2 answers
Size optimization options
I am trying to sort out an embedded project where the developers took the option of including all the h and c files into a c file, then they can compile just that one file with the -whole-program option to get good size optimization.
I hate this and…

Chris Aaaaa
- 167
- 1
- 8
4
votes
1 answer
DLL linking failed with LTO using MinGW-W64
I failed to build a shared library for Windows x86-64 using MinGW-W64 with -flto. Here is what I get (compilation is done on a Linux box):
# ...
x86_64-w64-mingw32-g++ -c -std=gnu++11 -fvisibility=hidden -DGLEW_STATIC -Ofast -flto -frtti -pedantic…

lesenk
- 793
- 1
- 8
- 22
4
votes
2 answers
Building Chromium, WebRTC without LTO
I'm on Arch Linux x86_64, attempting to build the WebRTC libraries. I get compile errors when I do:
[ghilliard@diadem trunk]$ ninja -C out/Release peerconnection_server
ninja: Entering directory `out/Release'
[1/1] LINK…

George Hilliard
- 15,402
- 9
- 58
- 96
3
votes
0 answers
GCC with LTO: Warning: argument 1 value ‘18...615’ (SIZE_MAX) exceeds maximum object size
I learnt recently about Link Time Optimizations in a C++ Weekly episode. I thought using LTO in my code would be a good idea, so I decided to use the flags -flto and -fno-fat-lto-objects. Unfortunately I started getting this…

Lluís Alemany-Puig
- 672
- 3
- 23
3
votes
2 answers
Link-time optimizations in CUDA 11 - what are they and how to use them?
The CUDA 11 features announcement, it's said that there are now:
New link time optimization capabilities
what link-time optimizations does nvcc actually employ (e.g. relative to the LTO capabilities in host-side code with g++ or clang++)?
Also -…

einpoklum
- 118,144
- 57
- 340
- 684
3
votes
2 answers
How to prevent GCC from inserting memset during link-time optimization?
While developping a bare metal firmware in C for a RV32IM target (RISC-V), I encountered a linking error when LTO is enabled:
/home/duranda/riscv/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld:…

DurandA
- 1,095
- 1
- 17
- 35
3
votes
0 answers
gcc 9.2: spurious -Wuninitialized
I am trying to build our code base with gcc 9.2.0, but when using -flto, I get a dozen warnings with missing information.
These issues did not arise with gcc6.3.
: In member function ‘__ct_base ’:
: error: is used…

Julien Vivenot
- 2,230
- 13
- 17
3
votes
0 answers
Using LTO causes undefined reference to std::basic_string destructor
Decided to try LTO in my build (CentOS 7, CMake 3.14.3, gcc 8.2.1, -std=c++17):
# this adds "-flto -fno-fat-lto-objects"
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
All projects build fine, with exception of…

C.M.
- 3,071
- 1
- 14
- 33
3
votes
1 answer
Incorrect output of `nm` on GCC LTO fat object files
If I have tmp.c:
char constantFOO[0x12];
char constantBAR[0x34];
I see gcc -c tmp.c -o tmp.o && nm tmp.o shows
0000000000000034 C constantBAR
0000000000000012 C constantFOO
But if I compile with -flto -ffat-lto-objects, nm outputs zeros for the…

jberryman
- 16,334
- 5
- 42
- 83
3
votes
1 answer
Are multiple source files being passed to gcc treated as a single translation unit?
I think I've read that compiling multiple files with gcc at the same time would achieve the same thing as adding all sources into a single source file, as per Single Compilation Unit, but I can't find any sources on that anymore. Is that true?
We…

Spidey
- 2,508
- 2
- 28
- 38
3
votes
0 answers
C++ ODR Warning with lto enabled using nested structs
After enabling lto in one of my projects the compiler started to throw warnings for lto violations at me.
After a bit of testing it boils down to this construct.
typedef struct {
typedef struct {
} test_t;
std::vector t;
}…

Thalhammer
- 285
- 3
- 7
3
votes
1 answer
How to use GCC LTO with differently optimized object files?
I'm compiling an executable with arm-none-eabi-gcc for a Cortex-M4 based microcontroller. Non-performance-critical code is compiled with -Os (optimized for executable code size) and performance critical parts with another optimalization flags, eg.…

Venemo
- 18,515
- 13
- 84
- 125
3
votes
1 answer
Get llvm IR after lto linking
Is there any way to get llvm IR after linking for lto? For example I have the following line:
$ clang -flto -O2 a.c main.c -fuse-ld=gold -v -save-temps
So I want to get llvm IR where file a.c and file main.c are linked in one monlithic.bc (or…

alexanius
- 402
- 2
- 11
3
votes
1 answer
CMake, static library and link time optimization
I'm trying to create static library with link time optimization using cmake and g++.
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -pedantic -std=c++11"
)
if (CMAKE_COMPILER_IS_GNUCXX)
set(
…

graywolf
- 7,092
- 7
- 53
- 77
3
votes
1 answer
LTO optimizations negative effects and find best solution
I have MCU with flash memory breaked in sections(as usual).
Linker places .struct_init, .struct_init_const, .struct_not_init sections to addresses belongs to flash memory section20. It is hardcoded in linker script.
Consider following test…

sigmaN
- 187
- 9