rustc_codegen_gcc: Progress Report #16
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
This month, I did the following:
While debugging the stdarch tests, I found out some of them were failing because libgccjit would assume char
is unsigned by default while it needed to be signed for the builtins to work properly.
This commit is not yet posted as a patch for review.
State of rustc_codegen_gcc
Here’s what has been done this month:
-
simd: impl extract_element for vector types (thanks to sadlerap!)
-
simd: implement float math intrinsics (thanks to sadlerap!)
-
simd: enable simd_as intrinsic (thanks to sadlerap!)
If you attended my talk at the LPC, you already know that rustc_codegen_gcc
can now compile Rust for Linux:
In this image, we can see Linux modules, built in Rust, and compiled with rustc_codegen_gcc
, that are being loaded and executed correctly!
It doesn’t work on the master branch since it requires 2 features to be implemented:
-
CPU features detection.
-
Some compiler flags support (
-Crelocation-model=static
).
If you want to try compiling Rust for Linux using the GCC codegen, I made a branch for both rustc_codegen_gcc
and Rust for Linux
:
It’s awesome that we can already compile Rust for Linux with very few hacks: we’re very close to being able to compile it on the master branch.
I also made some progress on the stdarch tests:
test result: FAILED. 4570 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.48s
Category | Last Month | This Month | Delta |
---|---|---|---|
Passed |
4564 |
4570 |
+6 |
Failed |
12 |
6 |
-6 |
Some tests were failing due to the fact that I was running them with a sysroot compiled in debug mode.
Indeed, during my investigation, I found out that there is a bug in some tests that makes them fail even with the LLVM codegen.
That’s also by compiling the sysroot in release mode that I found out that some bugs need to be fixed in rustc_codegen_gcc
regarding undefined behavior:
some tests from libcore fail with a sysroot compiled in release mode due to the optimizers taking advantage of undefined behavior and breaking the code.
And as mentioned in the beginning of this article, some stdarch tests were fixed by making the char type signed.
Unfortunately, I realized that there are many more failures than that when I attempted to run those tests in the CI: since my CPU doesn’t support AVX-512, those tests were just passing when running locally.
Here are the results in the CI:
test result: FAILED. 3649 passed; 927 failed; 0 ignored; 0 measured; 0 filtered out; finished in 22.99s
Here’s a rough summary of what has been implemented for SIMD:
Feature | Last month completion | Completion | Delta |
---|---|---|---|
target-specific builtins support in libgccjit |
Done |
||
support for vector shuffle (equivalent of |
Done |
||
|
Done |
||
|
Done |
||
|
Done |
||
|
Done |
||
|
implemented for x86 |
||
|
Done |
||
|
Done |
||
|
Done |
||
LLVM SIMD intrinsics |
~99% implemented for x86 |
~99% implemented for x86 |
0 (needs to fix some bugs) |
SIMD float intrinsics |
5% |
100% |
+95% |
|
0% |
100% |
+100% |
|
0% |
100% |
+100% |
|
0% |
100% |
+100% |
|
0% |
100% |
+100% |
|
50% |
50% |
0 |
|
0% |
0% |
0 |
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/3171116480/jobs/5164245308#step:19:12026
-
https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/3171116480/jobs/5164245359#step:19:12026
-
https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/3171116480/jobs/5164245405#step:19:15049 (failures)
Category | Last Month | This Month | Delta |
---|---|---|---|
Passed |
4787 |
4793 |
+6 |
Failed |
52 |
46 |
-6 |
For the next month, I’ll continue working on SIMD support: debugging those tests and fixing the issues found. I might also work on those AVX-512 failures and the issues with a sysroot compiled in release mode.
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.
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:
-
saethlin
-
embark-studios
-
Traverse-Research
-
Shnatsel
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. Another big thank you to Commeownist for his contributions.
Also, a big thank you to the rest of my sponsors:
-
kpp
-
0x7CFE
-
repi
-
nevi-me
-
oleid
-
acshi
-
joshtriplett
-
djc
-
TimNN
-
sdroege
-
pcn
-
alanfalloon
-
steven-joruk
-
davidlattimore
-
Nehliin
-
colelawrence
-
zmanian
-
alexkirsz
-
regiontog
-
berkus
-
belzael
-
vincentdephily
-
jam1garner
-
yvt
-
Shoeboxam
-
evanrichter
-
yerke
-
bes
-
seanpianka
-
srijs
-
kkysen
-
messense
-
riking
-
rafaelcaricio
-
Lemmih
-
memoryruins
-
pthariensflame
-
senden9
-
robjtede
-
Jonas Platte
-
zebp
-
spike grobstein
-
Oliver Marshall
-
Sam Harrington
-
Jonas
-
Jeff Muizelaar
-
Eugene Bulkin
-
Absolucy
-
Chris Butler
-
sierrafiveseven
-
Joseph Garvin
-
MarcoFalke
-
athre0z
-
icewind
-
Tommy Thorn
-
Sebastian Zivota
-
Oskar Nehlin
-
Nicolas Barbier
-
Daniel
-
Thomas Colliers
-
Justin Ossevoort
-
sbstp
-
Chris
-
Bálint Horváth
-
fanquake
-
sstadick
-
luizirber
-
kiyoshigawa
-
robinmoussu
-
Daniel Sheehan
-
Marvin Löbel
-
nacaclanga
-
Matthew Conolly
-
dandxy89
-
0x0177b11f
-
L.apz
-
JockeTF
-
davidcornu
-
tedbyron
-
stuhood
-
0xdeafbeef
-
Myrik Lord
-
Mauve
and a few others who preferred to stay anonymous.
Former sponsors/patreons:
-
igrr
-
finfet
-
Alovchin91
-
wezm
-
mexus
-
raymanfx
-
ghost
-
gilescope
-
Hofer-Julian
-
olanod
-
Denis Zaletaev
-
Chai T. Rex
-
Paul Ellenbogen
-
Dakota Brink
-
Botlabs
-
Cass
-
Oliver Marshall