GDC/Cross Compiler/Existing Sysroot

From D Wiki
Revision as of 20:40, 21 March 2014 by Jpf (talk | contribs) (GNU Binutils)
Jump to: navigation, search

This describes how to build a cross compiler if you have access to an existing system root (short sysroot). A sysroot is a folder which contains a minimal filesystem (especially libraries, the C library and header files). An example sysroot could look like this: 'sysroot/usr', 'sysroot/usr/lib', 'sysroot/usr/include'.

The sysroot

We assume that a sysroot is available at $SYSROOT. If the sysroot directory is inside the prefix where we'll install the compiler, the complete prefix directory can be moved to different locations. If it's not in the prefix directory GCC always uses the absolute path for the sysroot and if you move the sysroot the compiler will not work anymore.

Sysroot over SSH

If your target machine offers a fast SSH access it's possible to use the file system of the remote machine directly. This way the crosscompiler has full access to all libraries of the remote system. If a library is missing simply install it on the remote machine using the standard package manager.

You can mount a remote sysroot by using SSHFS:

sshfs -o idmap=user,follow_symlinks user@targethost:/ $SYSROOT

user@targethost is an SSH user / hostname account. $SYSROOT is the location where the sysroot will be mounted.

The follow_symlinks option is important. The remote filesystem will have absolute symlinks (/usr/lib/ --> /usr/lib/ .follow_symlinks makes sure we really get access to the remote /usr/lib/ and not to the local one.

Specifying a target and installation folder

export TARGET=arm-linux-gnueabi
export PREFIX={installation folder}
export SYSROOT={sysroot folder}

Replace {installation folder} with the absolute path to the folder the toolchain should be installed in.

GNU Binutils

# Delete existing binutils source archive and download a new one
export BINUTILS_NAME=binutils-2.24

# Extract binutils

# Create binutils build directory
export BINUTILS_BUILD_DIR=binutils-build

# Configure and build binutils
../$BINUTILS_NAME/configure \
  --with-sysroot=$SYSROOT \
  --target=$TARGET   \
  --prefix=$PREFIX   \
  --disable-nls      \
  --disable-multilib \
  --with-gnu-as      \
  --with-gnu-ld      \
make -j4 all
make install
cd ..

Note: Debian targets

If you're target sysroot is a recent debian distribution (>= wheezy) you'll have to apply one of the debian patches to binutils. Download it from here:

You then have to set DEB_TARGET_MULTIARCH before building binutils:

export DEB_TARGET_MULTIARCH=arm-linux-gnueabi

The correct value can be obtained by executing this on the target:

dpkg-architecture -qDEB_HOST_MULTIARCH

Download GDC

# Download GDC
rm -rf gdc
mkdir gdc
git clone gdc
cd gdc
git checkout gdc-4.8
cd ..

Download GCC

# Delete existing GCC source archive and download a new one
export GCC_NAME=gcc-4.8.2
rm -rf $GCC_NAME

# Extract GCC

Add GDC to GCC

# Add GDC to GCC
cd gdc
./ ../$GCC_NAME
cd ..

Build GCC

# Create GCC build directory
export GCC_BUILD_DIR=gcc-build

# Configure and build GCC
../$GCC_NAME/configure --target=$TARGET --prefix=$PREFIX \
  --enable-languages=d     \
  --disable-bootstrap      \
  --disable-libssp         \
  --disable-libgomp        \
  --disable-libmudflap     \
  --disable-multilib       \
  --disable-decimal-float  \
  --disable-libffi         \
  --disable-libmudflap     \
  --disable-libquadmath    \
  --disable-libssp         \
  --disable-nls            \
  --with-gnu-as            \
  --with-gnu-ld            \
make -j4
make install

Compiler GDC