Linux From Scratch - Version 7.4

Chapter 5. Constructing a Temporary System

5.10.
GCC-4.8.1 - Pass 2

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

Approximate build time:7.1 SBU

Required disk space:1.8 GB

5.10.1. 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:

For x86 machines, a bootstrap build of GCC uses the -fomit-frame-pointer 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:

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 -sv gcc /tools/bin/cc

Caution

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:

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 Section 4.4,
“Setting Up the Environment.”