%general-entities; ]> gcc &gcc-version;
&gcc-url;
GCC-&gcc-version; - Pass 2 GCC tools, pass 2 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../chapter06/gcc.xml" xpointer="xpointer(/sect1/sect2[1]/para[1])"/> <segmentedlist> <segtitle>&buildtime;</segtitle> <segtitle>&diskspace;</segtitle> <seglistitem> <seg>&gcc-ch5p2-sbu;</seg> <seg>&gcc-ch5p2-du;</seg> </seglistitem> </segmentedlist> </sect2> <sect2 role="installation"> <title>Installation of GCC Our first build of GCC has installed a couple of internal system headers. Normally one of them, limits.h will in turn include the corresponding system limits.h header, in this case, /tools/include/limits.h. However, at the time of the first build of gcc /tools/include/limits.h did not exist, so the internal header that GCC installed is a partial, self-contained file and does not include the extended features of the system header. This was adequate for building the temporary libc, but this build of GCC now requires the full internal header. Create a full version of the internal header using a command that is identical to what the GCC build system does in normal circumstances: cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h For x86 machines, a bootstrap build of GCC uses the compiler flag. Non-bootstrap builds omit this flag by default, and the goal should be to produce a compiler that is exactly the same as if it were bootstrapped. Apply the following sed command to force the build to use the flag: cp -v gcc/Makefile.in{,.tmp} sed 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \ > gcc/Makefile.in Once again, change the location of GCC's default dynamic linker to use the one installed in /tools. for file in \ $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h) do cp -uv $file{,.orig} sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \ -e 's@/usr@/tools@g' $file.orig > $file echo ' #undef STANDARD_STARTFILE_PREFIX_1 #undef STANDARD_STARTFILE_PREFIX_2 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/" #define STANDARD_STARTFILE_PREFIX_2 ""' >> $file touch $file.orig done As in the first build of GCC it requires the GMP, MPFR and MPC packages. Unpack the tarballs and move them into the required directory names: tar -Jxf ../mpfr-&mpfr-version;.tar.xz mv -v mpfr-&mpfr-version; mpfr tar -Jxf ../gmp-&gmp-version;.tar.xz mv -v gmp-&gmp-version; gmp tar -zxf ../mpc-&mpc-version;.tar.gz mv -v mpc-&mpc-version; mpc Create a separate build directory again: mkdir -v ../gcc-build cd ../gcc-build Before starting to build GCC, remember to unset any environment variables that override the default optimization flags. Now prepare GCC for compilation: CC=$LFS_TGT-gcc \ AR=$LFS_TGT-ar \ RANLIB=$LFS_TGT-ranlib \ ../gcc-&gcc-version;/configure \ --prefix=/tools \ --with-local-prefix=/tools \ --with-native-system-header-dir=/tools/include \ --enable-clocale=gnu \ --enable-shared \ --enable-threads=posix \ --enable-__cxa_atexit \ --enable-languages=c,c++ \ --disable-libstdcxx-pch \ --disable-multilib \ --disable-bootstrap \ --disable-libgomp \ --with-mpfr-include=$(pwd)/../gcc-&gcc-version;/mpfr/src \ --with-mpfr-lib=$(pwd)/mpfr/src/.libs The meaning of the new configure options: --enable-clocale=gnu This option ensures the correct locale model is selected for the C++ libraries under all circumstances. If the configure script finds the de_DE locale installed, it will select the correct gnu locale model. However, if the de_DE locale is not installed, there is the risk of building Application Binary Interface (ABI)-incompatible C++ libraries because the incorrect generic locale model may be selected. --enable-threads=posix This enables C++ exception handling for multi-threaded code. --enable-__cxa_atexit This option allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects. This option is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI, and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions. --enable-languages=c,c++ This option ensures that both the C and C++ compilers are built. --disable-libstdcxx-pch Do not build the pre-compiled header (PCH) for libstdc++. It takes up a lot of space, and we have no use for it. --disable-bootstrap For native builds of GCC, the default is to do a "bootstrap" build. This does not just compile GCC, but compiles it several times. It uses the programs compiled in a first round to compile itself a second time, and then again a third time. The second and third iterations are compared to make sure it can reproduce itself flawlessly. This also implies that it was compiled correctly. However, the LFS build method should provide a solid compiler without the need to bootstrap each time. Compile the package: make Install the package: make install As a finishing touch, create a symlink. Many programs and scripts run cc instead of gcc, which is used to keep programs generic and therefore usable on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system administrator free to decide which C compiler to install: ln -vs gcc /tools/bin/cc At this point, it is imperative to stop and ensure that the basic functions (compiling and linking) of the new toolchain are working as expected. To perform a sanity check, run the following commands: echo 'main(){}' > dummy.c cc dummy.c readelf -l a.out | grep ': /tools' If everything is working correctly, there should be no errors, and the output of the last command will be of the form: [Requesting program interpreter: /tools/lib/ld-linux.so.2] Note that /tools/lib, or /tools/lib64 for 64-bit machines appears as the prefix of the dynamic linker. If the output is not shown as above or there was no output at all, then something is wrong. Investigate and retrace the steps to find out where the problem is and correct it. This issue must be resolved before continuing on. First, perform the sanity check again, using gcc instead of cc. If this works, then the /tools/bin/cc symlink is missing. Install the symlink as per above. Next, ensure that the PATH is correct. This can be checked by running echo $PATH and verifying that /tools/bin is at the head of the list. If the PATH is wrong it could mean that you are not logged in as user lfs or that something went wrong back in Once all is well, clean up the test files: rm -v dummy.c a.out <para>Details on this package are located in <xref linkend="contents-gcc" role="."/></para> </sect2> </sect1>