GCC-16.2.0

#### Beyond Linux® From Scratch (System V Edition) - Version r13.1-84

### Chapter 13. Programming

- Prev

  dtc-1.8.1

- Next

  GC-8.2.12

- Up
- Home

# GCC-16.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++, Fortran, Objective C, Objective C++, Go, and Modula2. Since C and C++ are installed in LFS, this page is either for upgrading C and C++, or for installing additional compilers.

### Note

Additional languages, including COBOL, D, and Ada, are available in the collection. COBOL is currently only supported on x86-64 systems. D and Ada have a binary bootstrap requirement for the first installation, so their installation is not described here. To install D or Ada, you can proceed along the same lines as below after installing the corresponding compiler from a binary package. Finally add `ada` or `d` or `cobol` to the `--enable-languages` line as desired.

### Note

Development versions of BLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.

### Caution

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

### Package Information

- Download (HTTP): https://ftpmirror.gnu.org/gcc/gcc-16.2.0/gcc-16.2.0.tar.xz

- Download MD5 sum: 19b777fb19ea4982731392481306f0d3

- Download size: 102 MB

- Estimated disk space required: 12 GB (4.1 GB installed with all listed languages; add 2 GB for tests)

- Estimated build time: 19 SBU (add 40 SBU for tests; both with parallelism=8)

### GCC Dependencies

#### Optional

GDB-17.2, Graphviz-15.1.1 (some tests use it if installed; note that if it's installed but not built with libpng-1.6.58 these tests will fail), libxml2-2.15.4 (for the COBOL runtime library), Valgrind-3.27.1 (for tests), and ISL (to enable graphite optimization)

## Installation of GCC

### 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. Running the full suite of tests is recommended because of this.

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 https://gcc.gnu.org/ml/gcc-testresults/. You may also want to refer to the information found in the GCC section of Chapter 8 in the LFS book (../../../../lfs/view/development/chapter08/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 bootstrapping anyway, add `--disable-bootstrap` to the ./configure options below.

Install GCC by running the following commands:

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

    mkdir build               &&
    cd    build               &&

    ../configure              \
        --prefix=/usr         \
        --disable-multilib    \
        --with-system-zlib    \
        --enable-default-pie  \
        --enable-default-ssp  \
        --enable-host-pie     \
        --disable-fixincludes \
        --enable-languages=c,c++,fortran,go,objc,obj-c++,m2 &&
    make

If you have installed additional packages such as valgrind and gdb, the gcc part of the test suite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). If all the compilers above are built, there will be about 165 unexpected failures out of over 625,000 tests. To run the tests, issue:

    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/16.2.0/include{,-fixed}     &&

    ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/16.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 version of zlib instead of the bundled copy. zlib is used for compressing and decompressing GCC's intermediate language in LTO (Link Time Optimization) object files.

`--enable-default-pie`: Makes the `-fpie` option the default when compiling programs. Together with the ASLR feature enabled in the kernel, this defeats some types of attacks based on known memory layouts.

`--enable-default-ssp`: Makes the `-fstack-protector-strong` option the default when compiling programs. SSP is a technique preventing attacks that alter the flow of a program by corrupting the parameter stack.

`--enable-host-pie`: Makes the compiler executables PIE (Position Independent Executable). This can be used to enhance protection against ROP (Return Oriented Programming) attacks, and can be viewed as part of a wider trend to harden binaries.

`--enable-languages=c,c++,fortran,go,objc,obj-c++,m2`: This command identifies which languages to build. You may modify this command to remove undesired languages. GCC also supports Ada and D, but building GCC with Ada (or D) support needs an existing Ada (or D) compiler. So they are not enabled here. You can also enable COBOL support by adding cobol to the command, but note that it only works properly on x86_64 systems.

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.

`--enable-host-shared --enable-languages=jit`: Build `libgccjit`, a library for embedding GCC inside programs and libraries for generating machine code. Despite “JIT” (just-in-time) in the name, the library can be used for AOT (ahead-of-time) compilation as well. `--enable-host-shared` is needed for building `libgccjit`, but it significantly slows down GCC. So `libgccjit` should be built and installed separately, not as a part of the “main” GCC installation. If you need this library, configure GCC with these two options and install the library by running make -C gcc jit.install-common jit.install-info as the `root` user. This library is not used by any BLFS package, nor is it tested by the BLFS developers.

## Contents

Some program and library names and descriptions are not listed here, but can be found at LFS section for GCC as they were initially installed during the building of LFS.

Installed Programs: gccgo, gfortran, gm2, go, and gofmt, hard-linked to architecture specific names
Installed Libraries: libgfortran.{so,a}, libgm2.{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
gm2 | is a GCC-based compiler for the Modula-2 language
go | is a tool for managing Go source code
gofmt | is a tool for formatting Go source code
gfortran | is a GCC-based compiler for the Fortran language

- Prev

  dtc-1.8.1

- Next

  GC-8.2.12

- Up
- Home