Difference between revisions of "GDC/Development/DevelopmentEnvironment"

From D Wiki
Jump to: navigation, search
(Title looks bad)
(Added intro)
Line 1: Line 1:
 
{{ParentArticle|[[GDC]] > [[GDC/Development | Development]]}}
 
{{ParentArticle|[[GDC]] > [[GDC/Development | Development]]}}
 +
 +
== Introduction ==
 +
This page provides instructions on how to set up a development environment for hacking the GDC compiler.
  
 
== Prerequesites ==
 
== Prerequesites ==

Revision as of 13:10, 16 October 2014


Introduction

This page provides instructions on how to set up a development environment for hacking the GDC compiler.

Prerequesites

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/
    gcc/
    build/
  usr/
  • $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=http://ftp.tsukuba.wide.ad.jp/software/gcc/releases
export GCC_NAME=gcc-4.9.1
export GCC_SOURCE_ARCHIVE=$GCC_NAME.tar.bz2
wget $GCC_MIRROR/$GCC_NAME/$GCC_SOURCE_ARCHIVE
tar xjfv $GCC_SOURCE_ARCHIVE -C gcc
rm $GCC_SOURCE_ARCHIVE

You may wish to use an alternate GCC mirror.

Obtain the GDC Source Code

cd $HOME/gdc-src/gdc/
git clone https://github.com/D-Programming-GDC/GDC.git .
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/
./setup-gcc.sh ../gcc

Configure GCC

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

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/
export DESTDIR=$HOME
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 setup-gcc.sh script

cd $HOME/gdc-src/gdc/
./setup-gcc.sh --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

Cleaning

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:

internal_error
gcc_unreachable

Noteworthy functions for debugging trees/gimple:

debug_tree
debug_generic_expr
debug_gimple_stmt

See also Debugging GCC on the GCC wiki.