GCC-9.2.0

Introduction to GCC

The GCC package contains the GNU Compiler Collection. This page describes the installation of compilers for the following languages: C, C++, D, Fortran, Objective C, Objective C++, and Go.

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

[Caution]

Caution

If you are upgrading GCC from any other version prior to 9.2.0, 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.

Some system headers need to be fixed to be used with GCC. This is done during the installation of GCC, and the fixed headers are installed in /usr/lib/gcc/<machine triplet>/<GCC version>/include-fixed . This is harmless if GCC is built during the LFS stage. But if you reinstall GCC in BLFS, some of the BLFS packages may be fixed. If one of those packages is reinstalled afterwards, the fixed headers are not updated, which may lead to version mismatches. In case that happens, the fixed headers must be updated by running (as root): /usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/install-tools/mkheaders . The machine triplet may be different on a 32bit system.

Package Information

GCC Dependencies

Recommended

Optional

GDB-9.1, Valgrind-3.15.0 (for tests), and ISL (to enable graphite optimization)

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/gcc

Installation of GCC

[Important]

Important

Even if you specify only languages other than C and C++ to the ./configure command below, the installation process will overwrite your existing GCC C 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.

Do not continue with the make install command until you are confident the build was successful. You can compare your test results with those found at http://gcc.gnu.org/ml/gcc-testresults/. You may also want to refer to the information found in the GCC section of Chapter 6 in the LFS book (../../../../lfs/view/9.1/chapter06/gcc.html).

The instructions below are intentionally performing a bootstrap process. Bootstrapping is needed for robustness and is highly recommended when upgrading the compilers version. To disable bootstrap anyways, add --disable-bootstrap to the ./configure options below.

Install GCC by running the following commands:

case $(uname -m) in
  x86_64)
    sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
  ;;
esac

sed -e '1161 s|^|//|' \
    -i libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc

mkdir build                                            &&
cd    build                                            &&

../configure                                           \
    --prefix=/usr                                      \
    --disable-multilib                                 \
    --with-system-zlib                                 \
    --enable-languages=c,c++,d,fortran,go,objc,obj-c++ &&
make

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). As of gcc-9.2.0, about 100 FAIL occur in the guality suite, as well as miscellaneous failures throughout the rest of the test suite. If all the compilers above are built, there will be slightly over 120 unexpected failures out of over 390,000 tests. To run the tests, issue:

ulimit -s 32768 &&
make -k check

The tests are very long, and the results may be hard to find in the logs, specially if you use parallel jobs with make. You can get a summary of the tests with:

../contrib/test_summary

Now, as the root user:

make install &&

mkdir -pv /usr/share/gdb/auto-load/usr/lib              &&
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib &&

chown -v -R root:root \
    /usr/lib/gcc/*linux-gnu/9.2.0/include{,-fixed}

rm -rf /usr/lib/gcc/$(gcc -dumpmachine)/9.2.0/include-fixed/bits/

Some packages expect to find the C preprocessor in /lib or may refer to the C compiler under the name cc. The following symbolic links are not needed if you have followed the LFS instructions, since they have been already created. If you do not have them on your system, issue as the root user:

ln -v -sf ../usr/bin/cpp /lib          &&
ln -v -sf gcc /usr/bin/cc              &&
install -v -dm755 /usr/lib/bfd-plugins &&
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/9.2.0/liblto_plugin.so /usr/lib/bfd-plugins/

Command Explanations

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

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

--with-system-zlib: Uses the system zlib instead of the bundled one. zlib is used for compressing and uncompressing GCC's intermediate language in LTO (Link Time Optimization) object files.

--enable-languages=c,c++,d,fortran,go,objc,obj-c++: This command identifies which languages to build. You may modify this command to remove undesired languages. Two other languages can be added, besides ADA (see introduction above): BRIG (add brig to the list of enabled languages), a binary format for HSAIL (Heterogeneous System Architecture Intermediate Language), and JIT (add jit to the list of enabled languages), a library which can be linked into interpreters that want to generate machine code on the fly at run-time. They have not been tested by the BLFS developers.

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.

../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.

mv -v /usr/lib/*gdb.py ...: The installation stage puts some files used by gdb under the /usr/lib directory. This generates spurious error messages when performing ldconfig. This command moves the files to another location.

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 directory (and its content) will be incorrect. This command changes the ownership to the root user and group.

rm -rf .../include-fixed/bits/: Remove an erroneous file in gcc added by the fixincludes process.

Contents

Some program and library names and descriptions are not listed here, but can be found at ../../../../lfs/view/9.1/chapter06/gcc.html#contents-gcc as they were initially installed during the building of LFS.

Installed Programs: gccgo, go, gofmt, gdc and gfortran, hard-linked to architecture specific names
Installed Libraries: libgfortran.{so,a}, libgdruntime.{so,a}, libgphobos.{so,a} libgo.{so,a}, libgobegin.a, libgolibbegin.a, libobjc.{so,a}, and numerous other run-time libraries and executables
Installed Directories: /usr/lib/go

Short Descriptions

gccgo

is a GCC-based compiler for the Go language.

go

is a tool for managing Go source code.

gofmt

is a tool for formatting Go source code.

gdc

is a GCC-based compiler for the D language.

gfortran

is a GCC-based compiler for the Fortran language.

Last updated on 2020-02-18 12:45:12 -0800