Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

35.5. gcc-16.2.0

The GNU compiler collection

Version 16.2.0, release 1
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 20_selfhost (Self-Hosting Bootstrap), 15 of 15 in build order
Licence GPL-3.0-or-later AND GPL-3.0-or-later WITH GCC-exception-3.1 AND LGPL-2.1-or-later
Homepage https://gcc.gnu.org/
Build time 14.8 SBU
Installed size 341.2 MiB in 1800 files
Recipe ports/core/toolchain/gcc/kpkgbuild

About

GCC is KDOS’s compiler for C, C++ and Fortran, with the runtime libraries programs in those languages link: libgcc_s, libstdc++, libgfortran, libgomp, libatomic and the sanitizer runtimes. Every later port’s C, C++ and Fortran is compiled by this package, apart from the few recipes that choose clang, and cc is a link to it.

It is the last port 20_selfhost builds, after gmp, mpfr, mpc and zlib, which it links, and with binutils already rebuilt. It is the second native GCC of the tree: Part III built one with the cross compiler, and this one is that compiler compiling itself inside the chroot. Its target is the chroot’s own x86_64-pc-linux-musl, not the bootstrap’s x86_64-kdos-linux-musl, and its install hook, postinstall.sh, clears away what the bootstrap left under the old name; What the gcc hook removes lists it, and the reasons are in The toolchain rebuilt as packages. 30_foundation names gcc again, so a changed recipe is rebuilt before anything else in that phase compiles.

The source is configured and built in a build directory of its own inside the tree. GCC’s installation manual does not support building in the source directory itself; it recommends a build directory outside the tree and says a subdirectory of it, as here, should work as well.

Sources

Dependencies

Depends on: mpc, mpfr, gmp, zlib.

Required by (22): arpack-ng, calculix, cfitsio, fftw, fluidsynth, ghc, go, graphicsmagick, libraw, nco, ocaml, octave, openblas, patchelf, qrupdate, R, scipy, suitesparse, sundials, valgrind, voacapl, wsjtx.

Optional, off in KDOS

These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.

Patches

build.sh applies these; kpkg applies nothing by itself.

Differs from the bootstrap build. Cross GCC, pass 1 builds this source too, in script/phases/00_cross/01_gcc.sh, before kpkg exists.

Only in the bootstrap build: --disable-libatomic, --disable-libgomp, --disable-libquadmath, --disable-libssp, --disable-libstdcxx, --disable-libvtv, --disable-shared, --disable-threads, --enable-initfini-array, --enable-languages=c,c++, --prefix=$CROSS_SYSROOT, --target=$KDOS_TARGET, --with-newlib, --with-sysroot=$SYSROOT, --without-headers.

Only in this build: --enable-__cxa_atexit, --enable-host-bind-now, --enable-host-pie, --enable-languages=c,c++,fortran,lto, --enable-linker-build-id, --enable-threads=posix, --libexecdir=/usr/lib, --prefix=/usr, --with-system-zlib, --without-isl, --without-zstd.

Differs from the bootstrap build. libstdc++ builds this source too, in script/phases/10_bootstrap/030_libstdc++.sh, before kpkg exists.

Only in the bootstrap build: --build=$(../config.guess), --disable-libstdcxx-pch, --host=$KDOS_TARGET, --with-gxx-include-dir=/../cross/$KDOS_TARGET/include/c++/$GCC_VER.

Only in this build: --disable-bootstrap, --enable-__cxa_atexit, --enable-default-pie, --enable-default-ssp, --enable-host-bind-now, --enable-host-pie, --enable-languages=c,c++,fortran,lto, --enable-linker-build-id, --enable-threads=posix, --libexecdir=/usr/lib, --with-system-zlib, --without-isl, --without-zstd.

Differs from the bootstrap build. GCC builds this source too, in script/phases/10_bootstrap/100_gcc.sh, before kpkg exists.

Only in the bootstrap build: --disable-libatomic, --disable-libgomp, --disable-libquadmath, --disable-libsanitizer, --disable-libssp, --disable-libvtv, --enable-languages=c,c++, --host=$KDOS_TARGET, --target=$KDOS_TARGET, --with-build-sysroot=$SYSROOT.

Only in this build: --disable-bootstrap, --enable-__cxa_atexit, --enable-host-bind-now, --enable-host-pie, --enable-languages=c,c++,fortran,lto, --enable-linker-build-id, --enable-threads=posix, --with-system-zlib, --without-isl, --without-zstd.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/20_selfhost/phase.env && kpkg install gcc'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/gcc.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/toolchain/gcc
echo 'e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e  gcc-16.2.0.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/gcc
SRC=$SRC_ROOT/gcc-16.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf gcc-16.2.0.tar.xz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/t-linux64-lib.patch"
patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/libstdcxx-generic-locale-names.patch"

mkdir -v build
cd       build

