Toolchains

A toolchain is a set of distinct software development tools that are linked (or chained) together by specific stages such as GCC, binutils and glibc (a portion of the GNU Toolchain). Optionally, a toolchain may contain other tools such as a debugger or a compiler for a specific programming language, such as C++. Quite often, the toolchain used for embedded development is a cross toolchain, or more commonly known as a cross compiler. All the programs (like GCC) run on a host system of a specific architecture (such as x86), but they produce binary code (executables) to run on a different architecture (for example, ARM). This is called cross compilation and is the typical way of building embedded software. It is possible to compile natively, running GCC on your target. Before searching for a prebuilt toolchain or building your own, it's worth checking to see if one is included with your target hardware's Board Support Package (BSP) if you have one.

Introduction
When talking about toolchains, one must distinguish three different machines:
 * The build machine, on which the toolchain is built
 * The host machine, on which the toolchain is executed
 * The target machine, for which the toolchain generates code

From these three different machines, we distinguish four different types of toolchain building processes:
 * A native toolchain, as can be found in normal Linux distributions, has usually been compiled on x86, runs on x86 and generates code for x86.
 * A cross-compilation toolchain, which is the most interesting toolchain type for embedded development, is typically compiled on x86, runs on x86 and generates code for the target architecture (be it ARM, MIPS, PowerPC or any other architecture supported by the different toolchain components)
 * A cross-native toolchain, is a toolchain that has been built on x86, but runs on your target architecture and generates code for your target architecture. It's typically needed when you want a native GCC on your target platform, without building it on your target platform.
 * A Canadian build is the process of building a toolchain on machine A, so that it runs on machine B and generates code for machine C. It's usually not really necessary.

Binutils
The GNU Binutils is the first component of a toolchain. The GNU Binutils contains two very important tools:
 * as, the assembler, that turns assembly code (generated by GCC) to binary.
 * ld, the linker, that links several object code into a library, or an executable.

Binutils also contains a couple of other binary file manipulation or analysis tools, such as objcopy, objdump, nm, readelf, strip, and so on. The Binutils website has some documentation on all these tools.

C, C++, Java, Ada, Fortran, Objective-C compiler
The second major component of a toolchain is the compiler. In the embedded Linux, the only realistic solution today is GCC, the GNU Compiler Collection. Nowadays, as input, it not only supports C, but also C++, Java, Fortran, Objective-C and Ada. As output, it supports a very wide range of architectures.

C library
The C library implements the traditional POSIX API that can be used to develop userspace applications. It interfaces with the kernel through system calls and provides higher-level services.

Realistically, there are nowadays two options for the C Library:
 * glibc is the C library from the GNU project. It's the C library used by virtually all desktop and server GNU/Linux systems. It's feature-full, portable, complies to standards, but a bit bloated.
 * Embedded GLIBC (EGLIBC) is a variant of the GNU C Library (GLIBC) optimized for embedded systems. Its goals include reduced footprint, support for cross-compiling and cross-testing, while maintaining source and binary compatibility with GLIBC. The project is discontinued.
 * uClibc is an alternate C library, which features a much smaller footprint. This library can be an interesting alternative if flash space and/or memory footprint is an issue. However, the space advantages gained using uClibc are becoming less important as the price of memory and flash continues to drop. It is still useful C library for embedded systems without an MMU.
 * uClibc-ng is a spin-off of uClibc C library. The main goal of the spin-off is to do regular releases and do a lot of automatic runtime testing.
 * musl New standard C library. musl is lightweight, fast, simple, free, and strives to be correct in the sense of standards-conformance and safety.

The C library has a special relation with the C compiler, so the choice of the C library must be done when the toolchain is generated. Once the toolchain has been built, it is no longer possible to switch to another library.

Debugger
The debugger is also usually part of the toolchain, as a cross-debugger is needed to debug applications running on your target machine. In the embedded Linux world, the typical debugger is GDB.

Lazarus and Free Pascal
Free Pascal is a professional but free 32 bit / 64 bit compiler for Pascal and Object Pascal. It supports a wide variety of processors and Linux distributions including the Raspberry Pi.

