Замечание

There are frequent misunderstandings about this chapter. The
procedures are the same as every other chapter as explained
earlier (Package build
instructions). First extract the gcc tarball from the sources
directory and then change to the directory created. Only then
should you proceed with the instructions below.

In case the above seems hard to follow, let's break it down a bit.
First we find all the files under the gcc/config directory that are named either
linux.h, linux64.h or sysv4.h. For each file found, we copy it to a
file of the same name but with an added suffix of «.orig». Then the first sed expression prepends
«/tools» to every instance of
«/lib/ld», «/lib64/ld» or «/lib32/ld», while the second one replaces hard-coded
instances of «/usr». Next, we add our
define statements which alter the default startfile prefix to the
end of the file. Note that the trailing «/» in «/tools/lib/» is
required. Finally, we use touch to update the timestamp on
the copied files. When used in conjunction with cp -u, this prevents unexpected
changes to the original files in case the commands are
inadvertently run twice.

GCC doesn't detect stack protection correctly, which causes
problems for the build of Glibc-2.17, so fix that by issuing the
following command:

sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure

Do not build the .info files. They are not needed here and are
broken with the current version of makeinfo.

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

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

Since a working C library is not yet available, this ensures
that the inhibit_libc constant is defined when building
libgcc. This prevents the compiling of any code that requires
libc support.

--without-headers

When creating a complete cross-compiler, GCC requires
standard headers compatible with the target system. For our
purposes these headers will not be needed. This switch
prevents GCC from looking for them.

--with-local-prefix=/tools

The local prefix is the location in the system that GCC will
search for locally installed include files. The default is
/usr/local. Setting this to
/tools helps keep the host
location of /usr/local out of
this GCC's search path.

--with-native-system-header-dir=/tools/include

By default GCC searches /usr/include for system headers. In
conjunction with the sysroot switch, this would translate
normally to $LFS/usr/include.
However the headers that will be installed in the next two
sections will go to $LFS/tools/include. This switch ensures
that gcc will find them correctly. In the second pass of GCC,
this same switch will ensure that no headers from the host
system are found.

--disable-shared

This switch forces GCC to link its internal libraries
statically. We do this to avoid possible issues with the host
system.

These switches disable support for the decimal floating point
extension, threading, libmudflap, libssp and libgomp and
libquadmath respectively. These features will fail to compile
when building a cross-compiler and are not necessary for the
task of cross-compiling the temporary libc.

--disable-multilib

On x86_64, LFS does not yet support a multilib configuration.
This switch is harmless for x86.

--enable-languages=c

This option ensures that only the C compiler is built. This
is the only language needed now.

Compile GCC by running:

make

Compilation is now complete. At this point, the test suite would
normally be run, but, as mentioned before, the test suite framework
is not in place yet. The benefits of running the tests at this
point are minimal since the programs from this first pass will soon
be replaced.

Install the package:

make install

Using --disable-shared
means that the libgcc_eh.a file isn't
created and installed. The Glibc package depends on this library as
it uses -lgcc_eh within its
build system. This dependency can be satisfied by creating a
symlink to libgcc.a, since that file
will end up containing the objects normally contained in
libgcc_eh.a: