Hacker News new | ask | show | jobs
by rapsey 1280 days ago
More architectures supported at least. Now Rust can really be used anywhere C is used
3 comments

You don't need to write an new frontend for that, just add libgccjit as a backend for rustc.
Which has been done, and I'm really sad how that effort has been overshadowed hard by GCCRS, when the latter is much more niche in its use case
Out of curiosity, what can GCC's backend generate that LLVM can't?
Lots of rarer or older architectures are not in LLVM e.g. alpha, ia64, HP-PA. The LLVM backends which do exist for such also tend to have been exercised less and thus me more buggy (I think PPC/spe had a fair amount of issues there but it might have gotten better).

You can see something of a summary over on https://builds.Debian.org/status/package.php?p=rustc&suite=s... the BD-Uninstallable entries are unsupported archs, though some of them might be due to rustc or bringup bugs (e.g. m68k is supposedly supported by llvm and rustc).

Then there’s embedded, on the more open side LLVM is slowly gaining ground but there’s also less open ecosystems where customising / forking gcc is pretty standard historically, and there’s not much LLVM can do.

> Lots of rarer or older architectures are not in LLVM e.g. alpha, ia64, HP-PA.

If there are people who care about these historical architectures, they can do the work to maintain them in LLVM. That's how m68k support was added.

Some of those older architectures are supported by the Linux kernel, which is adopting Rust. Giving GCC the ability to compile Rust code maintains support for those platforms as the percentage of Rust in the kernel grows.

There are also embedded applications, of course; plenty of crappy manufacturers still give you a GCC fork as your only compiler for their dedicated hardware. The ability to get Rust hooked into those compilers can help keep the ecosystem up to date.

Even companies maintaining their own software sometimes take a long time to add support to LLVM. Take for example Espressif's Xtensa fork that is only now starting to get merged (if https://discourse.llvm.org/t/rfc-request-for-upstream-tensil... is to be believed). Many patches are still waiting for review, so it'll be a while until LLVM finally supports Xtensa (and with it microcontrollers such as the ESP32). GCC has had Xtensa support for ages (Github lists xtensa.h going back all the way to 2002) and I doubt Espressif is the only company in this position.

"Just do the work" sounds easy but that work can take years. Getting modern Linux versions to compile may not be enough to drive companies to put in the effort; many may prefer to simply never update their kernels past the current LTS version again.

Adding a frontend to GCC works around this problem quite efficiently. It also makes it easier to port existing code to these platforms; sure, the lack of a borrow checker drops all guarantees Rust has been designed to provide, but if you're not writing any code, you don't need those anyway.

> If there are people who care about these historical architectures, they can do the work to maintain them in LLVM.

Or they can decide to use an existing compiler that already works.

I disagree, but that aside I think the big motivator was embedded support. The reality is what OP said: companies fork GCC.
So in order to use rust you also have to become a compiler developer?
In order to use rust on an unsupported architecture? Pretty much yes. Same as if you wanted to use Clang or GCC on an unsupported architecture.
It's pretty frequent that embedded chips will have patched versions of GCC in their toolkit.
But only the more 'exotic' architectures. Everything ARM works fine with upstream GCC.
AVR (for example, old Arduino boards) and xtensa (like esp32 developer boards) are the only ones I know of. Most of the desktop OS platforms are supported by both.
AVR should be working these days https://github.com/llvm/llvm-project/tree/main/llvm/lib/Targ...

Unless you mean some specific chips?

Also while ESP32 has not been mainlined (I think), Espressif has both an llvm and a rustc fork.
Espressif has forks of everything (OpenOCD, GDB, GCC) that they never mainline and that just become outdated as they release new chips.

The latest xtensa-esp8266-elf-gcc is version 5.2

Their first patches are in the process of being merged: https://discourse.llvm.org/t/rfc-request-for-upstream-tensil...
I didn't know that!
Not so, there some obscure hardware platforms with C compilers but which are unsupported by GCC. GCC has no official backend for PIC or Z80, for instance.

Non-standard C-like languages are used in computer graphics and GPU computing (OpenGL, Direct3D, OpenCL), but strictly speaking they don't count as C.