rustc_codegen_gcc: Progress Report #43
What is rustc_codegen_gcc?
rustc_codegen_gcc is a GCC ahead-of-time codegen for rustc, meaning that it can be loaded by the existing rustc frontend, but benefits from GCC by having more architectures supported and having access to GCC’s optimizations. It is not to be confused with gccrs, which is a GCC frontend for Rust.
GCC patches status
There’s been some progress on this side!
Not much progress for reviews or merge upstream, but we wrote many more patches in our GCC fork:
-
Add missing *_to_object casts (thanks to GuillaumeGomez!)
-
Correctly handle packed attribute on a type fields (thanks to GuillaumeGomez!)
-
Remove gcc_jit_type_set_packed (thanks to GuillaumeGomez!)
-
Add support for type attributes (thanks to GuillaumeGomez!)
-
libgccjit: Fix add of section and retain attributes (thanks to GuillaumeGomez!)
-
libgccjit: Add support for retain attribute (thanks to GuillaumeGomez!)
-
libgccjit: Add support for section attribute on functions and variables (thanks to GuillaumeGomez!)
-
Add support for used variable attribute in libgccjit (thanks to GuillaumeGomez!)
-
Add support for new alias variable attribute in libgccjit (thanks to GuillaumeGomez!)
-
libgccjit: Expose va_arg and va_start (thanks to folkertdev!)
State of rustc_codegen_gcc
Here’s what has been done during the past months:
-
Fix EII (thanks to AsakuraMizu!)
-
Refactor to avoid having to use set_type for global variables
-
Update gccjit.rs dependency version to 6.0.0 (thanks to GuillaumeGomez!)
-
Add explicit register support for m68k (thanks to techmetx11!)
-
Finish the m68k target CPU LLVM list for GCC (thanks to techmetx11!)
-
Fix two broken links in the docs (thanks to kutsibalci!)
-
Only emit -fno-asynchronous-unwind-tables when we should not emit unwind tables
-
Update gcc and gccjit (thanks to GuillaumeGomez!)
-
Only keep minimum required info for cpuid.def (thanks to GuillaumeGomez!)
-
Add new y.sh clippy command (thanks to GuillaumeGomez!)
-
asm: seed the in_value for inout (thanks to xobs!)
-
int: implement signed comparison for unsigned integers (thanks to xobs!)
-
Automatically install rustfmt if not installed when running y.sh fmt command (thanks to GuillaumeGomez!)
-
Cleanup for build_system::Command enum (thanks to GuillaumeGomez!)
-
Add support for section linking (thanks to GuillaumeGomez!)
-
Update doc for subtree sync (thanks to GuillaumeGomez!)
-
doc/subtree.md: fix typo ("sync" → "synced") (thanks to DanielEScherzer!)
-
Add support for used attribute (thanks to GuillaumeGomez!)
-
gcc: locate codegen-backends via host_tuple() (thanks to xobs!)
-
Add support for aliases (thanks to GuillaumeGomez!)
-
Support guaranteed tail calls (thanks to folkertdev!)
-
use core fallbacks for more f16/f128 operations (thanks to folkertdev!)
-
implement va_start and va_arg (thanks to folkertdev!)
-
Allow to specify the channel for the rustc command (thanks to GuillaumeGomez!)
-
Add asm tests (thanks to GuillaumeGomez!)
-
Add comment explaining why we don’t handle all function parameter attributes in GCC (thanks to GuillaumeGomez!)
-
Directly generate correctly formatted intrinsics file and regenerate intrinsics (thanks to GuillaumeGomez!)
I’m happy to have finally fixed the issues we had with unwinding when compiling in release mode! However, the version of rustc_codegen_gcc distributed by rustup does not contain that fix yet since we had a lot of issues with syncing the changes to the Rust repo. Most of those issues should be fixed now, so we should be able to sync soon.
While I consider unwinding to be done in rustc_codegen_gcc, there will probably be some issues to fix outside rustc_codegen_gcc. For instance, we had to fix an issue in the Rust unwind library. We will probably also need to fix some exception handling issues in some GCC backends.
Now that unwinding is fixed, it is a good time to do a crater run to discover issues with rustc_codegen_gcc and see how many crates it supports. Before we do that, though, I plan to attempt to compile a couple widely-used crates to see if there are big issues to fix first. So, this is what I plan to do in the coming months.
Here’s a rough summary of what has been implemented:
| Feature | Last month completion | Completion | Delta |
|---|---|---|---|
Unwinding. |
80% |
100% |
+20% |
Run tests in the Rust CI |
80% |
80% |
|
More function and variable attributes. |
22% |
60% |
+38% |
Target features (to detect what is supported in an architecture, like SIMD). |
82% |
82% |
|
Debug info. |
20% |
20% |
|
Thin LTO. |
5% |
5% |
|
Support for new architectures in libraries (libc, object, …) and rustc. |
2% |
2% |
|
SIMD for other architectures than x86-64. |
0% |
||
Refactor to rustc_codegen_ssa to make it easier for the GCC codegen |
0% |
||
Rustup distribution. |
Done |
||
LTO |
Done |
||
Endianness support for non-native 128-bit integers. |
Done |
||
SIMD (x86-64). |
Done |
||
Basic and aggregate types. |
Done |
||
Operations, local and global variables, constants, functions, basic blocks. |
Done |
||
Atomics. |
Done |
||
Thread-local storage. |
Done |
||
Inline assembly. |
Done |
||
Many intrinsics. |
Done |
||
Metadata. |
Done |
||
Setting optimization level. |
Done |
||
Packed structures. |
Done |
||
Alignment, symbol visibility, attributes. |
Done |
||
128-bit integers. |
Done |
UI tests progress
Here are the results of running the UI tests in the CI:
-
https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/33278895790/job/99170541346#step:19:4685
-
https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/33278895790/job/99170541415#step:19:4818
-
https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/33278895749#summary-99170541126 (failures)
| Category | Last Month | This Month | Delta |
|---|---|---|---|
Passed |
7156 |
7699 |
+543 |
Failed |
80 |
21 |
-59 |
How to contribute
rustc_codegen_gcc
If you want to help on the project itself, please do the following:
-
Run the tests locally.
-
Choose a test that fails.
-
Investigate why it fails.
-
Fix the problem.
Even if you can’t fix the problem, your investigation could help, so if you enjoy staring at assembly code, have fun!
Crates and rustc
If you would like to contribute on adding support for Rust on
currently unsupported platforms, you can help by adding the support
for those platforms in some crates like libc and object and also
in the rust compiler itself.
Test this project
Otherwise, you can test this project on new platforms and also compare the assembly with LLVM to see if some optimization is missing.
To do so, follow these instructions to build the project and run a program via the cargo command of our script.
If you find a bug, please open an issue.
Good first issue
Finally, another good way to help is to look at good first issues. Those are issues that should be easier to start with.
Thanks for your support!
I wanted to personally thank all the people that sponsor this project: your support is very much appreciated.
A special thanks to the following sponsors:
-
Futurewei
-
Shnatsel
-
Rust Foundation
A big thank you to bjorn3 for his help, contributions and reviews. And a big thank you to lqd and GuillaumeGomez for answering my questions about rustc’s internals and to Kobzol and GuillaumeGomez for their contributions. Another big thank you to Commeownist for his contributions.
Also, a big thank you to the rest of my sponsors:
-
kpp
-
0x7CFE
-
oleid
-
joshtriplett
-
djc
-
sdroege
-
pcn
-
alanfalloon
-
davidlattimore
-
colelawrence
-
zmanian
-
berkus
-
belzael
-
yvt
-
yerke
-
srijs
-
kkysen
-
riking
-
Lemmih
-
memoryruins
-
senden9
-
robjtede
-
Jonas Platte
-
Sam Harrington
-
Jonas
-
Eugene Bulkin
-
Joseph Garvin
-
MarcoFalke
-
athre0z
-
Sebastian Zivota
-
Oskar Nehlin
-
Nicolas Barbier
-
Daniel
-
Justin Ossevoort
-
kiyoshigawa
-
Daniel Sheehan
-
Marvin Löbel
-
nacaclanga
-
L.apz
-
JockeTF
-
davidcornu
-
stuhood
-
Mauve
-
icewind1991
-
nicholasbishop
-
David Vasak
-
Eric Driggers
-
Olaf Leidinger
-
UtherII
-
simonlindholm
-
lemmih
-
Eddddddd
-
rrbutani
-
Mateusz K
-
thk1
-
teh
-
KirilMihaylov
-
Vladislav Sukhmel
-
ximou
-
Kate Kiesel
-
jplatte
-
thesamesam
-
sbstp
-
Laine Taffin Altman
-
LunNova
-
Robin Moussu
and a few others who preferred to stay anonymous.
Former sponsors/patreons:
-
igrr
-
embark-studios
-
saethlin
-
Traverse-Research
-
finfet
-
Alovchin91
-
wezm
-
mexus
-
raymanfx
-
ghost
-
gilescope
-
olanod
-
Denis Zaletaev
-
Chai T. Rex
-
Paul Ellenbogen
-
Dakota Brink
-
Botlabs
-
Cass
-
Oliver Marshall
-
pthariensflame
-
tedbyron
-
sstadick
-
Absolucy
-
rafaelcaricio
-
dandxy89
-
luizirber
-
regiontog
-
vincentdephily
-
zebp
-
Hofer-Julian
-
messense
-
fanquake
-
jam1garner
-
evanrichter
-
Nehliin
-
nevi-me
-
TimNN
-
steven-joruk
-
seanpianka
-
spike grobstein
-
Jeff Muizelaar
-
robinmoussu
-
Chris Butler
-
sierrafiveseven
-
icewind
-
Thomas Colliers
-
Tommy Thorn
-
Bálint Horváth
-
Matthew Conolly
-
Lapz
-
Myrik Lord
-
T
-
Emily A. Bellows
-
Chris
-
repi
-
opensrcsec
-
NobodyXu
-
alexkirsz
-
0xdeafbeef
-
l-const
-
CohenArthur
-
bes
-
acshi
-
Shoeboxam
-
teohhanhui
-
g4titanx
-
0x0177b11f
-
VasanthakumarV
