Dr. Brian Robert Callahan

submited by
Style Pass
2024-03-28 15:00:04

There are, I think, two great open source compiler infrastructures: GCC and LLVM. They have been a great boon to all kinds of development, open source and closed source alike.

Today, we are going to create a bit of a franken-compiler toolchain. Once upon a time, the LLVM project had a plugin for GCC called DragonEgg that would cause GCC to use LLVM's optimizers and backend generators instead of GCC's. We will do something not quite that cool but something with potentially useful results.

As a consequence of LLVM containing an integrated assembler, this means that clang can assemble assembly files if you pass them to clang. GCC cannot do this, at least not directly: if you pass gcc an assembly file it will simply pass it onto your assembler, usually GNU as but can be another Unix assembler, such as the Sun assembler, which can be run on Solaris and Illumos.

And so I want to know if it is possible to replace GNU as with clang as the assembler in the GCC toolchain. There is potential to want this, at least one some systems. FreeBSD, specifically FreeBSD 14.0-RELEASE, where will be running our experiment today, no longer ships a /usr/bin/as binary. With LLVM also providing a linker and many other utilities found in the GNU binutils, could GCC become a boutique frontend for the LLVM system?

Leave a Comment