%general-entities; ]> gcc-pass2 &gcc-version;
&gcc-url;
GCC-&gcc-version; - Pass 2 GCC tools, pass 2 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../chapter08/gcc.xml" xpointer="xpointer(/sect1/sect2[1]/para[1])"/> <segmentedlist> <segtitle>&buildtime;</segtitle> <segtitle>&diskspace;</segtitle> <seglistitem> <seg>&gcc-tmpp2-sbu;</seg> <seg>&gcc-tmpp2-du;</seg> </seglistitem> </segmentedlist> </sect2> <sect2 role="installation"> <title>Installation of GCC As in the first build of GCC, the GMP, MPFR, and MPC packages are required. Unpack the tarballs and move them into the required directory names: tar -xf ../mpfr-&mpfr-version;.tar.xz mv -v mpfr-&mpfr-version; mpfr tar -xf ../gmp-&gmp-version;.tar.xz mv -v gmp-&gmp-version; gmp tar -xf ../mpc-&mpc-version;.tar.gz mv -v mpc-&mpc-version; mpc For x86_64 target, set the default directory name for 64-bit libraries to lib. The command is unnecessary, but harmless for 32-bit x86. If you are building for another target, you may need to adjust the command for your target. sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 Fix an issue causing failure cross-compiling libstdc++: sed 's/gnu++17/& -nostdinc++/' \ -i libstdc++-v3/src/c++17/Makefile.in Override the building rule of libgcc and libstdc++ headers, to allow building these libraries with POSIX threads support: sed '/thread_header =/s/@.*@/gthr-posix.h/' \ -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in Create a separate build directory again: mkdir -v build cd build Before starting to build GCC, remember to unset any environment variables that override the default optimization flags. Now prepare GCC for compilation: ../configure \ --build=$(../config.guess) \ --host=$LFS_TGT \ --target=$LFS_TGT \ LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \ --prefix=/usr \ --with-build-sysroot=$LFS \ --enable-initfini-array \ --disable-nls \ --disable-multilib \ --disable-decimal-float \ --disable-libatomic \ --disable-libgomp \ --disable-libquadmath \ --disable-libssp \ --disable-libvtv \ --enable-languages=c,c++ The meaning of the new configure options: --with-build-sysroot=$LFS Normally, using --host ensures that a cross-compiler is used for building GCC, and that compiler knows that it has to look for headers and libraries in $LFS. But the build system of GCC uses other tools, which are not aware of this location. This switch is needed to have them find the needed files in $LFS, and not on the host. --target=$LFS_TGT As we are cross-compiling GCC, it's impossible to build target libraries (libgcc and libstdc++) with the compiled GCC binaries because these binaries won't run on the host distro. GCC building system will attempt to use the C and C++ compilers on the host distro as a workaround by default. It's not supported to build GCC target libraries with a different version of GCC, so using host compilers may cause building failure. This parameter ensures to build the libraries with GCC pass 1 and prevent the issue. LDFLAGS_FOR_TARGET=... Allow libstdc++ to use shared libgcc being built in this pass, instead of the static version built in GCC pass 1. This is needed for supporting C++ exception handling. --enable-initfini-array This option is automatically enabled when building a native compiler with a native compiler on x86. But here, we build with a cross compiler, so we need to explicitly set this option. Compile the package: make Install the package: make DESTDIR=$LFS install As a finishing touch, create a utility 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 -sv gcc $LFS/usr/bin/cc <para>Details on this package are located in <xref linkend="contents-gcc" role="."/></para> </sect2> </sect1>