|
|
Log in / Subscribe / Register

Compiling the kernel with gccrs

By Daroc Alden
September 22, 2026

RustConf

Pierre-Emmanuel Patry and Arthur Cohen gave a talk at RustConf 2026 on the status of the Rust frontend for GCC (gccrs), with a particular eye toward the goal of compiling the Linux kernel. Patry gave a follow-up talk for a more kernel-focused audience at Kangrejos the next week, which Cohen could not attend. The gccrs project is making good progress overall, but it will still be some time until the compiler is usable.

Cohen began the RustConf talk by stating that the title of the presentation, "Compiling the Linux kernel with gccrs", was a lie. Gccrs cannot currently compile the Linux kernel, for multiple reasons. One such reason, Cohen said, is that he and Patry were laid off and couldn't dedicate all of their time to gccrs — although Open Source Security has since picked up their contracts. Another reason, which Patry brought up at Kangrejos, was that their current goal was really to "miscompile the Linux kernel". The project needs to get to the point of emitting a binary that can be tested and validated to be said to be "compiling" anything; almost certainly, there will be a delay between the point where gccrs accepts the kernel's Rust code without complaint, and where the output it produces is actually a usable kernel. Nevertheless, the two of them have made substantial progress.

[Arthur Cohen]

GCC is a nearly 40-year-old project, Cohen explained, that brings together compilers for a number of different languages, such as C, C++, Fortran, Go, and Algol. The gccrs project wants to add a full implementation of a Rust compiler to that list, separate from the Rust project's rustc compiler. That is important for many reasons. For example, GCC supports more backend architectures than rustc does. GCC also supports custom compiler plugins that many existing projects rely on. With Rust code now included in the Linux kernel, it would be nice to be able to compile the kernel with just GCC.

Therefore, the main goal of gccrs has been to compile the Rust code present in the Linux kernel. That code is split into several different crates that depend on each other, Patry explained to both the RustConf and Kangrejos audiences. The most fundamental is core, which provides the "bare minimum to make Rust language features work". For example, for loops in Rust use the Iterator trait, which is defined in core. Without core, the compiler can't support for loops.

Other crates within the kernel include stdarch, which provides architecture-specific operations, alloc, which handles memory allocation, pin_init, which handles creating immovable structures, and others. When gccrs started, Patry said, he and Cohen began by trying to compile small snippets of Rust code in isolation. That approach has reached its limits, so the plan now is to focus on making core work, and then move up the dependency graph to alloc and so on, until the whole kernel compiles.

That approach has been working well, but has caused some problems with trying to parallelize the work, Cohen said. Currently, each problem that comes up with compiling core is hidden behind the previous problem, making it hard to split work across multiple contributors. To address that, Patry and Cohen made a mock version of the core library with only the parts needed by alloc, so that getting that crate to compile could proceed in parallel.

The core library is "really complicated", Cohen added. In many ways, it is the strangest Rust library, since it needs to do so many low-level operations that other code doesn't need to address. The hope is that once gccrs can compile core, it will be able to handle most Rust code, and any remaining libraries will be easy to support. "Maybe I just tell myself that," Cohen added, to general chuckles. The alloc crate also uses some complicated features, such as arbitrary self types, but the version used in the kernel is simpler than the one used in the standard library, so Cohen is not too worried.

[Pierre-Emmanuel Patry]

The project will eventually need to get the standard-library version working, however. There are two kernel crates that use procedural macros, Patry said, which are Rust code that is called during the compilation process, and can link against the standard library. So, even though the kernel itself does not link the standard library, gccrs will still need to be able to build it in order to compile the kernel.

At Kangrejos, Miguel Ojeda asked whether it would be possible to use procedural macros compiled by rustc, as a temporary workaround until the standard library is usable. Patry wasn't sure, but thought that it was theoretically possible. He was leery of disrupting the ecosystem by introducing strange incompatibilities between procedural macros and the code they generate, however. Ojeda opined that a workaround that gave the kernel access to gccrs a bit earlier would be useful for testing gccrs and finding problems. He then went to check on the use of the standard library in procedural macros in the kernel, and reported a few minutes later that the only uses are via the syn crate, and a single use of a BTreeSet that could probably be replaced.

