Completely Ripping the Runtime out of D
Published , Updated
Update: a lot of this information is already outdated (good news!). See my latest update, and my second update.
Most high level languages are built as a layer on top of C. That includes out-of-the-box D, but it doesn’t have to
be that way: D is a plausible candidate for a “better C”. I think this is a pretty cool idea, so I’ve been
experimenting with it to see what’s possible. The dmd
compiler (and very soon the ldc2
compiler) has a -betterC
command line flag that’s intended to remove dependencies on the
D runtime. Unfortunately, it’s still extremely rudimentary — the docs only promise it “omit[s] generating some
runtime information and helper functions” — so in practice it’s hard to write non-trivial D code without getting
runtime dependencies, even if you don’t need them in theory.
With a little linker hacking, it’s possible to rip these unnecessary dependencies out of compiled D code. As an example, I’ll completely remove all references to the D runtime out of some compiled D code so that it can link directly to some C, as if it were C code to begin with.