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
11
votes
1 answer
undefined reference cross compiling static libraries with LTO under GCC
I am attempting to use GCC 4.9.2 to cross compile an application from Linux (x86_64-pc-linux-gnu) for Windows (x86_64-w64-mingw32).
When building targets that link against static libraries and also using link-time optimisation I get undefined…

dcro
- 161
- 2
- 5
10
votes
1 answer
How to detect code compiled with LTO?
Exist any way to detect if code is compiled with -flto?
Example is classic library or executable under Linux compiled with GCC (4.9.1), without debugging.

okias
- 386
- 2
- 9
9
votes
2 answers
INTERPROCEDURAL_OPTIMIZATION not set even if check_ipo_supported() works in CMake
I've the following project in CMake 3.14.0, that builds a project for Visual Studio 2017 64 bit generator (minimum version is 3.10.0 because other developer can have previous versions of CMake, but greater than 3.9.0):
cmake_minimum_required…

Jepessen
- 11,744
- 14
- 82
- 149
8
votes
1 answer
Why are my C++ binary built with -LTO so very large?
I'm compiling some binaries on Mac, but the compiled size has become huge with more recent compiler (up to ~20MB from ~5MB before). I think it's related to LTO (link time optimization) that was not activated before. I do not observe this file bloat…

Yann TM
- 1,942
- 13
- 22
8
votes
1 answer
Replacing __aeabi_dsub to save space (-flto issues)
I'm trying to cram a lot of code into a reasonably small ARM microcontroller. I've done a massive amount of work on size optimisation already, and I'm down to the point where I need double arithmetic, but __aeabi_ddiv, __aeabi_dadd and __aeabi_dsub…

Gordon Williams
- 1,856
- 1
- 17
- 31
8
votes
1 answer
Suppress -Wlto-type-mismatch warning for struct with flexible array
I'm doing a gcc compile with -Wlto-type-mismatch and -Werror set (for the good of the rest of the project). I have an extern struct with a flexible array that is provoking an lto-type-mismatch warning/error.
Here's the code distilled down to an…

Dan Halbert
- 2,761
- 3
- 25
- 28
7
votes
1 answer
LTO optimizing out global variables
I am seeing LTO optimize some global objects out from a TU if there are no functions in that TU that are being explicitly from another TU.
The following excerpt attempts to describe the key classes and files involved (please note that it's just for…

Virag Doshi
- 109
- 4
7
votes
0 answers
g++ 7 with -flto and -std=c++17 results in segmentation fault (aborted with core dumped)
Code:
#include
#include
#include
int main(int argc, char *argv[]) {
std::string filename = "dummyfile";
std::ifstream infile(filename);
std::string line;
std::getline(infile, line);
return…

narengi
- 1,345
- 3
- 17
- 38
7
votes
3 answers
How to combine LTO with symbol versioning
I would like to compile a shared library using both symbol versioning and link-time optimization (LTO). However, as soon as I turn on LTO, some of the exported symbols vanish. Here is a minimal example:
Start by defining two implementations of a…

Nikratio
- 2,338
- 2
- 29
- 43
6
votes
3 answers
gcc LTO: Limit scope of optimization
An LTO build of a rather large shared library (many template instantiations) takes rather long (>10min). Now I know a few things about the library, and could specify some kind of "blacklist" in the form of object files that do not need to be…

Martin Richtarsky
- 619
- 7
- 18
6
votes
0 answers
binutils and gcc with LTO
I have binutils-2.25.1 installed to /usr/local/binutils-2.25.1, configured with
../configure --prefix=/usr/local/binutils-2.25.1 --enable-plugins --enable-gold --disable-werror
And I want to build RPM package - gcc with LTO support that uses linker…

artshmelev
- 61
- 1
- 5
6
votes
2 answers
How well do compilers (with link-time optimization) cope with functions that return quickly (early-out paths)?
In C, if I have a function call that looks like
// main.c
...
do_work_on_object(object, arg1, arg2);
...
// object.c
void do_work_on_object(struct object_t *object, int arg1, int arg2)
{
if(object == NULL)
{
return;
}
// do lots of…

mabraham
- 2,806
- 3
- 28
- 25
5
votes
1 answer
lld runs LTO even if -fno-lto is passed
I have a CMake project with several subprojects that create static libraries built with -flto=thin.
The project has a lot of tests that are linked against the aforementioned libraries. With LTO it takes a lot of time to build tests, therefore I have…

Simone Rondelli
- 356
- 1
- 18
5
votes
1 answer
No need to define functions in header files for inlining?
In order for the compiler to inline a function call, it needs to have the full definition. If the function is not defined in the header file, the compiler only has the declaration and cannot inline the function even if it wanted to.
Therefore, I…

Magnar Myrtveit
- 2,432
- 3
- 30
- 51
5
votes
0 answers
Extracting LLVM bitcode embedded using `-lto-embed-bitcode`
Goal: Extract full-program (merged) post-LTO bitcode from an ELF binary.
The program happens to be written in Rust, but I don't think that's a crucial detail.
I'm able to compile a Rust program into an ELF binary with a .llvmbc section using the…

Edd Barrett
- 3,425
- 2
- 29
- 48