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++ (eglibc). 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, eglibc depends on gcc, and gcc depends on eglibc. 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 eglibc, and when eglibc is finally ready, gcc cross-compiler is built again, but this time it depends on eglibc and able to operate in hosted mode in terms of C99 standard.

eglibc further complicates this situation, because it requires additional bootstrapping compiler tied to its headers in order to build the library itself. Two-phase eglibc cross-bootstrapping procedure using three cross-compilers as explained in this tutorial follows official documentation (EGLIBC.cross-building file).

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

Also, it is not possible to build eglibc in MinGW environment (MinGW make utility is not powerful enough for this task). However, eglibc 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.