Lto with GCC compiled code

Hello, I have some Rust code written as a static library and compiled using llvm, and C code, that is compiled using gcc. Then it all is linked with gcc. I have fat lto enabled for Rust, but it obviously does not interact with C code. Is it possible to lto both Rust and C sources? Compiling C with llvm is an option, but I want to investigate this route of using gcc. Can you advise something?

LTO requires all code being compiled with the same compiler framework. You can't mix GCC and LLVM compiled object files with LTO. As such you either have to use clang for compiling the C code or use the experimental GCC backend for rustc. I don't know if it supports linker plugin LTO yet. It requires nightly rustc. Instructions on how to build it can be found at GitHub - rust-lang/rustc_codegen_gcc: libgccjit AOT codegen for rustc If you are on x86_64 linux you can use the provided to compile against, if not you will have to build libgccjit too, which can take an hour or so if I understand correctly.