161.11. libstdcxx-arm-none-eabi-16.2.0
The C++ standard library for arm-none-eabi, built against picolibc
| Version | 16.2.0, release 1 |
| Shelf | embedded — Microcontroller and bare-metal development: cross toolchains, C libraries, flashers, debug probes and serial consoles |
| Phase | 41_system (System), 469 of 1047 in build order |
| Licence | GPL-3.0-or-later WITH GCC-exception-3.1 |
| Homepage | https://gcc.gnu.org/ |
| Build time | 52.7 SBU |
| Installed size | 209.6 MiB in 1624 files |
| Recipe | ports/core/embedded/libstdcxx-arm-none-eabi/kpkgbuild |
About
The C++ standard library for bare-metal ARM: libstdc++.a, libsupc++.a and libstdc++exp.a for every multilib of gcc-arm-none-eabi, and the headers under /usr/arm-none-eabi/include/c++, built against picolibc. With it arm-none-eabi-g++ can compile and link C++ firmware for the Cortex-M and Cortex-R parts of its rmprofile multilib set, and picotool, whose RP2350 helper programs are pico-sdk projects that enable C++, depends on it. It is the second build of the cross compiler’s gcc source: libstdc++ compiles against the target C library, and picolibc is built with that compiler, so the compiler, the C library and this library are three recipes. How the split works is in A second build of the same source.
Why it is in KDOS
The comment above the 4 ports from binutils-arm-none-eabi to libstdcxx-arm-none-eabi in script/phases/41_system/packages.d/embedded.txt:
THE ORDER IS THE DEPENDENCY. binutils first, then a gcc built --without-headers so libgcc can exist before a libc does, then the libc built WITH that gcc. One recipe cannot do the last two: the compiler has to be installed before the library it compiles can configure against it.
Cortex-M and Cortex-R. --with-multilib-list=rmprofile is what keeps this to the profiles a microcontroller actually is, rather than every ARM variant since 1985.
Sources
gcc-arm-none-eabi-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: gcc-arm-none-eabi, binutils-arm-none-eabi, picolibc-arm-none-eabi, gmp, mpfr, mpc, zlib, zstd.
Required by (1): picotool.
Patches
build.sh applies these; kpkg applies nothing by itself.
picolibc-long-double-math.patch— In bothlibstdc++-v3/configure.acand the generatedconfigure, adds theHAVE_*Ldefinitions (HAVE_ACOSLthroughHAVE_TANHL) for thelong doublemaths functions to libstdc++’s picolibc branch, which defines only thefloatones although picolibc has both. Without them<cmath>declares nostd::acosland its kin, and the C++23stdmodule does not compile.
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/41_system/phase.env && kpkg install libstdcxx-arm-none-eabi'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/embedded/libstdcxx-arm-none-eabi.
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/embedded/libstdcxx-arm-none-eabi
echo 'e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e gcc-arm-none-eabi-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/libstdcxx-arm-none-eabi
SRC=$SRC_ROOT/libstdcxx-arm-none-eabi-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-arm-none-eabi-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 recipe’s helpers _up, group and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/picolibc-long-double-math.patch"
mkdir -p build && cd build
../configure \
--target=arm-none-eabi \
--prefix=/usr \
--libexecdir=/usr/lib \
--with-sysroot=/usr/arm-none-eabi \
--with-native-system-header-dir=/include \
--enable-languages=c,c++ \
--with-picolibc \
--without-newlib \
--with-headers=no \
--disable-nls \
--disable-shared \
--disable-threads \
--disable-libssp \
--disable-libgomp \
--disable-libquadmath \
--disable-libatomic \
--disable-libstdcxx-pch \
--disable-libstdcxx-verbose \
--enable-hosted-libstdcxx \
--disable-decimal-float \
--with-gnu-as --with-gnu-ld \
--with-zstd=/usr \
--without-isl \
--enable-multilib \
--with-multilib-list=rmprofile \
--with-pkgversion="KDOS" \
CFLAGS_FOR_TARGET="-Os -pipe -ffunction-sections -fdata-sections" \
CXXFLAGS_FOR_TARGET="-Os -pipe -ffunction-sections -fdata-sections"
make all-target-libstdc++-v3 2>&1 | tee ../libstdcxx-build.log
test "${PIPESTATUS[0]}" -eq 0
if grep -F 'stamp-modules-bits] Error' ../libstdcxx-build.log; then
exit 1
fi
make -C arm-none-eabi/libstdc++-v3 DESTDIR=$PKG install
find "$PKG" \( -name '*.la' -o -name '*-gdb.py' \) -delete
rm -rf "$PKG/usr/share"
The switches, and why each is set:
--target=arm-none-eabi,--prefix=/usr,--libexecdir=/usr/lib,--with-sysroot=/usr/arm-none-eabi,--enable-multilib,--with-multilib-list=rmprofile— The options gcc-arm-none-eabi is configured with;--enable-multilibis gcc’s default, which that recipe leaves unstated. They have to match it: the prefix, the sysroot and the multilib set decide the directories the libraries are installed in, and the installed compiler driver searches only its own.--with-native-system-header-dir=/include— Where the C library’s headers are, relative to the sysroot. picolibc’s headers are in/usr/arm-none-eabi/include, not in the sysroot’s/usr/include, and without the switch the build stops atfixincludes, which looks for a directory that does not exist.--with-picolibc,--without-newlib— Select libstdc++’s picolibc configuration: theos/picolibcsupport files and a fixed list of the functions picolibc provides, taken without link tests, which a bare-metal target cannot run.--with-picolibcalso keeps libtool’sdlopenprobe, a link test, out of configure. configure tests for newlib before picolibc, so--with-newlibwould take the newlib branch and itsos/newlibfiles instead.--with-headers=no— In libstdc++’s configure, takes#include <stdio.h>out of the prologue autoconf puts in front of every compile test, and, with--without-newlibbeside it, makes the library default to a freestanding build, which--enable-hosted-libstdcxxreverses.--enable-hosted-libstdcxx— Builds the hosted library, with streams, strings, containers and the rest, which picolibc can support, rather than the freestanding subset.--disable-libstdcxx-verbose— Leaves the verbose terminate handler out of the library. That handler prints the type and message of an uncaught exception, and pulls the demangler and stdio into every firmware image that can throw.--disable-shared,--disable-threads,--disable-libstdcxx-pch— Static archives only, no thread support and no precompiled headers, as in gcc-arm-none-eabi.--disable-libssp,--disable-libgomp,--disable-libquadmath,--disable-libatomic,--disable-decimal-float— The other target libraries and features a gcc build can make for its target, none of which this build installs.--with-zstd=/usr,--without-isl— The host side of the configured compiler: zstd for compressed LTO streams, and no isl loop optimiser, as in gcc-arm-none-eabi. Nothing of the compiler itself is installed from this build.--with-pkgversion="KDOS"— The string the compiler prints in place of(GCC)in its version line.CFLAGS_FOR_TARGET,CXXFLAGS_FOR_TARGET— The flags for the target libraries:-Os -pipe -ffunction-sections -fdata-sections, nothing from the host’s flags.-Osbecause every byte oflibstdc++a firmware links lands in the part’s flash, and the per-function sections let--gc-sectionsdrop what a firmware image does not call. See A language standard reaching the compiler’s own runtime.
The common switches of each build system are explained in the Flag glossary.
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/libstdcxx-arm-none-eabi, 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 libstdcxx-arm-none-eabi-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/libstdcxx-arm-none-eabi, and runs the triggers its paths call for.
Contents
Installed directories: /usr/arm-none-eabi/include/c++, /usr/share/licenses/libstdcxx-arm-none-eabi.
Notes
- The build log is checked for the
stdmodule. When the module interface fails, make printsstamp-modules-bits] Error 1 (ignored)and goes on, and the package would ship alibstdc++.modules.jsonthat advertises a module that does not exist.build.shtees the output ofmake all-target-libstdc++-v3to a log, fails on make’s own exit status, and fails again if that line is in the log. - Only libstdc++ is installed. The install runs
make installinarm-none-eabi/libstdc++-v3, not the top-levelinstall-target-libstdc++-v3, which installslibgccfirst and would give this package files gcc-arm-none-eabi owns. The libtool.lafiles are deleted, and so are the-gdb.pypretty-printer loaders beside each archive and/usr/share, where the printers would land in/usr/share/gcc-<version>/python, the host gcc’s own path; a loader beside a static archive is never auto-loaded anyway. - The version is the compiler’s. The recipe carries the gcc tarball under gcc-arm-none-eabi’s file name and checksum, and both recipes carry
group = gcc-arm-none-eabi, so the two are bumped together.