../configure \
	--prefix=/usr \
	--libexecdir=/usr/lib \
	--enable-languages=c,c++,fortran,lto \
	--disable-bootstrap \
	--with-system-zlib \
	--without-zstd \
	--without-isl \
	--enable-linker-build-id \
	--disable-nls \
	--disable-multilib \
	--enable-threads=posix \
	--enable-__cxa_atexit \
	--enable-default-pie \
	--enable-default-ssp \
	--enable-host-pie \
	--enable-host-bind-now \
	-with-pkgversion="KDOS" \
	CFLAGS_FOR_TARGET="${CFLAGS/-std=gnu[0-9][0-9]/}" \
	CXXFLAGS_FOR_TARGET="$CXXFLAGS" \
	LDFLAGS_FOR_TARGET="$LDFLAGS"
make LIBGCC2_DEBUG_CFLAGS=-g0
make DESTDIR=$PKG install LIBGCC2_DEBUG_CFLAGS=-g0

install -m644 ../gcc/doc/{gcc,g++,gfortran}.1 -t "$PKG/usr/share/man/man1"
install -d "$PKG/usr/share/info"
install -m644 ../gcc/doc/{gcc,gccint,cpp,cppinternals}.info ../gcc/fortran/gfortran.info \
	-t "$PKG/usr/share/info"
rm -f "$PKG/usr/share/info/gccinstall.info"

ln -sv /usr/bin/gcc $PKG/usr/bin/cc

install -d "$PKG/usr/share/gdb/auto-load/usr/lib"
mv "$PKG"/usr/lib/libstdc++.so.*-gdb.py "$PKG/usr/share/gdb/auto-load/usr/lib/"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

postinstall.sh runs on the installed system after the package is adopted:

root="${PKG_ROOT:-/}"
rm -rf "$root/usr/lib/gcc/x86_64-kdos-linux-musl" \
	"$root/usr/x86_64-kdos-linux-musl" \
	"$root/usr/include/c++/$version/x86_64-kdos-linux-musl"
rm -f "$root"/usr/bin/x86_64-kdos-linux-musl-* \
	"$root/usr/share/info/gccinstall.info"

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/gcc, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf gcc-16.2.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/gcc, and runs the triggers its paths call for.

Contents

Installed programs: c++, cc, cpp, g++, gcc, gcc-ar, gcc-nm, gcc-ranlib, gcov, gcov-dump, gcov-tool, gfortran, lto-dump, x86_64-pc-linux-musl-c++, x86_64-pc-linux-musl-g++, x86_64-pc-linux-musl-gcc, x86_64-pc-linux-musl-gcc-16.2.0, x86_64-pc-linux-musl-gcc-ar, x86_64-pc-linux-musl-gcc-nm, x86_64-pc-linux-musl-gcc-ranlib, x86_64-pc-linux-musl-gfortran.

Installed libraries: libasan.a, libasan.so, libatomic.a, libatomic.so, libatomic_asneeded.a, libatomic_asneeded.so, libcc1.so, libgcc_s.so, libgcc_s_asneeded.so, libgfortran.a, libgfortran.so, libgomp.a, libgomp.so, libhwasan.a, libhwasan.so, libitm.a, libitm.so, liblsan.a, liblsan.so, libquadmath.a, libquadmath.so, libssp.a, libssp.so, libssp_nonshared.a, libstdc++.a, libstdc++.so, libstdc++exp.a, libstdc++fs.a, libsupc++.a, libtsan.a, libtsan.so, libubsan.a, libubsan.so.

Installed directories: /usr/include/c++, /usr/lib/gcc/x86_64-pc-linux-musl, /usr/share/gcc-16.2.0, /usr/share/licenses/gcc.

Short descriptions

cpp The C Preprocessor
g++ GNU project C and C++ compiler
gcc GNU project C and C++ compiler
gcov coverage testing tool
gcov-dump offline gcda and gcno profile dump tool
gcov-tool offline gcda profile processing tool
gfortran GNU Fortran compiler
lto-dump Tool for dumping LTO object files

Notes

The recipe’s facet_dev = line moves the compiler into the package’s development facet: the drivers under /usr/bin, everything under /usr/lib/gcc/ (cc1, cc1plus, f951, lto1, the crt files, libgcc.a and the plugin headers), the .o and .spec files in /usr/lib, libcc1, the sanitizer runtimes, /usr/share/gcc-<version> and the manual pages. What is left is the run-time libraries, libstdc++, libgcc_s, libgfortran, libgomp, libquadmath, libatomic and libitm, which most of the base links, so gcc stays in the base and a machine with FACETS=run carries about 10 MB of it instead of 339 MB. A build here restores the facet first (kdos update install --dev gcc, which a source install runs itself). The line is part of the recipe hash, so a change to it rebuilds gcc and every port keyed on it.

After make install, build.sh does four more things: