RPi Linaro GCC Compilation

Overview
This page explains how to build yourself a version of Linaro GCC specifically for building software for the RPi.

From the Linaro website: "Linaro GCC is performance focused branch of the current GCC stable release and includes backports of the improvements and bug fixes that Linaro and others have done upstream"

Requirements
This process should be carried out on the Linux system you wish to compile RPi software on. Therefore, you will require a reasonably powerful computer (preferably 64bit). If you are running on Windows, it is possible to use a linux virtual machine running on Virtualbox. The only software required is crosstool-NG (plus its dependencies).

Procedure
The whole process takes about an hour on a dual-core 2.8GHz 64-bit AMD system using an 8Mbit ADSL connection. NOTE: This procedure was tested on 24th November 2012 using crosstool-ng 1.17.0. It may not be accurate for newer versions of the software.

Install crosstool-NG
tar -xjvf crosstool-ng-1.17.0.tar.bz2
 * Download the crosstool-NG source (from http://crosstool-ng.org/).
 * Extract the source tarball into your home directory:
 * Or clone a more recent version from git, I saw this newest version work as well:

git clone https://github.com/crosstool-ng/crosstool-ng.git cd crosstool-ng git checkout 1.22

./configure --prefix=/opt/crosstool-ng-1.17.0
 * Change to the extracted directory, then configure it. You should specify an installation prefix to keep it separate from the OS in case you want to run multiple versions - we are using /opt/crosstool-ng-1.17.0 in this example:

make make install PATH=$PATH:/opt/crosstool-ng-1.17.0/bin
 * If configure fails due to missing dependencies, install them for your platform using the package manager (i.e. yum install, apt-get install, etc.)
 * during the build you might need packages for expat, libexpat1-dev, python-dev
 * When configure completes successfully, make and install it:
 * Add the crosstool-NG bin folder to your path. The easiest way to do this is add it to PATH in your .profile, for example:

Build GCC Linaro
ct-ng menuconfig ldd
 * Make a new directory in your home directory where you want to run crosstool-NG, then change to it.
 * Configure crosstool-NG:
 * Set the following options (derived from the arm-bcm2708hardfp-linux-gnueabi build on GitHub):
 * Paths & Misc:
 * Check "Try features marked as EXPERIMENTAL"
 * Set "Prefix directory" to whereever you want the finished toolchain to be placed (e.g. /home/ /crosscompile)
 * Set "Number of parallel jobs" to be the number of processor cores in your system x1.5
 * Target options:
 * Set "Target architecture" to "ARM"
 * Set "Endianness" to "Little endian"
 * Set "Bitness" to "32-bit"
 * Set "Architecture level" to "armv6zk"
 * Set "Emit assembly for CPU" to "arm1176jzf-s"
 * Set "Tune for CPU" to "arm1176jzf-s"
 * Set "Use specific FPU" to "vfp"
 * Set "Floating point" to "hardware (FPU)"
 * Set "Default instruction set mode" to "arm"
 * Check "Use EABI"
 * General toolchain:
 * Set "Tuple's vendor string" to "rpi" - you can choose whatever you like here and it will appear in the compiler filenames.
 * Operating system:
 * Set "Target OS" to "linux"
 * Set "Linux kernel version" to match that running on the RPI (it was tested with the 3.6 branch patched to version 3.6.3)
 * Binary utilities:
 * Set "Binary format" to "ELF"
 * Set "binutils version" to "2.22"
 * C compiler:
 * Check "Show linaro versions"
 * Set "gcc version" to "linaro-4.7-2012.10"
 * Check "C++"
 * Set "gcc extra config" to "--with-float=hard"   (Note: see "Discussion" page)
 * Check "Link libstdc++ statically into gcc binary"
 * C-library:
 * Set "C library" to "eglibc", or, as eglibc gets deprecated, glibc from version 2.19 up.
 * Set "eglibc version" to "2_13", however, to reduce the size of your executables you could also try to match it with the libc already present on the Pi and select a custom libc-version here, for example the exact commit your libc was build from if you can reveal that. The major version of libc can be made visible with

ct-ng build
 * Build it:
 * All the required source will now be downloaded and built - exact times vary according to processing power and internet connection speed.

Configure system to use new compiler
Your compiler will be located in /home/ /crosscompile (or whereever you specified in the configuration). You can choose to move it to another location (e.g. /opt/arm) if you want to. Then, add that location to your PATH: PATH=$PATH:/opt/arm/bin:/opt/crosstool-ng-1.17.0/bin

Now if you run: arm-rpi-linux-gnueabi-gcc -v you should get the version information from your new build. It should end something like: gcc version 4.7.3 20121001 (prerelease) (crosstool-NG 1.17.0)

By the way, this manual also works for the newest stable gcc-linaro-5.3-2016.05 at http://releases.linaro.org/components/toolchain/gcc-linaro/5.3-2016.05/