Link-Time Optimization
Subject: Computer and Technology noun /ˈlɪŋk.taɪm ˌɑːp.tɪ.məˈzeɪ.ʃən/ 1 definition
- compiler-design
- compiler-optimization
- systems-programming
- software-performance
-
Definition (noun)
Entry #274 · UpdatedLink-Time Optimization (LTO) is a compiler optimization technique that defers final optimization and machine-code generation until the linking stage, giving the optimizer visibility across an entire program rather than a single source file. Instead of lowering each translation unit to standalone native instructions in isolation, the compiler stores Intermediate Representation (IR)—such as LLVM bitcode or GCC GIMPLE—inside object files so the toolchain can analyze all linked modules together. With this unified view of the program's call graph and symbol table, the optimizer executes interprocedural passes across file boundaries—including cross-module function inlining, dead-code elimination, devirtualization, and global constant propagation—before generating target binaries. By removing the optimization barrier imposed by separate compilation, LTO improves runtime performance and shrinks binary size, though whole-program analysis increases link-phase memory consumption and incremental build times unless partitioned.
Common Forms
Full (Monolithic) LTO: Merges the intermediate representation of all linked translation units into a single unified module for whole-program analysis and code generation, maximizing optimization depth at the cost of high peak memory usage and slower linking.
ThinLTO (Scalable Parallel LTO): Computes compact cross-module summary indices during compilation so each module can selectively import external callees and run optimization and code generation in parallel across CPU cores or build caches, sharply reducing link latency and RAM usage.
Fat LTO Objects: Embeds both intermediate representation bitcode and precompiled native machine code inside the same object file or static archive, allowing standard non-LTO linkers to fall back to native sections while LTO-enabled builds consume the IR.
Cross-Language LTO: Aligns IR formats and ABI metadata across compatible compiler frontends—such as Clang for C/C++ and
rustcfor Rust sharing an LLVM backend—enabling the linker to inline and optimize directly across foreign-function interfaces.
Example
A C++ audio-processing engine compiles
dsp_filter.cppandmain.cppseparately withclang++ -O2 -flto=thin -c, writing LLVM bitcode intodsp_filter.oandmain.oinstead of finalized x86-64 machine code. When the final link runsclang++ -flto=thin -fuse-ld=lld main.o dsp_filter.o -o engine, thelldThinLTO backend reads the summary index, imports and inlinesapply_biquad()directly into the hot sample loop inmain.o, and propagates constant filter coefficients to enable SIMD vectorization and eliminate call-frame overhead.