Bootstrapping GDC with DMD

Hacker News Top Tools

Summary

The author describes how they bootstrapped the GNU D Compiler (GDC) on FreeBSD using the DMD compiler and a small wrapper program, challenging GCC's claim that GDC must be built with GDC.

No content available
Original Article
View Cached Full Text

Cached at: 07/15/26, 01:44 PM

# I bootstrapped GDC with DMD Source: [https://briancallahan.net/blog/20260713.html](https://briancallahan.net/blog/20260713.html) ## [Dr\. Brian Robert Callahan](https://briancallahan.net/blog/) academic, developer, with an eye towards a brighter techno\-social life --- --- ##### [\[prev\]](https://briancallahan.net/blog/20260609.html) ##### \[next\] ## 2026\-07\-13 I bootstrapped GDC with DMD Get the source code[here](https://github.com/ibara/gdc-wrapper)\. [FreeBSD](https://www.freebsd.org/)does not have a package for[GDC](https://wiki.dlang.org/GDC), the GNU D Compiler, which is the[D](https://dlang.org/)frontend of[GCC](https://gcc.gnu.org/)\. I frequently use GDC on FreeBSD as a[research tool](https://doi.org/10.2139/ssrn.6869668)\. As such, I had to actually bootstrap GDC for FreeBSD\. I forgot to share how I did it; this post is intended to fix that\. It's very straightforward and easy\. If you have[DMD](https://wiki.dlang.org/DMD), then you can easily get GDC\. I wrote a small[wrapper program](https://github.com/ibara/gdc-wrapper)to make it as easy and quick as possible\. #### What GCC claims GCC in their[documentation](https://gcc.gnu.org/install/prerequisites.html)says that GDC must be built with GDC\. Specifically, they say, "In order to build GDC, the D compiler, you need a working GDC compiler \(GCC version 9\.4 or later\) and D runtime library, 'libphobos', as the D front end is written in D\." The documentation goes on to say, "Versions of GDC prior to 12 can be built with an ISO C\+\+11 compiler, which can then be installed and used to bootstrap newer versions of the D front end\." Parts of that are inarguably true:[GDC is written in D as of GCC 12](https://gcc.gnu.org/gcc-12/changes.html)\. But parts of it feel untested: what is so special about GDC that it is the only D compiler that can build GDC? All the D compilers share a frontend, and the D frontend does not use any esoteric parts of the language\. And even if it did, all three D compilers share a frontend, so in theory any D compiler should be able to bootstrap GDC\. This is what I wanted to test, if for no other reason than it would take incredibly long to build an old version of GCC just to build a new version of GCC\. It takes seconds to build DMD\. #### What reality demonstrates In order to build GDC, you need a D compiler and libphobos version sufficient to build only the stage1 GDC\. The stage1 GDC builds the stage1 libphobos\. If we have a D compiler that can do just enough to build a working stage1 GDC, then we are golden\. That's the only hurdle we need to overcome\. The DMD compiler, the reference D compiler, is perfectly capable of doing this\. The impediment isn't whether or not DMD can build the stage1 GDC; it is the fact that of all three D compiler frontends, DMD, GDC, and[LDC](https://wiki.dlang.org/LDC), they all use different flag sets\. DMD and LDC are close to one another; GDC uses a very different flag style to match GCC\. If we can write a small wrapper program that translates those flag differences, we should be able to build the stage1 GDC with DMD\. #### `gdc\-wrapper` The little program just mechanically translates flags, adds all the other arguments unchanged, and then calls DMD with the transformed argument list\. I mostly went through trial\-and\-error until DMD built the stage1 GDC\. I would just let the GDC build run and when something failed, I would add that flag to the wrapper\. The most difficult flags to deal with were`\-MF`and`\-MT`, which create dependency rules files\. What I did here was ignore`\-MT`and create the file specified with`\-MF`but with only a single newline character in it\. That's a bit of a hack but we're not interested in getting it exactly right; we're interested in getting stage1 GDC built and moving on\. Other than that, we ignore warning flags, convert`\-o output\.o`to`\-ofoutput\.o`, change`\-finline`to`\-inline`, change`\-fversion=VERSION`to`\-version=VERSION`, and a few more small changes to make sure things linked correctly\. #### And it works I[downloaded](https://dlang.org/download.html)the FreeBSD x86\_64 DMD 2\.112\.0 binaries from the D website, untarred it to my`HOME`, and then built`gdc\-wrapper`with`\./configure \-\-dmd=/home/briancallahan/dmd2/freebsd/bin64/dmd && make`and I was able to build GDC without issue by adding`/home/briancallahan/gdc\-wrapper`to the end of my`PATH`temporarily with`export PATH=$PATH:$PWD`\. It really was that simple\. I can build GDC 15\.2\.0 and GDC 16\.1\.0 with this on FreeBSD 15\. #### Conclusion Hopefully this helps some FreeBSD, NetBSD, GNU Hurd, or Illumos people\. Or anyone on a Linux distro that doesn't have a GDC package\. The obvious limitation is that for now, DMD only has backends for x86 and x86\_64 \(though an ARM64 backend is on the way\!\)\. So if you want a GDC for a different CPU architecture, you will first need to bootstrap a native GDC with this procedure and then you can follow[one of our previous posts](https://briancallahan.net/blog/20250817.html)to build a cross\-GDCen routeto a native GDC for a different CPU architecture\. [![Top](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAICAYAAADJEc7MAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wkWDyUKJxzXegAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAUklEQVQY02Ocd/j/fwY0kGjDwMhACPz//5/h////DPMO//8PYxODWXAZOP8Iw39k22F8uBg2G7Gx0cWYGMgEWJ2aaMPAiO5UDOcTGxjogUe2UwHwdJDZUucW5QAAAABJRU5ErkJggg==)](https://briancallahan.net/blog/20260713.html#top) [![RSS](https://briancallahan.net/blog/media/pic_rss.gif)](https://briancallahan.net/blog/feed.xml) ---

Similar Articles

Adopting the Parallel DWARF linker in dsymutil

Hacker News Top

Apple's dsymutil tool, which links DWARF debug info into self-contained bundles, is adopting a parallel DWARF linker to address the single-threaded bottleneck in type deduplication, despite challenges in qualification due to non-binary-identical output.

Building GCC 1.27 (2019)

Hacker News Top

A blog post describes the process of building GCC 1.27, a 1988 compiler, on a modern Ubuntu system, detailing necessary patches and steps.

Bootstrapping Rust Considered Harmful

Lobsters Hottest

A critical analysis of the Rust compiler's bootstrapping process, highlighting the excessive size and dependency bloat compared to other languages like OCaml, and arguing for a more lightweight approach.