Antoyo's Blog

submited by
Style Pass
2021-05-23 21:00:01

rustc_codegen_gcc is a shared library that can be loaded by the Rust compiler to replace the code generation done by LLVM by another code generator: in this case, it generates code using GCC or, more precisely, its library libgccjit. Despite its name, libgccjit can generate code ahead-of-time (aot) too.

This is very exiting that we can do this because it will allow us to generate code for architectures that are not supported by LLVM. Also, it will be nice to see the difference in performance, both in terms of compile time, but also in terms of run-time of the generated binaries.

Recently, rustc_codegen_gcc was improved enough that it can now run the tests of libcore. This is a very important milestone as it means that rustc_codegen_gcc can compile and run correctly programs of medium complexity. Moreover, it will allow me to see more easily what bugs need to be fixed.

In order to reach this milestone, multiple features needed to be added to libgccjit. I had to write as much as 7 gcc patches that needs to be applied to upstream gcc in order to run this GCC codegen for Rust. Among other things, support was added for thread-local-storage variables, specifying the link section of a variable, sized integer types (including 128-bit integers). Also a reflection API was added and a few bugs were fixed.

Leave a Comment