Structure of the Cross-Toolchain

The term "cross-compiler" on this website means a broad concept: not only compiler itself (gcc, g++), but also anything it needs to work: linker, librarian, assemler (they are called binutils); standard header files and standard libraries, including ones required by C++ (glibc). According to GNU nomenclature, all these components together are called toolchain or cross-toolchain.

C99 standard defines two different levels of C compiler operation: freestanding and hosted. In the first case, compiler operates without standard header files and libc. This mode is used to build operating systems, different kind of bootloaders, and libc itself. In the second mode compiler depends on libc, for example it can check if printf() format string matches actual parameter types; it can replace memset(?,0,4) with simple 32-bit zero assignment; a code generated by hosted compiler should call _chkstk() when creating stack frame larger than size of page, it should properly set errno on FPU errors etc. For C++ dependency is even tighter, because compiler-generated code calls operator functions new and delete; and relies upon standard library to support exception handling and stack unwinding.

So, glibc depends on gcc, and gcc depends on glibc. To break this circual dependency, during building of cross-toolchain we first build a bootstrapping cross-compiler, which is able to work in freestanding mode only; then this bootstrapping compiler is used to build glibc, and when glibc is finally ready, gcc cross-compiler is built again, but this time it depends on glibc and able to operate in hosted mode in terms of C99 standard.

Also, glibc depends on Linux kernel. Kernel is being intensively developed, new system calls, structures, ioctl codes etc are added, corresponding declarations appear in glibc header files, and corresponding exported symbols appear in glibc shared libraries. glibc can be built in such way that it is compatible with old kernels, or one can "cut off the tail of compatibility", then glibc would be smaller and faster. Minimum kernel version required by glibc in order to run is specified when glibc is configured during build, also glibc build requires some kernel headers (not all of them) — Linux API headers.

Also, it is not possible to build glibc in MinGW environment (MinGW make utility is not powerful enough for this task). However, glibc can be successfully built in Cygwin environment. So, general plan of building cross-toolchain is as follows:


>> Read next section or buy already prepared cross-compiler (€10) to save your time.