8.38. GCC-14.2.0

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

Approximate build time: 46 SBU (with tests)
Required disk space: 6.3 GB

8.38.1. Installation of GCC

Create the PKGBUILD for the GCC package with the following commands:

mkdir /sources/gcc
cd /sources/gcc
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>
# Note, if bootstrapping, this package will recquire sudo permissions
# for the build user as temporary gcc build is not possition inedependent

pkgbase="gcc"
pkgname=(gcc-ada
         gcc-d
         gcc-fortran
         gcc-go
         gcc-m2
         gcc-objc
         gcc-rust
         gcc)
pkgver="14.2.0"
pkgrel="1"
pkgdesc="The GCC package contains the GNU compiler collection."
arch=('x86'
      'x86_64')
url="https://gcc.gnu.org/"
options=('!emptydirs'
         '!lto'
         'staticlibs')
license=('GPL'
         'LGPL'
         'FDL'
         'custom')
makedepends=('coreutils'
             'diffutils'
             'findutils'
             'gawk'
             'gcc'
             'gettext'
             'gmp'
             'grep'
             'isl'
             'm4'
             'make'
             'mpfr'
             'patch'
             'perl'
             'rust'
             'sed'
             'tar'
             'texinfo'
             'zztd')
checkdepends=('dejagnu'
              'inetutils')
source=('https://ftp.gnu.org/gnu/gcc/gcc-14.2.0/gcc-14.2.0.tar.xz')
md5sums=('2268420ba02dc01821960e274711bde0')
    
# If you want to modify what is actually built for a local build, set these 0
_build_ada=1
_build_d=1
_build_fortran=1
_build_go=1
_build_lto=1 #lto-dump gets installed with base gcc package
_build_m2=1
_build_objc=1
_build_rust=1

_confargs=""
_languages="c,c++"
_need_temp_gcc="no"

# See if we have ada
_have_ada=$(pacman -Q gcc-ada > /dev/null 2>&1 && echo "1" || echo "0")
if [[ "x${_build_ada}" == "x1" && "x${_have_ada}" == "x0" ]]; then
  _need_temp_gcc="yes"
fi

# See if we have d
_have_d=$(pacman -Q gcc-d > /dev/null 2>&1 && echo "1" || echo "0")
if [[ "x${_build_d}" == "x1" && "x${_have_d}" == "x0" ]]; then
  _need_temp_gcc="1"
fi

# Add temp gcc if needed
if [[ "x${_need_temp_gcc}" == "x1" ]]; then
  source=("${source}"
          "http://www.lucasit.com/gcc-${pkgver}-bootstrap-c-c++-ada-d-isl-20250309.tar.xz")