Gary Guo thought that Ojeda was overlooking the complexity needed to support allocation, however, which is used implicitly by procedural macros. Once allocation is working, "you probably also get B-Trees for free," he remarked. Patry said that he hadn't spent much time looking into getting procedural macros working, since he and Cohen had been focused on the core crate. Maybe some additional thought will find a way to make it work, he suggested.

Compiling core

Cohen went into more detail on what has been involved in getting core to compile. For the past three years, he and Patry have mostly been working on fixing name resolution, the process of linking uses of names to their definitions. The initial implementation was simple, "like how a textbook compiler does name resolution". That implementation proved to be fundamentally flawed, however, because Rust's name resolution is quite complex. There are multiple separate namespaces (for functions and constants, types, labels, and lifetimes), and name resolution sometimes has to cross between them. Additionally, names can be used before they are defined.

Names can also be defined by macros, which themselves rely on being able to resolve names. Therefore, name resolution and macro expansion have to run interleaved with each other, in a fix-point fashion that repeats the process until all names have been discovered. Cohen originally told his boss that this work would take three weeks. Patry and Cohen finished it just before RustConf, nearly three years later. Despite the delays, name resolution is now working correctly, as is declarative macro expansion. It is not particularly fast, but "that is a problem for future Arthur".

At Kangrejos, Patry went into more detail on the performance problem. The core crate is roughly 85,000 lines of code, and gccrs used to take about 42 minutes to compile it. The crate does rely heavily on macros, but most of the time is spent in name resolution. Because name resolution runs until it reaches a fix-point, the compiler makes many of the same calls. Adding a cache for those calls brought the time required to compile core down to three minutes (compared to rustc's 30 seconds), which is "not as fast as rustc, but fast enough to work with".

The other tricky parts, such as inline assembly support, and the lang items system, are mostly working. At this point, each individual bug that the gccrs developers work on could be the last one standing between gccrs and compiling core.

There is still a known problem with passing crate metadata between compilation units, Patry added. Right now, the serialization format for crate metadata is a dump of the crate's abstract syntax tree. That's a temporary hack, he explained, which is working for the moment but that will need to be cleaned up to do cross-crate linking correctly.

Next steps

Cohen then explained some of the next steps for the project. Another known problem is the handling of the Drop trait, which is used to automatically clean up allocations at the end of their scope. Janet Chien, a Google Summer of Code (GSoC) participant working with the gccrs project, has been focused on improving that part of the implementation. When she started work, gccrs did not implement drops at all. Now, it has support for common cases, but can still be tripped up by nonlinear control flow, partial moves, generics, and temporary values. Enes Çevik, another GSoC participant, has been adding infrastructure for compiling and testing the alloc crate.

Once gccrs can compile all of the crates used by the kernel, the next step will be to catch up to stable Rust. For the last several years, gccrs has been targeting parity with rustc version 1.49 and a matching old version of the kernel. The project chose to do that to avoid chasing an endlessly moving target while trying to get basic functionality working at all; eventually, however, it will be time to chase that target. Patry is not too worried about the process of catching up. Most changes to the language come in the form of new library functions and types, and stabilization of existing unstable features, which Cohen expects should be trivial to support.

There are three features in particular that do represent actual changes to the language itself that will have to be dealt with, which Patry called out for the RustConf audience: trait upcasting, the new use<...> syntax, and return-position impl Trait in traits. There is also one additional experimental feature, cfi_encoding, which the kernel uses when generating bindings between C and Rust code. That will be slightly tricky, Patry explained, because it requires changes to GCC's control-flow integrity (CFI) code. There is an existing patch series addressing that, but it has remained unmerged since its introduction in 2025. The gccrs developers may need to work with the rest of the GCC maintainers to figure out whether that series is acceptable and how to get it merged.

After that, the project will have to test kernels compiled with gccrs to ensure that the behavior exactly matches that of binaries compiled with rustc. Since the kernel is not even compiling yet, Patry and Cohen haven't begun major work in that direction, but they have taken a few preliminary steps.

One audience member at RustConf asked whether gccrs implemented any of the intermediate representations that rustc uses. Patry said that it did not — although since the project hopes to reuse the implementation of the next-generation trait solver, the code may eventually have to produce an intermediate representation suitable for that.

Another person asked how well documented the Rust language specification is, and how that affected the validation of gccrs. The specification is not enough to fully implement a compiler, Cohen said, but that isn't the fault of the people working on the specification. The upstream rustc developers are productive, with new features coming with each version of the compiler. Patry and Cohen have tried to improve the specification where it is lacking, which is another benefit of having an independent reimplementation of the language.

[ Thanks to the Linux Foundation, LWN's travel sponsor, for assistance with attending both RustConf and Kangrejos. ]


Index entries for this article
ConferenceKangrejos/2026
ConferenceRustConf/2026


to post comments

"New plan is to focus on making core work"

Posted Sep 22, 2026 18:46 UTC (Tue) by CohenArthur (subscriber, #173796) [Link] (1 responses)

Thank you for the nice write-up! I hope you enjoyed the talk, I had a good time reading about it lol. I have one little nitpick I want to point out, as you wrote the following:

> When gccrs started, Patry said, he and Cohen began by trying to compile small snippets of Rust code in isolation. That approach has reached its limits, so the new plan is to focus on making core work, and then move up the dependency graph to alloc and so on, until the whole kernel compiles.

Please note that this isn't a recent plan from our part. We have always focused on core, but in the first few years of the project it was easier to focus on snippets from core that required a proper implementation of the feature we were working on. If you look at our testsuite, you'll see that a lot of testcases are direct excerpts from core 1.49. For testing for-loops, we have to fetch entire parts of the iter module from core and multiple trait implementations in order to ensure they're working. This means that for-loop testcases, just like a lot of other testcases in gccrs, are _multiple hundreds of lines long_ as they require a lot of "core context" in order to work properly. When we say "snippets from core" in the talk, it means that yeah we are not compiling the full mod structure that core uses, and that we're making it a little bit simpler to deal with - less imports, less macro invocations, less modules, etc etc. But it's still core.

Furthermore, we've always known that the first big goal of the compiler would be to compile the core library, so this is not a recent development. We've been testing core as a whole for years at this point, and trying to make sure that we were on the right track to compiling it.

Finally, yes we are moving through the dependency graph and getting to alloc and so on, but likewise this isn't a new development - over the years we've spent a lot of time looking at the code in alloc, and in the kernel, and in the std crate, and in a regular Rust program, identifying the features required and working on them, bit by bit, testcase by testcase, parallelizing the work and focusing on different areas at once. We have features in the compiler that aren't needed by core, but needed by other crates for example. We also have lints and error checks and warning passes, as we are committed to providing the same experience to Rust users, both during compilation and after compilation.

I'm guessing this is due to the way I worded that part during the talk, for which I apologize and should have been clearer :) thank you for reporting on the talk, I really appreciate it and it was really fun to give a talk at RustConf.

"New plan is to focus on making core work"

Posted Sep 22, 2026 19:04 UTC (Tue) by daroc (editor, #160859) [Link]

Oh, I see how that could be misread; I think your talk was perfectly clear and this is my own error as much as yours. I'll go tweak the wording in the article. Thanks!

Laid off?

Posted Sep 23, 2026 7:17 UTC (Wed) by taladar (subscriber, #68407) [Link] (3 responses)

> One such reason, Cohen said, is that he and Patry were laid off and couldn't dedicate all of their time to gccrs — although Open Source Security has since picked up their contracts.

Does that mean whoever paid for the gccrs work no longer considers it a good investment or were they laid off from jobs unrelated to this work?

Laid off?

Posted Sep 23, 2026 9:16 UTC (Wed) by CohenArthur (subscriber, #173796) [Link] (2 responses)

We weren't the only people that were laid off. They got rid of the entire French subsidiary (which we were a part of) as well as 3 employees from the parent company. Open Source Security was already funding most of the work through our old company, as a client for our compiler services, and offered to instead continue funding the entirety of the work on gccrs :) our old job was roughly 50% gccrs as we were also working on other company projects, and now it's 100% gccrs!

Laid off?

Posted Sep 24, 2026 7:35 UTC (Thu) by taladar (subscriber, #68407) [Link] (1 responses)

Thanks.

That sounds stressful for you but maybe like a positive outcome in the long term for the project. Hopefully you got through it all without too many worries.

Laid off?

Posted Oct 6, 2026 17:27 UTC (Tue) by CohenArthur (subscriber, #173796) [Link]

Thank you :) It was very stressful, I'm glad it's past us and we can continue moving forward on the compiler at our usual pace. It slowed development down for the month of August for sure, but the future is bright, and I can't wait until we have something even more meaningful to show for the project.


Copyright © 2026, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds