How exactly does the Rust compiler compile LLVM modules to object files/executables?

I understand that the Rust compiler uses LLVM as its backend by default, and I've read some of the code in rustc_codegen_ssa and rustc_codegen_llvm, but I still don't fully understand how the compiler converts LLVM modules to actual executables.

Is it generating object files using write_output_file and then invoking some system linker separately or is something else happening? I'm mostly asking because I'm building my own toy programming language using Rust and LLVM and I'm trying to figure out how to convert the LLVM module into an executable (or at least an object file that I can link) from inside my compiler rather than just dumping LLVM IR to a file and leaving it to the user to create the executable using some external tool like Clang.

Also cross-posted on r/rust.

1 Like