fi

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"

  # hack! - some configure tests for header files using "$CPP $CPPFLAGS"
  #sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" {libiberty,gcc}/configure

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

  # The GCC documentation recommends building GCC in a dedicated build directory
  mkdir build
}

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}/build"

  # Handle options
  if [[ "x${_build_ada}" == "x1" ]]; then
    _languages="ada,${_languages}"
  fi

  if [[ "x${_build_d}" == "x1" ]]; then
    _languages="${_languages},d"
  fi

  if [[ "x${_build_fortran}" == "x1" ]]; then
    _languages="${_languages},fortran"
  fi

  if [[ "x${_build_go}" == "x1" ]]; then
    _languages="${_languages},go"
  fi

  if [[ "x${_build_lto}" == "x1" ]]; then
    _languages="${_languages},lto"
  fi

  if [[ "x${_build_m2}" == "x1" ]]; then
    _languages="${_languages},m2"
  fi

  if [[ "x${_build_objc}" == "x1" ]]; then
    _languages="${_languages},objc,obj-c++"
  fi

  if [[ "x${_build_rust}" == "x1" ]]; then
    _languages="${_languages},rust"
  fi

  # Put temporary gcc into place
  if [[ "x${_need_temp_gcc}" == "x1" ]]; then
    if [[ -d /opt/gcc ]]; then echo "ERROR: /opt/gcc exists! Exiting..." && exit 1; fi
    # Copy to real filesystem -- FIXME: REQUIRES SUDO PERMISSIONS
    sudo cp -Rv ${srcdir}/opt/gcc /opt
    export PATH="/opt/gcc/bin:${PATH}"
    _confargs="${_confargs} --enable-bootstrap"
  else
    _confargs="${_confargs} --disable-bootstrap"
  fi

  # Disable -Werror in CFLAGS
  CFLAGS=${CFLAGS/-Werror=format-security/}
  CXXFLAGS=${CXXFLAGS/-Werror=format-security/}

  ../configure --prefix=/usr            \
               LD=ld                    \
               --enable-default-pie     \
               --enable-default-ssp     \
               --enable-host-pie        \
               --disable-multilib       \
               --disable-fixincludes    \
               --with-system-zlib       \
               ${_confargs}             \
               --enable-languages=${_languages}

  # Optimize final GCC
  # Borrowed form Arch
  # See https://bugs.archlinux.org/task/71777
  if [[ "x${_need_temp_gcc}" == "x1" ]]; then
    make -O STAGE1_CFLAGS="-O2" \
    BOOT_CFLAGS="$CFLAGS" \
    BOOT_LDFLAGS="$LDFLAGS" \
    LDFLAGS_FOR_TARGET="$LDFLAGS"
  else
    make -O BOOT_CFLAGS="$CFLAGS" \
    BOOT_LDFLAGS="$LDFLAGS" \
    LDFLAGS_FOR_TARGET="$LDFLAGS"
  fi

  # Install to temp location and extract split packages from there
  make DESTDIR=${srcdir}/gcc-dest install

  # Strip most of the package if not a debug build
  if check_option 'debug' n; then
    options+=('!strip')

    # Executables
    find "${srcdir}/gcc-dest/usr/bin" \
      -type f \
      -executable \
      -exec strip $STRIP_BINARIES {} + 2> /dev/null || true
    find "${srcdir}/gcc-dest/usr/lib/libexec/" \
     -type f -executable \
     -not -name "*.so*" \
     -not -name "*.a" \
     -not -name "*.sh" \
     -exec strip $STRIP_BINARIES {} + 2> /dev/null || true

    # Libraries
    find "${srcdir}/gcc-dest/usr/lib" \
      -name '*.a' \
      -type f \
      -exec strip $STRIP_STATIC {} + 2> /dev/null || true
    find "${srcdir}/gcc-dest/usr/lib" \
      -type f \
      -name '*.so' \
      -not -name "libquadmath*" \
      -not -name "libstdc++*" \
      -not -name "libitm*" \
      -not -name "libatomic*" \
      -exec strip $STRIP_SHARED {} + 2> /dev/null || true
  fi

  # Remove temporary gcc if needed
  if [[ "x${_need_temp_gcc}" == "x1" ]]; then
    sudo rm -rfv /opt/gcc
  fi
}

check() {
  cd ${srcdir}/${pkgbase}-${pkgver}/build
  make -k check || true
  ${srcdir}/${pkgbase}-${pkgver}/contrib/test_summary
}

package_gcc-ada() {
  pkgdesc="The GCC package contains the GNU compiler collection (Ada front-end)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Bin
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/gnat* "${pkgdir}/usr/bin"

  # Lib
  install -vdm755 "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v \
  "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/ada_target_properties" \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"/adainclude \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"/adalib \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  # Libexec
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/gnat1" \
        "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  # Info
  install -vdm755 "${pkgdir}/usr/share/info"
  mv -v "${srcdir}"/gcc-dest/usr/share/info/gnat* \
        "${pkgdir}/usr/share/info"
}

package_gcc-d() {
  pkgdesc="The GCC package contains the GNU compiler collection (D front-end)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Bin
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/{,"${CARCH}"-pc-linux-gnu-}gdc "${pkgdir}/usr/bin"

  # Lib
  install -vdm755 "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libg{druntime,phobos}.* "${pkgdir}/usr/lib"
  install -vdm755 "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/include"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/include/d" \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/include"

  # Libexec
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/d21" \
        "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  # Info/Man
  install -vdm755 "${pkgdir}"/usr/share/{info,man/man1}
  mv -v "${srcdir}"/gcc-dest/usr/share/info/gdc.* \
        "${pkgdir}/usr/share/info"
  mv -v "${srcdir}"/gcc-dest/usr/share/man/man1/gdc.* \
        "${pkgdir}/usr/share/man/man1"
}

