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

161.15. libstdcxx-riscv64-unknown-elf-16.2.0

The C++ standard library for riscv64-unknown-elf, 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), 473 of 1047 in build order
Licence GPL-3.0-or-later WITH GCC-exception-3.1
Homepage https://gcc.gnu.org/
Build time 30.6 SBU
Installed size 86.7 MiB in 1057 files
Recipe ports/core/embedded/libstdcxx-riscv64-unknown-elf/kpkgbuild

About

The C++ standard library for bare-metal RISC-V: libstdc++.a, libsupc++.a and libstdc++exp.a for every multilib of gcc-riscv64-unknown-elf, from rv64gc with the lp64d ABI down to the rv32i variants, and the headers under /usr/riscv64-unknown-elf/include/c++, built against picolibc. With it riscv64-unknown-elf-g++ can compile and link C++ for RV32 and RV64 microcontrollers and for the soft cores the FPGA tools synthesise. 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. It is the same build as libstdcxx-arm-none-eabi for the other target; 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-riscv64-unknown-elf to libstdcxx-riscv64-unknown-elf in script/phases/41_system/packages.d/embedded.txt:

RV32 and RV64 — the MCUs and the soft cores the FPGA flow (yosys, nextpnr) synthesises.

Sources

Dependencies

Depends on: gcc-riscv64-unknown-elf, binutils-riscv64-unknown-elf, picolibc-riscv64-unknown-elf, gmp, mpfr, mpc, zlib, zstd.

Required by: no port names it.

Patches

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

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-riscv64-unknown-elf'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/embedded/libstdcxx-riscv64-unknown-elf.

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-riscv64-unknown-elf
echo 'e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e  gcc-riscv64-unknown-elf-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-riscv64-unknown-elf
SRC=$SRC_ROOT/libstdcxx-riscv64-unknown-elf-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-riscv64-unknown-elf-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=riscv64-unknown-elf \
	--prefix=/usr \
	--libexecdir=/usr/lib \
	--with-sysroot=/usr/riscv64-unknown-elf \
	--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-abi=lp64d --with-arch=rv64gc \
	--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 riscv64-unknown-elf/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:

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-riscv64-unknown-elf, 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-riscv64-unknown-elf-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-riscv64-unknown-elf, and runs the triggers its paths call for.

Contents

Installed directories: /usr/riscv64-unknown-elf/include/c++, /usr/share/licenses/libstdcxx-riscv64-unknown-elf.

Notes