Slashdot reader sleeping cat shares a recent FOSDEM talk by a compiler engineer on the team building Rust-GCC, “an alternative compiler implementation for the Rust programming language.”
“If gccrs interprets a program differently from rustc, this is considered a bug,” explains the project’s FAQ on GitHub.
The FAQ also notes that LLVM’s set of compiler technologies — which Rust uses — “is missing some backends that GCC supports, so a gccrs implementation can fill in the gaps for use in embedded development.” But the FAQ also highlights another potential benefit:
With the recent announcement of Rust being allowed into the Linux Kernel codebase, an interesting security implication has been highlighted by Open Source Security, inc. When code is compiled and uses Link Time Optimization (LTO), GCC emits GIMPLE [an intermediate representation] directly into a section of each object file, and LLVM does something similar with its own bytecode. If mixing rustc-compiled code and GCC-built code in the Linux kernel, the compilers will be unable to perform a full link-time optimization pass over all of the compiled code, leading to absent CFI (control flow integrity).
If Rust is available in the GNU toolchain, releases can be built on the Linux kernel (for example) with CFI using LLVM or GCC.
Started in 2014 (and revived in 2019), “The effort has been ongoing since 2020…and we’ve done a lot of effort and a lot of progress,” compiler engineer Arthur Cohen says in the talk. “We have upstreamed the first version of gccrs within GCC. So next time when you install GCC 13 — you’ll have gccrs in it. You can use it, you can start hacking on it, you can please report issues when it inevitably crashes and dies horribly.”
“One big thing we’re doing is some work towards running the rustc test suite. Because we want gccrs to be an actual Rust compiler and not a toy project or something that compiles a language that looks like Rust but isn’t Rust, we’re trying really hard to get that test suite working.”
- It reuses the GNU toolchain — the gdb debugger, the as assembler , and the linker ld — while also reusing official Rust libraries like libcore,libstd, and libproc.
- “Because of the way GCC is architectured, once you get to that common GCC backend and common GCC intermediate representation, you can basically reuse all of the plugins that have been written for GCC ever. And that means a lot of plugins — security plugins, stuff like the static analyzers, the LTO (link time optimization), CFI, security plugins, and so on.”
- “We also hope that because were writing it in C++, that means we can backport it to previous versions of GCC. And hopefully that will help some systems get Rust.”
- “Because GCC is much older than LLVM, it has support for more architectures and more targets than LLVM. So technically thanks to gccrs, you will now be able to run Rust on your favorite Soviet satellite and so on.”