How Link-Time Optimization (LTO) breaks the translation unit compilation boundary:
Normally, the compiler cannot inline functions defined in util.cpp when compiling main.cpp because translation units are isolated.
Full LTO vs ThinLTO:
- Full LTO (
-flto): Emits LLVM bitcode instead of machine code, merges entire project into one giant module at link time. Slower compilation, maximum inlining. - ThinLTO (
-flto=thin): Generates lightweight function summaries and imports only required functions across modules concurrently. Scales to million-line projects with 95% of full LTO speedups!