From D Wiki
Revision as of 13:09, 16 October 2014 by Verax (talk | contribs) (Title looks bad)
Jump to: navigation, search


The minimum system requirements you need to obtain and build GDC are:

  • gcc and g++
  • libmpc-dev
  • libmpfr-dev
  • libgmp3-dev
  • autoconf and automake
  • flex and bison
  • patch
  • git

For cross-compiling/multilib builds, you should also have installed:

  • gcc-multilib
  • (maybe g++-multilib)

Creating a Directory Structure

These instructions will do a native build. If you wish to build a cross-compiler, see GDC/Cross_Compiler and modify these scripts and instructions per your target's requirements.

These instructions will use the following directory structure.

  • $HOME/gdc-src/gdc/ - This directory will contain the GDC source code downloaded from a GCC mirror
  • $HOME/gdc-src/gcc/ - This directory will contain the GCC source code clone from the GDC GitHub repository
  • $HOME/gdc-src/build/ - configure should not be run within the $HOME/gdc-src/gcc/ directory, so $HOME/gdc-src/build/ will be used to for running configure and make
  • $HOME/usr/ - This directory will contain the final GDC toolchain binaries, libraries, etc...

Run the following commands to create the directory structure

mkdir $HOME/gdc-src/
mkdir $HOME/gdc-src/gdc/
mkdir $HOME/gdc-src/gcc/
mkdir $HOME/gdc-src/build/
mkdir $HOME/usr/

Obtain the GCC Source Code and Extract it to $HOME/gdc-src/gcc/

cd $HOME/gdc-src/
export GCC_MIRROR=
export GCC_NAME=gcc-4.9.1
tar xjfv $GCC_SOURCE_ARCHIVE -C gcc

You may wish to use an alternate GCC mirror.

Obtain the GDC Source Code

cd $HOME/gdc-src/gdc/
git clone .
git checkout gdc-4.9

If you plan on submitting pull requests, may want to first fork the GDC GitHub repository, and then clone from your fork.

Add GDC to GCC

cd $HOME/gdc-src/gdc/
./ ../gcc

Configure GCC

cd $HOME/gdc-src/build/
../gcc/configure         \
  --enable-languages=d   \
  --disable-bootstrap    \
  --prefix=/usr          \
  --disable-multilib     \
  --disable-libgomp      \
  --disable-libmudflap   \

Other configure arguments you might want to use:

--[enable|disable]-nls          # Native language support (NLS).  Lets GDC output diagnostics in languages other than English.
--[enable|disable|-libssp       # Build GCC with stack smashing protection.
--[enable|disable]-lto          # Support link-time optimization.
--[enable|disable]-ld           # Build the ld linker.
--[enable|disable]-gold         # Build the gold linker.
--[enable|disable]-multilib     # Allow building both 32-bit and 64-bit apps/libs.
--[enable|disable]-shared       # Build shared libraries.
--with-multilib-list=mXX,mYY    # Select multilibs, eg: --with-multilib-list=m32,m64,mx32 (AArch64 and x86-64 only)

Documentation on the various configure options can be found in GCC's documentation here

Build GCC

cd $HOME/gdc-src/build/
make CXXFLAGS="-g3 -O0" -j2 2>&1 | tee build.log

Install GCC

cd $HOME/gdc-src/build/
make install

Modifying the Source Code

GDC source code will still remain in $HOME/gdc-src/gdc and GCC source code will still be in $HOME/gdc-src/gcc. Hack away! When you're finished modifying the source code, you can do an incremental build by simply running the above make command, with the following caveats:

Adding/Removing files from libphobos or libdruntime require you to re-run the script

cd $HOME/gdc-src/gdc/
./ --update ../gcc

In certain circumstances (updating the frontend mostly), changes to dfrontend/idgen.c or dfrontend/impcnvgen.c sometimes do not trigger rebuilds of other sources. When this occurs, crashes or errors will look rather confusing. That's because the symbol table between two object files differ. Clean out all objects from the gdc build directory and re-make it.

Changes to just GDC only require a rebuild of cc1d - or the 'D compiler proper':

cd $HOME/gdc-src/build/
make -C gcc cc1d

Changes to libphobos/libdruntime can be done using make:

cd $HOME/gdc-src/build/
make all-target-libphobos


To clean out gdc/cc1d only from $HOME/gdc-src/build:

cd $HOME/gdc-src/build/
rm gcc/gdc gcc/d/*

To clean out libphobos/libdruntime:

cd $HOME/gdc-src/build/
make clean-target-libphobos

Debugging GDC

Though GCC does allow you to debug the compiler using -wrapper, it may be quicker to obtain the actual command passed to the cc1d and pass that to the debugger. To obtain that command run:

$HOME/usr/bin/gdc -pipe -c --verbose program.d

Noteworthy functions to break at to catch ICE's:


Noteworthy functions for debugging trees/gimple:


See also Debugging GCC on the GCC wiki.