package_gcc-fortran() {
  pkgdesc="The GCC package contains the GNU compiler collection (Fortran front-end)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Bin
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/{,"${CARCH}"-pc-linux-gnu-}gfortran \
        "${pkgdir}/usr/bin"

  # Lib
  install -vdm755 "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libgfortran.* "${pkgdir}/usr/lib"
  install -vdm755 "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"/libcaf* \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/finclude" \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  install -vdm755 "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/include"
  mv -v \
    "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"/include/ISO_F*.h \
    "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/include"

  # Libexce
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/f951" \
        "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  # Info/Man
  install -vdm755 "${pkgdir}"/usr/share/{info,man/man1}
  mv -v "${srcdir}"/gcc-dest/usr/share/info/gfortran.* \
        "${pkgdir}/usr/share/info"
  mv -v "${srcdir}"/gcc-dest/usr/share/man/man1/gfortran.* \
        "${pkgdir}/usr/share/man/man1"
}

package_gcc-go() {
  pkgdesc="The GCC package contains the GNU compiler collection (Go front-end)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Bin
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/{{,"${CARCH}"-pc-linux-gnu-}gccgo,go{,fmt}} \
        "${pkgdir}/usr/bin"

  # Lib
  install -vdm755 "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libgo.* "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libgo{,lib}begin.a "${pkgdir}/usr/lib"
  mv -v "${srcdir}/gcc-dest/usr/lib/go" "${pkgdir}/usr/lib"

  # Libexec
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  for file in buildid cgo go1 test2json vet; do
    mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/${file}" \
          "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  done

  #Info/Man
  install -vdm755 "${pkgdir}"/usr/share/{info,man/man1}
  mv -v "${srcdir}"/gcc-dest/usr/share/info/gccgo.* \
        "${pkgdir}/usr/share/info"
  mv -v "${srcdir}"/gcc-dest/usr/share/man/man1/{gccgo,go,gofmt}.* \
        "${pkgdir}/usr/share/man/man1"
}

package_gcc-m2() {
  pkgdesc="The GCC package contains the GNU compiler collection (Modula-2 frontend)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Bin
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/{,"${CARCH}"-pc-linux-gnu-}gm2 \
        "${pkgdir}/usr/bin"

  # Lib
  install -vdm755 "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libm2* \
        "${pkgdir}/usr/lib"
  install -vdm755 "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}/m2" \
        "${pkgdir}/usr/lib/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  # Libexec
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/cc1gm2" \
        "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

  #Info/Man
  install -vdm755 "${pkgdir}"/usr/share/{info,man/man1}
  mv -v "${srcdir}"/gcc-dest/usr/share/info/m2.* \
        "${pkgdir}/usr/share/info"
  mv -v "${srcdir}"/gcc-dest/usr/share/man/man1/gm2.* \
        "${pkgdir}/usr/share/man/man1"
}

package_gcc-objc() {
  pkgdesc="The GCC package contains the GNU compiler collection (Objective-C and Objective-C++ front-end)"
  depends=("gcc=${pkgver}-${pkgrel}")

  # Libs
  install -vdm755 "${pkgdir}/usr/lib"
  mv -v "${srcdir}"/gcc-dest/usr/lib/libobjc* "${pkgdir}/usr/lib"
  install -vdm755 "${pkgdir}/usr/lib/gcc/$CARCH-pc-linux-gnu/${pkgver}/plugin/include"
  mv -v \
    "${srcdir}/gcc-dest/usr/lib/gcc/$CARCH-pc-linux-gnu/${pkgver}/plugin/include/objc" \
    "${pkgdir}/usr/lib/gcc/$CARCH-pc-linux-gnu/${pkgver}/plugin/include"

  # Libexc
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  for file in cc1obj cc1objplus; do
    mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/${file}" \
          "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  done
}

package_gcc-rust() {
  pkgdesc="The GCC package contains the GNU compiler collection (Rust front-end)"
  depends=("gcc=${pkgver}-${pkgrel}"
           'rust')
  install -vdm755 "${pkgdir}/usr/bin"
  mv -v "${srcdir}"/gcc-dest/usr/bin/{,"${CARCH}"-pc-linux-gnu-}gccrs \
        "${pkgdir}/usr/bin"
  install -vdm755 "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"
  mv -v "${srcdir}/gcc-dest/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}/crab1" \
        "${pkgdir}/usr/libexec/gcc/${CARCH}-pc-linux-gnu/${pkgver}"

}

