Building a native version of Linaro GCC

draft r0

This page covers fetching, configuring, building, and installing a native version of Linaro GCC. Native means that the compiler runs on a machine and generates code for the same machine, such as running on ARM and generating code for ARM.

Linaro GCC is a drop-in replacement for FSF GCC and is configured and built in the same way. See http://gcc.gnu.org/install/build.html for more.

Have questions? Contact us on #linaro-tcwg on IRC or linaro-toolchain@lists.linaro.org.

Prerequisites

If you are on Debian/Ubuntu the easiest way of getting the prerequisites installed is using apt-get build-dep.

For Maverick or later, try:

  • apt-get build-dep gcc

For Lucid, try:

  • apt-get build-dep gcc-snapshot

For other Linux distributions, see the generic instructions at http://gcc.gnu.org/install/build.html.

Fetch the source

Fetch the tarball from the Linaro GCC downloads page:

Alternatively, fetch the latest revision from bzr:

  • bzr branch lp:gcc-linaro

Note that bzr branch may be unstable and is not tested to the same level as release tarballs.

Build and install

The earlier build-dep stage installed all of the prerequisites such as binutils, libgmp, and libmpfr. The next step is to configure and build the compiler. The instructions in this section are for building a Cortex-A9 ARM native compiler, i.e. one that runs on ARM and generates ARM code optimised for the A9. See the Variants section for information on building other versions including x86.

It's best to build in a different directory to the source code. Make a new build directory:

mkdir build
cd build

Configure Linaro GCC:

../gcc-linaro*/configure \
    --disable-bootstrap \
    --enable-languages=c,c++ \
    --with-mode=thumb --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=neon \
    --with-float=softfp \
    --prefix=$HOME/opt/gcc-linaro

Build and install:

make -j`getconf _NPROCESSORS_ONLN`
make install

You now have a ready-to-use compiler in $HOME/opt/gcc-linaro. Put $HOME/opt/gcc-linaro/bin in your patch and test by getting the version:

export PATH=$HOME/opt/gcc-linaro/bin
gcc --version
gcc (rob) 4.9.0 20130829 (experimental)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step by step

michaelh@ursa1:/scratch/michaelh$ mkdir src
michaelh@ursa1:/scratch/michaelh$ cd src/

michaelh@ursa1:/scratch/michaelh/src$ wget https://launchpad.net/gcc-linaro/4.8/4.8-2013.08/+download/gcc-linaro-4.8-2013.08.tar.xz
--2013-08-31 10:59:05--  https://launchpad.net/gcc-linaro/4.8/4.8-2013.08/+download/gcc-linaro-4.8-2013.08.tar.xz
Resolving launchpad.net (launchpad.net)... 91.189.89.222, 91.189.89.223
Connecting to launchpad.net (launchpad.net)|91.189.89.222|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://launchpadlibrarian.net/147734301/gcc-linaro-4.8-2013.08.tar.xz [following]
--2013-08-31 10:59:07--  https://launchpadlibrarian.net/147734301/gcc-linaro-4.8-2013.08.tar.xz
Resolving launchpadlibrarian.net (launchpadlibrarian.net)... 91.189.89.228, 91.189.89.229
Connecting to launchpadlibrarian.net (launchpadlibrarian.net)|91.189.89.228|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 69718936 (66M) [text/plain]
Saving to: 'gcc-linaro-4.8-2013.08.tar.xz'

michaelh@ursa1:/scratch/michaelh/src$ tar xaf gcc-linaro-4.8-2013.08.tar.xz 

michaelh@ursa1:/scratch/michaelh/src$ mkdir build
michaelh@ursa1:/scratch/michaelh/src$ cd build

michaelh@ursa1:/scratch/michaelh/src/build$ ../gcc-linaro*/configure \
>     --disable-bootstrap \
>     --enable-languages=c,c++ \
>     --with-mode=thumb --with-arch=armv7-a --with-tune=cortex-a9 \
>     --with-float=softfp --with-fpu=neon \
>     --prefix=$home/opt/gcc-linaro
checking build system type... armv7l-unknown-linux-gnueabi
checking host system type... armv7l-unknown-linux-gnueabi
checking target system type... armv7l-unknown-linux-gnueabi
checking for a bsd-compatible install... /usr/bin/install -c
checking whether ln works... yes
...

michaelh@ursa1:/scratch/michaelh/src/build$ make -j`getconf _NPROCESSORS_ONLN`
make[1]: entering directory `/scratch/michaelh/src/build'
mkdir -p -- ./libiberty
mkdir -p -- ./fixincludes
configuring in ./libiberty
configuring in ./fixincludes
configure: creating cache ./config.cache
checking whether to enable maintainer-specific portions of makefiles... no
checking for makeinfo... makeinfo --split-size=5000000
...

michaelh@ursa1:/scratch/michaelh/src/build$ make install
...
michaelh@ursa1:/scratch/michaelh/src/build$ export PATH=/home/michaelh/opt/gcc-linaro/bin:$PATH
michaelh@ursa1:/scratch/michaelh/src/build$ 

Variants

The configure statement above can be broken down into two groups.

Those that are build related:

  • --disable-bootstrap builds gcc in one pass using the host compiler. This is faster and uses less disk space, but doesn't test the compiler as well as a three stage bootstrap build.

  • --enable-languages=c,c++ builds the C and C++ compilers only, and skips the Fortran, Java, and Objective-C compilers. This is faster, but doesn't test the compiler as well.

  • --prefix=$home/opt/gcc-linaro sets where to install.

Those that set the default type of code generated:

  • --with-mode=thumb generates Thumb-2 code

  • --with-arch=armv7-a --with-tune=cortex-a9 generates code tuned for the A9 that still works on the A8

  • --with-fpu=neon generates VFP and NEON instructions for floating point and vectoriser related code

  • --with-float=softfp sets the floating point calling convention to match Ubuntu

To generate code that will work on all Cortex-a8 and above chips, use:

  • --with-mode=thumb --with-arch=armv7-a --with-fpu=vfpv3-d16

Note that NEON and VFPv3-D32 are optional. The Tegra2 in particular is VFP only. See http://wiki.debian.org/ArmHardFloatPort for more.

To build a compiler for x86_64 or i686, ommit the --with-* options:

../gcc-linaro*/configure \
    --disable-bootstrap \
    --enable-languages=c,c++ \
    --prefix=$home/opt/gcc-linaro

For these and other configurations, see:


CategoryHowTo

WorkingGroups/ToolChain/Using/GCCNative (last modified 2013-08-31 17:03:20)