c++gcclinkerclanglto

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 with lto the object files will only contain the intermediate language and no binary code. Therefore the tests will always be linked with LTO

GCC has the fat-lto-objects option: "Fat LTO objects are object files that contain both the intermediate language and the object code. This makes them usable for both LTO linking and normal linking."


Solution

  • This was supposed to be released in Clang 17, https://llvm.org/docs/FatLTO.html

    https://www.phoronix.com/news/LLVM-Fat-LTO-Objects

    Confusingly, this LLVM ticket mentions it only comes out in LLVM 18. https://github.com/llvm/llvm-project/issues/55431#issuecomment-1694769726