package_gcc() {
  pkgdesc="The GCC package contains the GNU compiler collection (C and C++ front-ends)"
  depends=('bash'
           'binutils'
           'glibc'
           'mpc'
           'python')
  groups=('core')

  install -vdm755 "${pkgdir}/usr/"
  mv -v "${srcdir}"/gcc-dest/usr/* "${pkgdir}/usr/"

  install -vdm755 "${pkgdir}/usr/share/gdb/auto-load/usr/lib"
  mv -v "${pkgdir}"/usr/lib/*gdb.py "${pkgdir}/usr/share/gdb/auto-load/usr/lib"

  ln -vsf ../usr/bin/cpp "${pkgdir}/lib"
  ln -vsf gcc "${pkgdir}/usr/bin/cc"

  if [[ "x${_build_lto}" == "x1" ]]; then
    install -vdm755 "${pkgdir}/usr/lib/bfd-plugins"
    ln -sfv ../../libexec/gcc/"${CARCH}"-pc-linux-gnu/"${pkgver}"/liblto_plugin.so \
            "${pkgdir}/usr/lib/bfd-plugins"
  fi
}
REALEOF

The meaning of the new configure parameters:

LD=ld

This parameter makes the configure script use the ld program installed by the Binutils package built earlier in this chapter, rather than the cross-built version which would otherwise be used.

--disable-fixincludes

By default, during the installation of GCC some system headers would be fixed to be used with GCC. This is not necessary for a modern Linux system, and potentially harmful if a package is reinstalled after installing GCC. This switch prevents GCC from fixing the headers.

--with-system-zlib

This switch tells GCC to link to the system installed copy of the Zlib library, rather than its own internal copy.

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp gcc-14.2.0-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
cp gcc-*-14.2.0-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/gcc-14.2.0-1-$(uname -m).pkg.tar.xz
for file /srv/pacman/repos/LFS/gcc-*-14.2.0-1-$(uname -m).pkg.tar.xz; do
   repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz "${file}"
done

Update the local cache and install the main GCC package:

pacman -Syu
pacman -S gcc --overwrite \* -dd --noconfirm

If you wish to install the additional GCC drivers, execute the following commands:

for file in ada d fortran go m2 objc rust; do
    pacman -S "gcc-${file}" --overwrite \* -dd --noconfirm
done

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/gcc
cp PKGBUILD /srv/pacman/source/LFS/gcc
cd /sources
rm -rf gcc
[Note]

Note

PIE (position-independent executables) are binary programs that can be loaded anywhere in memory. Without PIE, the security feature named ASLR (Address Space Layout Randomization) can be applied for the shared libraries, but not for the executables themselves. Enabling PIE allows ASLR for the executables in addition to the shared libraries, and mitigates some attacks based on fixed addresses of sensitive code or data in the executables.

SSP (Stack Smashing Protection) is a technique to ensure that the parameter stack is not corrupted. Stack corruption can, for example, alter the return address of a subroutine, thus transferring control to some dangerous code (existing in the program or shared libraries, or injected by the attacker somehow).

Now that our final toolchain is in place, it is important to again ensure that compiling and linking will work as expected. We do this by performing some sanity checks:

echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

There should be no errors, and the output of the last command will be (allowing for platform-specific differences in the dynamic linker name):

[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

Now make sure that we're set up to use the correct start files:

grep -E -o '/usr/lib.*/S?crt[1in].*succeeded' dummy.log

The output of the last command should be:

/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/../../../../lib/Scrt1.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/../../../../lib/crti.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/../../../../lib/crtn.o succeeded

Depending on your machine architecture, the above may differ slightly. The difference will be the name of the directory after /usr/lib/gcc. The important thing to look for here is that gcc has found all three crt*.o files under the /usr/lib directory.

Verify that the compiler is searching for the correct header files:

grep -B4 '^ /usr/include' dummy.log

This command should return the following output:

#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/include
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/include-fixed
 /usr/include

Again, the directory named after your target triplet may be different than the above, depending on your system architecture.

Next, verify that the new linker is being used with the correct search paths:

grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

References to paths that have components with '-linux-gnu' should be ignored, but otherwise the output of the last command should be:

SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64")
SEARCH_DIR("/usr/local/lib64")
SEARCH_DIR("/lib64")
SEARCH_DIR("/usr/lib64")
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");

A 32-bit system may use a few other directories. For example, here is the output from an i686 machine:

SEARCH_DIR("/usr/i686-pc-linux-gnu/lib32")
SEARCH_DIR("/usr/local/lib32")
SEARCH_DIR("/lib32")
SEARCH_DIR("/usr/lib32")
SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");

Next make sure that we're using the correct libc:

grep "/lib.*/libc.so.6 " dummy.log

The output of the last command should be:

attempt to open /usr/lib/libc.so.6 succeeded

Make sure GCC is using the correct dynamic linker:

grep found dummy.log

The output of the last command should be (allowing for platform-specific differences in dynamic linker name):

found ld-linux-x86-64.so.2 at /usr/lib/ld-linux-x86-64.so.2

If the output does not appear as shown above or is not received at all, then something is seriously wrong. Investigate and retrace the steps to find out where the problem is and correct it. Any issues should be resolved before continuing with the process.

Once everything is working correctly, clean up the test files:

rm -v dummy.c a.out dummy.log

8.38.2. Contents of GCC

Installed programs: c++, cc (link to gcc), cpp, g++, gcc, gcc-ar, gcc-nm, gcc-ranlib, gcov, gcov-dump, gcov-tool, and lto-dump
Installed libraries: libasan.{a,so}, libatomic.{a,so}, libcc1.so, libgcc.a, libgcc_eh.a, libgcc_s.so, libgcov.a, libgomp.{a,so}, libhwasan.{a,so}, libitm.{a,so}, liblsan.{a,so}, liblto_plugin.so, libquadmath.{a,so}, libssp.{a,so}, libssp_nonshared.a, libstdc++.{a,so}, libstdc++exp.a, libstdc++fs.a, libsupc++.a, libtsan.{a,so}, and libubsan.{a,so}
Installed directories: /usr/include/c++, /usr/lib/gcc, /usr/libexec/gcc, and /usr/share/gcc-14.2.0

Short Descriptions

c++

The C++ compiler

cc

The C compiler

cpp

The C preprocessor; it is used by the compiler to expand the #include, #define, and similar directives in the source files

g++

The C++ compiler

gcc

The C compiler

gcc-ar

A wrapper around ar that adds a plugin to the command line. This program is only used to add "link time optimization" and is not useful with the default build options.

gcc-nm

A wrapper around nm that adds a plugin to the command line. This program is only used to add "link time optimization" and is not useful with the default build options.

gcc-ranlib

A wrapper around ranlib that adds a plugin to the command line. This program is only used to add "link time optimization" and is not useful with the default build options.

gcov

A coverage testing tool; it is used to analyze programs to determine where optimizations will have the greatest effect

gcov-dump

Offline gcda and gcno profile dump tool

gcov-tool

Offline gcda profile processing tool

lto-dump

Tool for dumping object files produced by GCC with LTO enabled

libasan

The Address Sanitizer runtime library

libatomic

GCC atomic built-in runtime library

libcc1

A library that allows GDB to make use of GCC

libgcc

Contains run-time support for gcc

libgcov

This library is linked into a program when GCC is instructed to enable profiling

libgomp

GNU implementation of the OpenMP API for multi-platform shared-memory parallel programming in C/C++ and Fortran

libhwasan

The Hardware-assisted Address Sanitizer runtime library

libitm

The GNU transactional memory library

liblsan

The Leak Sanitizer runtime library

liblto_plugin

GCC's LTO plugin allows Binutils to process object files produced by GCC with LTO enabled

libquadmath

GCC Quad Precision Math Library API

libssp

Contains routines supporting GCC's stack-smashing protection functionality. Normally it is not used, because Glibc also provides those routines.

libstdc++

The standard C++ library

libstdc++exp

Experimental C++ Contracts library

libstdc++fs

ISO/IEC TS 18822:2015 Filesystem library

libsupc++

Provides supporting routines for the C++ programming language

libtsan

The Thread Sanitizer runtime library

libubsan

The Undefined Behavior Sanitizer runtime library