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
51
votes
4 answers
How do I enable link time optimization (LTO) with CMake?
I have the most recent cmake build and trying all build configurations (Debug, MinSizeRel, RelWithDebugInfo, Release, General) I see nowhere (text search) in generated makefiles the string -lto, so or the functionality is still not present, or it…

CoffeDeveloper
- 7,961
- 3
- 35
- 69
48
votes
2 answers
What information does GCC Profile Guided Optimization (PGO) collect and which optimizations use it?
Which information does GCC collect when I enable -fprofile-generate and which optimization does in fact uses the collected information (when setting the -fprofile-use flag) ?
I need citations here. I've searched for a while but didn't found anything…

JohnTortugo
- 6,356
- 7
- 36
- 69
34
votes
2 answers
Using GCC's link-time optimization with static linked libraries
I'm trying to use link-time optimizations with the -flto flag of GCC (6.1.1).
While it works fine with my code, it doesn't link with a static linked library I'm also building and linking with my project (which is Engine and the library is…

CpCd0y
- 640
- 1
- 8
- 17
25
votes
3 answers
LTO with LLVM and CMake
I am trying to apply Link Time Optimization with LLVM on a CMake Project, that creates a shared library. My question is pretty much the same as this one:
Switching between GCC and Clang/LLVM using CMake.
However, the answers do not seem to be…

SPMP
- 1,181
- 1
- 9
- 24
24
votes
2 answers
How can I use lto with static libraries?
When I try to build static libraries with -flto, I get undefined reference errors:
library.cpp:
#include
void foo() {
std::cout << "Test!" << std::endl;
}
main.cpp:
void foo();
int main() {
foo();
return 0;
}
Compilation…

Tavian Barnes
- 12,477
- 4
- 45
- 118
23
votes
2 answers
Why does using LTO increase the size of my Rust binary?
Introduction
I finished a small Rust project (about 300 lines of code) with the following dependencies:
rumqtt
signal
log
env_logger
Problem
When using cargo build --release without further configuration, a 2.942.744 bytes (= 2,8 MiB) binary is…

PEAR
- 685
- 3
- 10
- 20
21
votes
2 answers
What is the difference in gcc between lto and fat-lto-objects
I have tried to compile to assembler my source code with next flags:
1. -flto
2. -flto -ffat-lto-objects
3. -flto -fno-fat-lto-objects
Third one provides optimized slim LTO code as written in documentation, but I don't see any difference in the…

Laser
- 6,652
- 8
- 54
- 85
20
votes
1 answer
What is GCC lto wrapper?
I am using buildroot to prepare images for embedded system. I want to export buildroots internal cross compiler so others can use same version, After command checking GCC version: arm-linux-gcc -vI see configured COLLECT_LTO_WRAPPER to static…

Mihalko
- 563
- 2
- 5
- 14
17
votes
1 answer
Clang link-time optimization doesn't work properly on Fedora 18
I'm a newcomer to clang, so it's likely I'm doing something silly. But I've spent several hours looking for solutions, including searching here, where I haven't found questions addressing -flto with distro-provided packages. The detail of this…

SnoopyLane
- 189
- 1
- 6
16
votes
1 answer
Requirements to use flto
If I want to compile my project with -flto is it enough to have built gcc with --enable-gold or do I also need to build gold and replace ld with it? And do I need any other flags? Ie I'm doing this
gcc -flto one.c two.c

chew socks
- 1,406
- 2
- 17
- 37
15
votes
1 answer
Getting assember output from GCC/Clang in LTO mode
Normally, one can get GCC's optimized assembler output from a source file using the -S flag in GCC and Clang, as in the following example.
gcc -O3 -S -c -o foo.s foo.c
But suppose I compile all of my source files using -O3 -flto to enable link-time…

Mona the Monad
- 2,265
- 3
- 19
- 30
15
votes
3 answers
gcc LTO appears to strip debugging symbols
I have project, running on an ARM Cortex-M4 processor, where I'm trying to include the gcc link-time optimization (LTO) feature.
Currently my compilation and linking flags are:
CFLAGS = -ggdb -ffunction-sections -Og
LDFLAGS =…

swineone
- 2,296
- 1
- 18
- 32
14
votes
1 answer
Mingw x64 Windows: plugin needed to handle lto object
When I'm trying to compile my project with 64-bit mingw (x86_64-5.1.0-posix-seh-rt_v4-rev0) I got messages:
BFD: my/project/dir/filename.cpp.obj: plugin needed to handle lto object
for each source file. Yet when I compile with 32-bit…

EvgeniyZh
- 898
- 9
- 21
12
votes
3 answers
How to write a custom intermodular pass in LLVM?
I've written a standard Analysis pass in LLVM, by extending the FunctionPass class. Everything seems to make sense.
Now what I'd like to do is write a couple of intermodular passes, that is, passes that allows me to analyze more than one module at a…

stepthom
- 1,432
- 2
- 16
- 27
11
votes
4 answers
Prevent GCC LTO from deleting function
I work with GCC-ARM-Embedded and FreeRTOS.
FreeRTOS has the function vTaskSwitchContext() which is used only in some
inline assembler code.
The problem is: When I use LTO, GCC does not consider the inline assembler code and thinks the function is…

Jan Hieber
- 145
- 1
- 8