The Free Pascal toolchain is widely independent from GCC and other external tools. Major components are the Free Pascal compiler (FPC), a command-line tool, a text-mode IDE and, as an optional component, Lazarus, a full-featured GUI-based IDE. FPCUnit is a framework allowing for unit-testing.

On most platforms Free Pascal makes use of the GDB debugger.

http://elinux.org/Tiny6410

http://elinux.org/Micro2440

http://elinux.org/Mini210

http://elinux.org/Tiny210

Getting a toolchain
There are several ways to get a toolchain:
 * Get a prebuilt toolchain, either from a vendor such as CodeSourcery, or probably inside the Board Support Package shipped with your hardware platform by the vendor. This is the easiest solution, as the toolchain is already built, and has supposedly been tested by the vendor. The drawback is that you don't have flexibility on your toolchain features (which C library? hard-float or soft-float? which ABI?)
 * Build a toolchain on your own. However, this can be a real pain. There are version dependency issues, patches required to make something work, etc., etc. Check out this (obsolete) build matrix for crosstool and look at all the red "failed" entries.
 * Build a toolchain using an automated tool. The community has built several scripts or more elaborate systems to ease the process of building a toolchain. This way, the recipes and patches needed to build a toolchain made of particular versions of the various components are shared and easily available.

Bootlin
Since June 2017, Bootlin is offering free pre-built toolchains on toolchains.bootlin.com, supporting more than 38 CPU architecture variants, and three C libraries: GNU libc, uClibc-ng and musl. More details...

CodeSourcery
CodeSourcery used to release free cross-compiling toolchains for the major embedded architectures.

In 2010, CodeSourcery was acquired by Mentor Graphics, who now sells the materials described here as part of their Sourcery Tools Services product line. Indeed, the above link (to codesourcery.com) now takes you to Mentor Graphics' web site.

Now the free toolchains binaries they maintain only support MIPS, NIOS-II, AMD64 and Hexagon. Old versions with ARM support are still available through build systems (Buildroot...), which still know where to find them.

Linaro (ARM)
Linaro releases optimized toolchains for recent ARM CPUs (Cortex A8, A9...). These include Linaro's latest contributions to mainline GCC, but backported to stable GCC versions for immediate use by product developers. Linaro actually hires CodeSourcery people to improve ARM toolchains, so the ARM toolchains that you get with Linaro should be at least as good as the CodeSourcery ones.

Native toolchains are available through the standard GCC toolchain in Ubuntu. Cross toolchains from Linaro are available to Ubuntu users through special packages:

sudo add-apt-repository ppa:linaro-maintainers/toolchain sudo apt-get install gcc-arm-linux-gnueabi

Now find out the path and name of the cross-compiler executable by looking at the contents of the package:

dpkg -L gcc-arm-linux-gnueabi

Arch Linux users can install: yaourt -S gcc-linaro-arm-linux-gnueabihf

Linaro also makes source releases which can then be used by any build system (see below).

musl.cc
musl.cc provides static, musl-based cross- and native- GCC toolchains targeting a wide range of Linux- and Windows-based platforms. Toolchains run on Linux, macOS, Windows, and Solaris. Please note that this is a community-run website and is not officially endorsed by the musl project or its authors.

These toolchains include gcc, g++, and gfortran by default and feature very recent versions of GCC and its dependencies (e.g., binutils, MPFR, MPC, ...). GCC 5, 6, 7, 8, 9, 10, and 11 are also available. Linux-targeting toolchains include Linux headers, and are available for ARM, Motorola 68000, MIPS, OpenRISC, PowerPC, RISC-V, S/390, SuperH, and x86-based.

Tarballs can be searched and downloaded directly from the command line using curl (or wget if you set your User Agent to contain the string ):

$ curl -s musl.cc | grep mips64 https://musl.cc/mips64-linux-musl-cross.tgz https://musl.cc/mips64-linux-musl-native.tgz ...

In addition to the tarballs on this site, all cross-compilers are offered as i686-hosted Docker images (which run on 32- and 64-bit x86 systems) and are based on Alpine Linux. For example,

docker pull muslcc/i686:aarch64-linux-musl

All scripts, source code, instructions, and configuration files needed to reproduce these toolchains are supplied via links on the homepage.

DENX ELDK
The DENX Embedded Linux Development Kit (ELDK) provides a complete and powerful software development environment for embedded and real-time systems. It is available for ARM, PowerPC and MIPS processors and consists of:


 * Cross Development Tools (Compiler, Assembler, Linker etc.) to develop software for the target system.
 * Native Tools (Shell, commands and libraries) which provide a standard Linux development environment that runs on the target system.
 * Firmware (U-Boot) that can be easily ported to new boards and processors.
 * Linux kernel including the complete source-code with all device drivers, board-support functions, etc.
 * Xenomai - RTOS Emulation framework for systems requiring hard real-time responses.
 * SELF (Simple Embedded Linux Framework) as fundament to build your embedded systems on.

All components of the ELDK are available for free with complete source code under GPL and other Free Software Licenses. Also, detailed instructions to rebuild all the tools and packages from scratch are included.

The ELDK can be downloaded for free from several mirror sites or ordered on CD-ROM for a nominal charge (99 Euro). To order the CD please contact office@denx.de.

Detailed information about the ELDK is available here.

Scratchbox
Scratchbox provides toolchains for ARM and x86 target architectures (with PowerPC, MIPS and CRIS in experimental stages, but they aren't making real progress for the past many years, so Scratchbox should probably be considered ARM and x86 only). Both uClibc and glibc are supported.

Scratchbox simplifies cross compiling software which is built using GNU autotools - Code tests performed by configure are run in an emulator or even on the actual target. The toolchains scratchbox ships with are based on GCC 3.3 and as such are quite old, but stable and well tested. It should be pointed out that scripts to build custom toolchains are also provided with scratchbox allowing more recent GCC versions to be used.

Fedora ARM
Fedora ARM is a try to port Fedora to ARM. It provides some tools as an ARM toolchain packaged in RPM format. Link: Fedora ARM

Debian cross-tools packages
For Debian users, the toolchains problem is fairly reliably solved.

For a Debian-based box, just install pre-built cross toolchains from Debian experimental.

Targets include nearly all Debian-supported architectures. As of this writing the supported compiler is GCC 4.9. You can get older unsupported compilers from emdebian.

You will need to add the target architecture to your list of installable architectures. For example,

dpkg --add-architecture armhf apt-get update apt-get install gcc-arm-linux-gnueabihf

Free Pascal
Free Pascal is available for several processor architectures from http://www.freepascal.org, the Lazarus IDE from http://www.lazarus.freepascal.org.

Buildroot
Buildroot is a complete build system based on the Linux kernel configuration system and supports a wide range of target architectures. It generates root file system images ready to be written to flash. In addition to having a huge number of packages which can be compiled into the image, it also generates a cross toolchain to build those packages from source. Even if you don't want to use buildroot for your root filesystem, it is a useful tool for generating a toolchain. Buildroot supports uClibc-ng, glibc and musl.

OpenADK
OpenADK is a complete build system based on the Linux kernel configuration system and supports a wide range of target architectures. It is similar to buildroot. It generates root file system images ready to be written to flash. In addition to having a huge number of packages which can be compiled into the image, it also generates a cross toolchain to build those packages from source. Even if you don't want to use OpenADK for your root filesystem, it is a useful tool for generating a toolchain. OpenADK supports glibc, uClibc-ng, newlib and musl.

Crossdev (Gentoo)
Crossdev is specific to developers using Gentoo for their development PCs. It is a script which generates a cross toolchain using the portage build scripts for GCC, etc. There are numerous architectures which are supported and both uClibc and glibc toolchains can be built. Link: Gentoo Crossdev info

Crosstool-NG
Crosstool-NG is a well-maintained fork of crosstool, targeted at easier configuration, re-factored code, and a learning base on how toolchains are built, with support for both uClibc and glibc, for debug tools (gdb, strace, dmalloc, etc.), and a wide range of versions for each tools. Different target architectures are supported as well. It offers a kernel-like configuration system to select the different configuration options of the toolchain (component versions, component configuration, etc.). Crosstool-NG has an active and responsive user and developer community.

Crossdev/tsrpm (Timesys)
Crossdev is a project sponsored by Timesys, completely unrelated to the Gentoo cross toolchain generation system. The projects main focus is on a tool called tsrpm which is used to build cross development toolchains and generate cross-compiled software packages. Currently only x86 and select PowerPC architectures are supported. Link: Crossdev

EmbToolkit
EmbToolkit is the first toolchain building system giving the choice to generate GCC or llvm/clang based toolchain. EmbToolkit supports use of eglibc, glibc or uClibc as C Library and musl C library is also planned at time of writing. EmbToolkit can be used to generate only a toolchain (usable in a external project), but it is also possible to generate various root filesystems.

OSELAS.Toolchain
The OSELAS.Toolchain project aims at supplying a complete build system for recent GNU toolchains. It uses the PTXdist build system, a userland build system based on Kconfig. The current version 1.99.3.1 of OSELAS.Toolchain contains support for ARM, x86, AVR, MIPS and PowerPC. In addition, there are toolchains for bare metal platforms like Cortex-M3 and AVR-8-Bit. OSELAS.Toolchain contains some further goodies like gcj support for ARM and MinGW support for x86. Link: OSELAS.Toolchain Link: PTXdist

Bitbake
Bitbake is the tool used by OpenEmbedded. The best way to get started is probably by just building an existing distribution that uses openembedded (for example, Ångström, see http://www.angstrom-distribution.org/building-ångström for details).

ARM
See ARMCompilers

= Legacy Information (pre-2010) = This section has links to various old tool chains and tool chain resources, which might be of interest. In general, this information was last updated about 2010, and some information in this section might duplicate information above.

Crosstool
Jim Wilson said the following on LKML: I recommend Dan Kegel's page for anyone trying to build a cross compiler to linux. See http://kegel.com/crosstool This isn't very hard to follow, and it gives you a properly configured and built gcc/glibc for the target.

The University of Szeged has been doing benchmarking of GNU tools across processor architectures, but including ARM. There's a site at http://www.inf.u-szeged.hu/gcc-arm/

Debian
Debian packages which support cross-compilation can be found at emdebian.org

** http://emdebian.org/crosstools.html ** http://wiki.debian.org/EmdebianToolchain

There are also (binary) library/headers packages, from Debian packages for the target architectures, which support cross-compilation.

dpkg-cross is a tool for installing libraries and headers for cross compiling in a way similar to dpkg. See:
 * http://packages.debian.org/testing/utils/dpkg-cross

Mailing list: debian-embedded@lists.debian.org IRC: #emdebian @ OFTC

ARM
You may wish to examine the following mailing list: linux-arm-toolchain@lists.arm.linux.org.uk

Several ARM toolchain combo's have been discussed often in the recent past. List archives are at: http://lists.arm.linux.org.uk/pipermail/linux-arm-toolchain/

Building GCC 4.0 from scratch

 * How to build a gcc 4.0 ARM toolchain from scratch: http://linux.omap.com/pipermail/linux-omap-open-source/2005-November/005665.html

CodeSourcery
You can now download ARM GNU tool chains (source and pre-built releases) from http://www.codesourcery.com where you will have regular builds of the tool chain, integrating support for new core functionality. The current release include support for ARM v6 cores (binutils) and VFP support.

handhelds.org reference
Kristian S�rensen wrote:

We have had success using the ARM toolchain specified by handhelds.org. There are both a binary available and a script for building your own.

A description of the toolchain and how to use it on a HP iPAQ is available in our Master's Thesis in Appendix A (p 92). This may be downloaded here: http://prdownloads.sourceforge.net/umbrella/Umbrella.pdf?download

Jamey Hicks wrote: The handhelds.org toolchain binaries, sources, and build script are at ftp://ftp.handhelds.org/pub/linux/arm/toolchain/

The build script is actually crosstool 0.27, with slight changes I made to it for the particular selection of binutils, gcc, and glibc versions.

Greg Ungerer ARM multi-lib toolchain build
Greg writes:

Maybe this is interresting to some. This is the instructions I put together for building a gcc-3.3.4 based ARM toolchain that is multi-lib-ed to be able to build for all of big and little endian targets, and using either soft or hard float.

http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/build-arm-linux-3.4.4

Its nice just having one tool chain for all those variants (I generate code for both little and big endian targets on a daily basis, and everything from small non-mmu ARM7 cores to xscale, all with the same tool chain).

Toolchain downloads
Some member companies have provided sources and binaries for toolchains they are using for forum work.

/\ These are all provided on terms of: "use at your own risk".

ARM and MIPS toolchains from Sony
- Note that this information is now out of date (for linux-2.4). - How to install - INSTALL.txt

- ARM toolchain - arvv4tl-celf-linux-toolchain.tar.gz (22 MB) - MIPS toolchain - mipsel-celf-linux-toolchain.tar.gz (25 MB)

- Sources: - gcc-3.2.3.tar.gz (27 MB) - gcc-patch.tar.gz (29 KB) - binutils-2.12.1.tar.bz2 (9 MB) - binutils-patch.tar.gz (14 KB)

i386 and SH toolchains from Lineo Solutions
- i386 toolchain tools_i686_RPMS.tar.gz (28 MB) - SH toolchain tools_sh4_RPMS.tar.gz (24 MB)

- Sources: - tools_i686_SRPMS.tar.gz (43 MB) - tools_sh4_SRPMS.tar.gz (40 MB)

- Packages for user-space programs: - Userland_i686_RPMS.tar.gz (41 MB) - Userland_sh4_RPMS.tar.gz (47 MB) - Userland_SRPMS.tar.gz (123 MB)

ARM/Thumb toolchain from Panasonic
- Software information regarding this package - PMCinformation.txt - How to install - PMCinstall.txt - Sources: - cross-gcc-3.3.1-7.0.24.0500655.src.rpm(31 MB) - PMC.patch (8 KB) - Binaries: - mvlcee3.1_thumb.for_export_050531.tgz (388 MB)

Distributions
Some distributions provide toolchains as part of their offerings. The following free/unsupported distributions are available.

Snap Gear
SnapGear provides a uCLinux distribution CD. On the web page, there is source and binaries for toolchains for several architectures.

See http://www.uclinux.org/pub/uClinux/dist

ELDK
The Embedded Linux Development Kit (ELDK) is an Open Source project maintained by DENX Software Engineering. It supports PowerPC, ARM and MIPS systems. In addition to the usual cross-development tools, the ELDK comes with a pretty complete native development environment and some other extensions, like support for the Xenomai Real-Time and RTOS Emulation Framework.

See http://www.denx.de/twiki/bin/view/DULG/ELDK

Open Embedded
There is a project called OpenEmbedded which aims at making a free embedded distribution (with build system).

See http://openembedded.org and the OE wiki

Tux Screen
TuxScreen and uClibc projects have build systems that generate complete toolchains, jffs2 filesytem images, bootloader etc.
 * http://TuxScreen.net/
 * http://cvs.sourceforge.net/viewcvs.py/tuxscreen/buildroot-tux/

uClibc

 * http://uClibc.org/
 * http://buildroot.uclibc.org/

Toolchain resources
Here are random pointers to some resources:


 * CrossTools package
 * ftp://ftp.arm.linux.org.uk/pub/linux/arm/toolchain/
 * http://www.emdebian.org/crossdev.html
 * http://www.lart.tudelft.nl/lartware/compile-tools/
 * http://handhelds.org/z/wiki/Toolchains
 * ftp://ftp.handhelds.org/pub/linux/arm/toolchain/
 * ftp://ftp.handhelds.org/pub/linux/arm/toolchain/source/
 * ftp://ftp.handhelds.org/pub/linux/arm/toolchain/jacques
 * ftp://ftp.handhelds.org/pub/linux/arm/toolchain/monmotha/
 * www.mspy.com
 * http://www.armlinux.org/docs/toolchain/toolchHOWTO/x43.html
 * http://buildroot.uclibc.org/
 * http://www.denx.de/re/ELDK.html
 * http://cvs.gentoo.org/~zwelch/xcompile.html