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
3
votes
2 answers
gcc LTO - shared library - Am I right?
Context :
Trying to understand how lto (link time compilation) works
Code:
I have those files :
julia.h:
#ifndef JULIA_H
#define JULIA_H
#include
int julian();
#endif // JULIA_H
julia.c :
#include "julia.h"
int julian()
{
…

Larry
- 1,735
- 1
- 18
- 46
3
votes
1 answer
Link Time Optimization conflicting with multithreading support
As I've read about improved link time optimization support in g++-4.9, I want to give it a try. Sadly, I get exceptions at run time, specifically std::system_errorwith e.what() == Enable multithreading to use std::thread: Operation not…

stefan
- 10,215
- 4
- 49
- 90
3
votes
2 answers
ARM + gcc: don't use one big .rodata section
I want to compile a program with gcc with link time optimization for an ARM processor. When I compile without LTO, the system gets compiled. When I enable LTO
(with -flto), I get the following assembler-error:
Error: invalid literal constant:…

user3035952
- 301
- 5
- 12
3
votes
0 answers
cross-TU optimization for a static library
Link-time optimizations are usually implemented by putting some IR into the object files instead of actual machine code. Thus when dealing with static libraries it's just a collection of such IR files and LTO has to be done every single time the…

Trass3r
- 5,858
- 2
- 30
- 45
3
votes
2 answers
Does GCC LTO perform cross-file dead code elimination?
Say I have a function
void do_something() {
//....
#ifdef FEATURE_X
feature_x();
#endif
//....
}
I can compile and run this with no problems; if I want the feature I can pass -D FEATURE_X and it works.
However, what if I…

zebediah49
- 7,467
- 1
- 33
- 50
2
votes
0 answers
clang support for fat-lto-objects
I have a project where I use -flto=thin for my main targets, but I don't want to apply LTO to my tests since it slows compilation down (full context: lld runs LTO even if -fno-lto is passed).
As it is suggested here, it is likely that if you compile…

Simone Rondelli
- 356
- 1
- 18
2
votes
1 answer
Enable LTO and check if LTO is used
I have been trying to enable LTO on some code I have, and am trying to figure out the instructions to do it. GCC is what I am using
I see some instructions mentioned…

Marcus White
- 41
- 1
- 6
2
votes
2 answers
Why does CMake set -no-fat-lto-objects when I enable LTO/IPO?
I'm enabling IPO (inter-procedural optimization) for a C compilation of mine, using CMake:
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
As expected, this causes an -flto compiler flag to be added. However, it also adds…

einpoklum
- 118,144
- 57
- 340
- 684
2
votes
0 answers
Compiling android kernel blocked on linking of vmlinux.o
I want to custom my pixel 4a kernel and following to instruction,
mkdir android-kernel && cd android-kernel
repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-redbull-4.19-android12
repo sync
build/build.sh
Unfortunately,…

sivandahan
- 71
- 5
2
votes
2 answers
How to solve: lto1: fatal error: bytecode stream in file '...' generated with LTO version 6.0 instead of the expected 7.1
I am trying to embed a simple (test) Python script into C++. See this question for reference: Undefined reference to `main` error when embedding Python in C++ I'm trying to embed Python in C++. This is my Python file (with the name…

Alexandre Vandermonde
- 579
- 1
- 6
- 13
2
votes
0 answers
LTO and overriding stdlib functions in static libraries
I have an embedded platform that brings its own stdlib functions like malloc and printf in a static library. I need to compile this library with LTO. Unfortunately in this combination (-flto + -nostdlib + linking with stdlib replacements from an .a)…

stefanct
- 2,503
- 1
- 28
- 32
2
votes
0 answers
Force LTO inlining
I have object files containing moderately sized functions (approximately 256 FLOPs each, no loops) that are called from a .c file. I would like to force the inlining of these functions during Link-Time Optimizations available on GCC (-flto), as they…

Harkonnen
- 41
- 3
2
votes
1 answer
What gets discarded by gcc's -flto?
I'm building our firmware for stm32 with arm-none-eabi-gcc 6.3.1.
If I enable link-time optimization, it still compiles and boots and is ~10kiB smaller than without -ftlo but there is some subtle breakage.
How can I debug this?
Is there a way to get…

user1273684
- 1,559
- 15
- 24
2
votes
0 answers
Does LLVM LTO(Link-time Optimization) have any impact on Objective-C codes?
AFAIK, LTO can reduce dead codes and do some cross-file inlining. However,
Objective-C is based on runtime. Whether a method is indeed called is resolved until runtime, so it's not possible to reduce dead methods in Objective-C at link time, right?…

Evan
- 430
- 6
- 16
2
votes
1 answer
Statically linked executable with LTO (link time optimization) : how to make it with previously built libraries
On Ubuntu with g++4.9, I have built a static library (call it libZeroMQ.a) following its instructions, and it was built without "-flto" (link time optimization).
Now I am working on a project (call it MyEXE) which uses libZeroMQ.a, and I'll…

user1084699
- 75
- 4