5.13. Cross GCC-4.8.3 - Static

The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.

5.13.1. Installation of Cross GCC Compiler with Static libgcc and no Threads

Here we will compile GCC, as a cross-compiler that will create executables for our target architecture, statically so that it will not need to look for Glibc's startfiles, which do not yet exist in /tools. We will use this cross-compiler, plus the cross-linker we have just installed with Binutils, to compile Glibc. After Glibc is installed into /tools, we can rebuild GCC so that it will then be able to build executables that link against the libraries in /tools.

The following patch contains a number of updates to the 4.8.3 branch by the GCC developers:

patch -Np1 -i ../gcc-4.8.3-branch_update-1.patch

Make a couple of essential adjustments to GCC's specs to ensure GCC uses our build environment:

patch -Np1 -i ../gcc-4.8.3-specs-1.patch

Change the StartFile Spec so that GCC looks in /tools:

echo -en '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"\n' >> gcc/config/linux.h
echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h

We will create a dummy limits.h so the build will not use the one provided by the host distro:

touch /tools/include/limits.h

The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory:

mkdir -v ../gcc-build
cd ../gcc-build

Prepare GCC for compilation:

AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" \
    ../gcc-4.8.3/configure --prefix=/cross-tools \
    --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \
    --with-sysroot=${CLFS} --with-local-prefix=/tools \
    --with-native-system-header-dir=/tools/include --disable-nls \
    --disable-shared --with-mpfr=/cross-tools --with-gmp=/cross-tools \
    --with-isl=/cross-tools --with-cloog=/cross-tools --with-mpc=/cross-tools \
    --without-headers --with-newlib --disable-decimal-float --disable-libgomp \
    --disable-libmudflap --disable-libssp --disable-libatomic --disable-libitm \
    --disable-libsanitizer --disable-libquadmath --disable-threads \
    --disable-multilib --disable-target-zlib --with-system-zlib \
    --enable-languages=c --enable-checking=release

The meaning of the new configure options:


This specifies the system on which the cross-compiler is being built.


The purpose of this switch is to remove /usr/local/include from gcc's include search path. This is not absolutely essential, however, it helps to minimize the influence of the host system.


This switch ensures that GCC will search for the system headers in /tools/include and that host system headers will not be searched.


This tells GCC not to create a shared library.


Disables GCC from using the target's Libc when cross compiling.


This causes GCC to enable the inhibit_libc flag, which prevents libgcc from building code that uses libc support.


Disables support for the C decimal floating point extension.


These options prevent GCC from building a number of libraries that are not needed at this time.


This will prevent GCC from looking for the multi-thread include files, since they haven't been created for this architecture yet. GCC will be able to find the multi-thread information after the Glibc headers are created.


This tells GCC not to build the copy of Zlib in its source tree.


This tells GCC to link to the system-installed zlib instead of the one in its source tree.


This option ensures that only the C compiler is built.


This option selects the complexity of the internal consistency checks and adds error checking within the compiler.

Continue with compiling the package:

make all-gcc all-target-libgcc

The meaning of the new make options:

all-gcc all-target-libgcc

Compiles only the parts of GCC that are needed at this time, rather than the full package.

Install the package:

make install-gcc install-target-libgcc

Details on this package are located in Section 10.19.2, “Contents of GCC.”