Beyond Linux® From Scratch - Version 7.4

Chapter 13. Programming

GCC-4.8.1

Introduction to GCC

The GCC package contains GNU
compilers. This package is useful for compiling programs written in
C, C++, Fortran, Java, Objective C, Objective C++, Ada, and Go. You
should ensure you actually need one of these additional compilers
(C and C++ are installed in LFS) before you install them.
Additionally, there are instructions in the BLFS book to install
OpenJDK-1.7.0.40/IcedTea-2.4.1,
which can be used instead of the Java provided by the GCC package. Many consider the Iced Tea
version to be a more robust Java environment than the one provided
by GCC.

This package is known to build and work properly using an LFS-7.4
platform.

Caution

If you are upgrading GCC from
any other version prior to 4.8.1, then you must be careful
compiling 3rd party kernel modules. You should ensure that the
kernel and all its native modules are also compiled using the
same version of GCC that you use
to build the 3rd party module. This issue does not affect native
kernel (and kernel modules) updates, as the instructions below
are a complete reinstallation of GCC. If you have existing 3rd party modules
installed, ensure they are recompiled using the updated version
of GCC. As always, never update
the kernel headers from the ones used when Glibc was compiled during LFS.

GCC Dependencies

Recommended

Required if building java

Note

If you plan to compile Ada, you will need to install GNAT temporarily to satisfy the circular
dependency when you recompile GCC to include Ada. At the AdaCore download
page, choose your platform and 2013, then select the file to
download. You probably want the x86-linux or x86_64-linux file.

GNAT GPL 2013 Package Information

Installation of GNAT

Before unpacking and changing into the GCC source directory, first
unpack the GNAT tarball. You may
have to drill down several levels and unpack a second tarball. For
example, AdaCore-Download-2013-07-22_0530.tar expands to
x86_64-linux/2013/gnatgpl/gnat-gpl-2013-x86_64-pc-linux-gnu-bin.tar.gz.
Expand this second tarball and change into the newly created
directory. Install GNAT by running
the following command:

make ins-all prefix=/opt/gnat

The GNAT compiler can be invoked
by executing the gcc
binary installed in /opt/gnat/bin.

You may now remove the GNAT source
directory if desired.

Prepare to compile GCC by placing
the GNAT version of gcc at the beginning of the
PATH variable by using the following
commands as the root user:

PATH_HOLD=$PATH &&
export PATH=/opt/gnat/bin:$PATH_HOLD

Doing so has the drawback that the GCC and Binutils executables are taken from the just
installed GNAT package, but the
versions of those executables are outdated compared to those
installed in LFS. This is not important for the GCC compilers, since they recompile themselves
during the bootstrap process. On the other hand, the outdated
ld and as tools are used all along. In
order to use the LFS tools, issue:

Installation of GCC

Install GCC by running the
following commands:

Important

The installation process may overwrite your existing GCCgcc and c++ compilers and libraries.
Having the Tcl, Expect and DejaGnu packages installed before beginning
the build is highly recommended so you can run the full suite of
tests.

The instructions below let the build machinery perform a
“bootstrap” intentionally.
This is necessary if you install the Ada compiler anyway. Even if you don't, a
bootstrap is recommended for robustness.

If you have installed additional packages such as valgrind and gdb,
the gcc part of the testsuite will run more tests than in LFS. Some
of those will report FAIL and others XPASS (pass when expected to
FAIL). To run the checks:

You should now remove the GNAT
installation and perform other cleanups:

rm -rf /opt/gnat &&
export PATH=$PATH_HOLD &&
unset PATH_HOLD

Command Explanations

The first two sed
commands prevent the installation of the libffi library bundled with GCC, since it is outdated compared to
libffi-3.0.13. The three other sed commands are the same ones
used during the build of LFS.

mkdir ../gcc-build; cd
../gcc-build: The GCC documentation recommends building the
package in a dedicated build directory.

--enable-shared --enable-threads=posix
--enable-__cxa_atexit: These parameters are required to
build the C++ libraries to
published standards.

--disable-multilib: This
parameter ensures that files are created for the specific
architecture of your computer.

--enable-clocale=gnu: This
parameter is a failsafe for incomplete locale data.

--enable-lto: Setting this
parameter allows to build a compiler which is able to perform
“link time optimization
(lto)”.

--enable-languages=c,c++,fortran,java,objc,obj-c++,ada,go:
This command identifies which languages to build. You may modify
this command to remove undesired languages.

ulimit -s 32768: This
command prevents several tests from running out of stack space.

make -k check: This
command runs the test suite without stopping if any errors are
encountered.

../gcc-4.8.1/contrib/test_summary:
This command will produce a summary of the test suite results. You
can append | grep -A7
Summ to the command to produce an even more
condensed version of the summary. You may also wish to redirect the
output to a file for review and comparison later on.

ln -v -sf ../usr/bin/cpp
/lib: This command creates a link to the C
PreProcessor as some packages expect it to be installed in the
/lib directory.

ln -v -sf gcc
/usr/bin/cc: This link is created as some packages
refer to the C compiler using an alternate name.

chown -v -R root:root
/usr/lib/gcc/*linux-gnu/...: If the package is
built by a user other than root, the ownership of the installed
include and adalib directories (and their contents) will be
incorrect. These commands change the ownership to the root user and group . Omit the command changing
the Ada directories if you did not include Ada as one of the
installed languages.