IT lexicon › Programming › Cross-language LTO

Cross-language LTO

Programming På svenska → Updated: 2026-11-06

Link-time optimization across the language boundary, so a Rust function can be inlined into C++ code and vice versa.

Rust and Clang are both built on LLVM. With ordinary LTO each language is optimised on its own, and a call from C++ into Rust stays a call through the C ABI no matter how trivial the function. If both compilers instead leave LLVM bitcode in their object files, the linker's LTO plugin can treat the whole program as one IR and inline across the seam. In rustc it is switched on with -Clinker-plugin-lto.

Firefox, which mixes Rust and C++ at a fine grain, pushed for it and turned it on in 2019. The catch is version coupling: rustc and Clang must use compatible LLVM versions, or the linker can't read the bitcode. Toolchains therefore have to be upgraded in lockstep, which is easier for a browser with its own build environment than for an ordinary Linux distribution.

← Back to the lexicon