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
gcc-16.2.0.tar.xz(102.2 MiB)
sha256e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e
upstream: https://mirrors.ocf.berkeley.edu/gnu/gcc/gcc-16.2.0/gcc-16.2.0.tar.xz
archive copy: sources-2/embedded--gcc-arm-none-eabi-16.2.0.tar.xz
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.
--without-zstd, line 24: zstd (explained with the switches below)
Patches
build.sh applies these; kpkg applies nothing by itself.
libstdcxx-generic-locale-names.patch— Accept any locale name the C library accepts in libstdc++'s generic locale modelThe generic model refuses every name but "C", so std::locale("") throws under LANG=C.UTF-8 or any other UTF-8 locale, and so does every library that builds a locale from the environment, Boost.Process among them. A name newlocale() accepts is now valid; the facets keep the "C" locale's data, which is all the generic model has.
t-linux64-lib.patch— changes one line ofgcc/config/i386/t-linux64: the operating-system directory of the 64-bit multilib becomes../libinstead of../lib64. GCC then installs its runtime libraries in/usr/liband searches there, and nothing it links records a/usr/lib/../lib64RPATH. KDOS has one library directory,/usr/lib;/usr/lib64is a link to it (see Syncing fs/).
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:
--libexecdir=/usr/lib— install the compiler’s internal programs (cc1,cc1plus,f951,collect2,lto1,lto-wrapper) under/usr/lib/gcc/<triple>/<version>/instead of/usr/libexec. Part III’s GCC is configured with the same switch.--enable-languages=c,c++,fortran,lto— build the C, C++ and Fortran front ends and the LTO front end,lto1, which-fltoneeds at link time.gfortranis the Fortran compiler of the numerical ports, openblas, R, scipy and the rest.--disable-bootstrap— build the compiler once. A native GCC build otherwise compiles itself three times and compares the last two stages. The compiler building it here is the bootstrap’s GCC of the same version.--with-system-zlib— use the installed zlib instead of the copy in GCC’s source tree. GCC compresses LTO bytecode with it.--without-zstd— do not use zstd for LTO bytecode, and use zlib instead. zstd does not exist in20_selfhost; with the switch, the compiler is the same whichever phase rebuilds it, as binutils’ is.--without-isl— build without the isl library, so the Graphite loop optimisations (-floop-nest-optimizeand the rest) are not available. isl is not a port.--enable-linker-build-id— pass--build-idto the linker on every final link, so every executable and shared library GCC links carries a build ID even when a build’s own link line leaves out the tree’sLDFLAGS.--disable-multilib— build the 64-bit runtime libraries only, with no 32-bit (-m32) copies beside them.--enable-threads=posix— use POSIX threads for the C++ and Fortran runtimes’ thread support. This is the default on Linux; the switch states it.--enable-__cxa_atexit— register C++ static destructors with__cxa_atexit, which musl provides. GCC already defaults to this on Linux targets; the switch states it.--enable-default-pie— compile and link every program as a position-independent executable unless told otherwise, so it is loaded at a random address.--enable-default-ssp— turn on-fstack-protector-strongfor every compile. With--enable-default-pie, this is the part of the tree’s hardening the compiler supplies by itself (see The release flags).--enable-host-pie— build GCC’s own programs as position-independent executables.--enable-host-bind-now— link GCC’s own programs with-z now, so every symbol is resolved at start and the GOT can be read-only.-with-pkgversion="KDOS"— printKDOSwheregcc --versionprintsGCC:gcc (KDOS). It is spelled with one dash, which autoconf’s option parser accepts as it does two.CFLAGS_FOR_TARGET— the C flags for the libraries GCC builds for its target (libgcc,libgfortran,libgomp, the sanitizers). Unset, configure takes the build’sCFLAGSand puts-gin front of them, so the packages would carry DWARF. The tree’sCFLAGSare passed with their-std=option cut out, so these libraries compile under the C standard their own makefiles or GCC’s default give them.CXXFLAGS_FOR_TARGET— the same for the C++ libraries,libstdc++above all: the tree’sCXXFLAGS, with no-gadded.LDFLAGS_FOR_TARGET— the tree’sLDFLAGSfor the shared runtime libraries, solibstdc++.soand the rest are linked with-z nowand the other release link flags.LIBGCC2_DEBUG_CFLAGS=-g0— on bothmakelines. libgcc adds this variable,-gby default, after the flags it is given, so without itlibgccwould be compiled with debug information whateverCFLAGS_FOR_TARGETsays.
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:
- It copies the manual pages of
gcc,g++andgfortranand the info manuals ofgcc,gccint,cpp,cppinternalsandgfortranfrom the source, where the release carries them already built. GCC’s build regenerates those three manual pages withpod2man, from perl, and makes info manuals only when configure findsmakeinfo, from texinfo; both ports are built in30_foundation, after this one. Without them,make installwrites a placeholder file for each of the three pages and installs none of those info manuals. - It deletes
gccinstall.infofrom the package.make installwrites that manual only whenmakeinfoexists, so without the deletion the package’s contents would depend on whether texinfo was already in the tree. The install hook removes the bootstrap compiler’s copy of the same path, and a package that owned it would have its own file deleted by its own hook and failkpkg check. - It links
/usr/bin/ccto/usr/bin/gcc, the name make’s built-in rules and many makefiles call. - It moves libstdc++’s pretty-printer hook,
libstdc++.so.6.*-gdb.py, to/usr/share/gdb/auto-load/usr/lib/. gdb runs such a script only from its safe auto-load path, so beside the library it would be declined and every standard container would print as its internals.