15

Progress Report #26: rustc_codegen_gcc can now compile Rust for Linux!

 11 months ago
source link: https://blog.antoyo.xyz/rustc_codegen_gcc-progress-report-26
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Progress Report #26: rustc_codegen_gcc can now compile Rust for Linux!

01 Oct 2023

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 commits, which are yet to be sent on the gcc mailing list:

State of rustc_codegen_gcc

Here’s what has been done during the past month:

It was announced last year that rustc_codegen_gcc can compile Rust for Linux with very few hacks. Today, I’m happy to announce that it can compile Rust for Linux without any patches! (Well, we still need patches to GCC itself like the rest of rustc_codegen_gcc, but those will be merged upstream eventually.)

State of compiling popular crates

It was asked from time to time to test compiling the most popular crates with rustc_codegen_gcc and I finally did so. Here are the results of running the tests of the most popular crates.

Project Compiles Tests passing Tests failing Note

getrandom

memchr

cfg-if

lazy_static

base64

The process consumes a lot of memory and gets OOM-killed if running all the tests at once.

regex

bitflags

serde

As you can see, rustc_codegen_gcc successfully run and pass all the tests of all those crates. I had to fix a few small bugs in order to achieve this result and they were merged last month. The tests from base64 seem to have a memory leak when using the GCC codegen: I’m going the investigate this issue in the future.

In addition to running those tests, I was able to successfully run process-viewer and it seemed to work properly.

Next month, I plan to continue working on correctly handling the endianness for non-native 128-bit integers. This month, I setup the CI to be able to cross-compile to the m68k architecture in order to be able to run the integers test.

Here’s a rough summary of what has been implemented:

Feature Last month completion Completion Delta

Unwinding.

More function and variable attributes.

Target features (to detect what is supported in an architecture, like SIMD).

Thin LTO.

Debug info.

Endianness support for non-native 128-bit integers.

Rustup distribution.

SIMD for other architectures than x86-64.

Support for new architectures in libraries (libc, object, …) and rustc.

SIMD (x86-64).

Basic and aggregate types.

Operations, local and global variables, constants, functions, basic blocks.

Atomics.

Thread-local storage.

Inline assembly.

Many intrinsics.

Metadata.

Setting optimization level.

Packed structures.

Alignment, symbol visibility, attributes.

128-bit integers.

How to contribute

rustc_codegen_gcc

If you want to help on the project itself, please do the following:

  1. Run the tests locally.

  2. Choose a test that fails.

  3. Investigate why it fails.

  4. 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:

  • Futurewei

  • saethlin

  • embark-studios

  • Traverse-Research

  • 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. Another big thank you to Commeownist for his contributions.

Also, a big thank you to the rest of my sponsors:

  • 0x7CFE

  • oleid

  • acshi

  • joshtriplett

  • sdroege

  • alanfalloon

  • steven-joruk

  • davidlattimore

  • colelawrence

  • zmanian

  • alexkirsz

  • berkus

  • belzael

  • Shoeboxam

  • yerke

  • seanpianka

  • srijs

  • kkysen

  • riking

  • Lemmih

  • memoryruins

  • senden9

  • robjtede

  • Jonas Platte

  • spike grobstein

  • Oliver Marshall

  • Sam Harrington

  • Jonas

  • Jeff Muizelaar

  • Eugene Bulkin

  • Chris Butler

  • sierrafiveseven

  • Joseph Garvin

  • MarcoFalke

  • athre0z

  • icewind

  • Tommy Thorn

  • Sebastian Zivota

  • Oskar Nehlin

  • Nicolas Barbier

  • Daniel

  • Thomas Colliers

  • Justin Ossevoort

  • Chris

  • Bálint Horváth

  • kiyoshigawa

  • robinmoussu

  • Daniel Sheehan

  • Marvin Löbel

  • nacaclanga

  • Matthew Conolly

  • 0x0177b11f

  • L.apz

  • JockeTF

  • davidcornu

  • stuhood

  • Myrik Lord

  • Mauve

  • icewind1991

  • nicholasbishop

  • Emily A. Bellows

  • David Vasak

  • Eric Driggers

  • Olaf Leidinger

  • UtherII

  • simonlindholm

  • lemmih

  • Eddddddd

  • rrbutani

  • Mateusz K

  • 0xdeafbeef

and a few others who preferred to stay anonymous.

Former sponsors/patreons:

  • finfet

  • Alovchin91

  • mexus

  • raymanfx

  • ghost

  • gilescope

  • olanod

  • Denis Zaletaev

  • Chai T. Rex

  • Paul Ellenbogen

  • Dakota Brink

  • Botlabs

  • Oliver Marshall

  • pthariensflame

  • tedbyron

  • sstadick

  • Absolucy

  • rafaelcaricio

  • dandxy89

  • luizirber

  • regiontog

  • vincentdephily

  • Hofer-Julian

  • messense

  • fanquake

  • jam1garner

  • sbstp

  • evanrichter

  • Nehliin

  • nevi-me

  • TimNN


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK