A toolchain is a suite of tools used in a serial manner to develop software applications and operating systems. The GNU toolchain is a broad collection of programming tools produced by the GNU Project.
The GNU toolchain plays a vital role in development of Linux, some BSD systems, and more importantly software for embedded systems. Before we delve into the components of GNU toolchain, let’s understand the general aspects of a toolchain.
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 produce binary code (executables) to run on a different architecture (e.g. ARM). This is called cross compilation and and is the typical way of building embedded software.
When talking about toolchains, we 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.
The projects included in the GNU toolchain are,
GNU Compiler Collection (GCC)
The GNU Compiler Collection (GCC) is a compiler system supporting various programming languages. Originally named the GNU C Compiler, when it only handled the C programming language, GCC 1.0 was released in 1987. It was extended to compile C++ in December of that year. Front ends were later developed for Objective-C, Objective-C++, Fortran, Java, Ada, and Go among others.
As well as being the official compiler of the GNU operating system, GCC has been adopted as the standard compiler by many other modern Unix-like computer operating systems, including the BSD family, although FreeBSD and OS X have moved to the LLVM system. Versions are also available for Windows and other operating systems; GCC can compile code for Android and iOS.
GCC has been ported to a wide variety of processor architectures, and is widely deployed as a tool in the development of both free and proprietary software. GCC is also available for most embedded platforms, including Symbian (called gcce), AMCC, and Freescale Power Architecture-based chips. The compiler can target a wide variety of platforms, including video game consoles such as the PlayStation 2 and Dreamcast.
As a matter of fact, The GNU Binutils are 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.
GNU Build System
The GNU Build System, also known as the Autotools, is a suite of programming tools designed to assist in making source code packages portable to many Unix-like systems.
It can be difficult to make a software program portable: the C compiler differs from system to system; certain library functions are missing on some systems; header files may have different names. One way to handle this is to write conditional code, with code blocks selected by means of preprocessor directives (
#ifdef); but because of the wide variety of build environments this approach quickly becomes unmanageable. Autotools is designed to address this problem more manageably.
Autotools is part of the GNU toolchain and is widely used in many free software and open source packages.
The GNU Build System makes it possible to build many programs using a two-step process:
- configure : A shell script that goes and detects what is available in the environment and/or what is desired by the user to determine how to build the software.
- make : Uses timestamps to rebuild modules.
Make is a build automation tool that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program. Though integrated development environments and language-specific compiler features can also be used to manage a build process, Make remains widely used, especially in Unix.
Besides building programs, Make can be used to manage any project where some files must be updated automatically from others whenever the others change.
The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger for the GNU operating system. However, its use is not strictly limited to the GNU operating system; it is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C,C++, Objective-C, Free Pascal, Fortran, Java and partially others.
GNU m4 is an implementation of the m4 macro preprocessor. Developed by the GNU Project, GNU m4 is designed to avoid many kinds of arbitrary limits found in traditional m4 implementations, such as maximum line lengths, maximum size of a macro and number of macros. Removing such arbitrary limits is one of the stated goals of the GNU Project.
The GNU Autoconf package makes extensive use of the features of GNU m4.
GNU bison, commonly known as Bison, is a parser generator that is part of the GNU Project. Bison reads a specification of a context-free language, warns about any parsing ambiguities, and generates a parser (either in C, C++, or Java) which reads sequences of tokens and decides whether the sequence conforms to the syntax specified by the grammar. Bison by default generates LALR parsers but can also create GLR parsers.
In POSIX mode, Bison is compatible with yacc, but also has several improvements over this earlier program. flex, an automatic lexical analyser, is often used with Bison, to tokenise input data and provide Bison with tokens.