diff mbox series

[pseudo] test-glibc-symver: Add test for glibc version deps

Message ID 20261130130650.942556-1-david.nystrom@est.tech
State New
Headers show
Series [pseudo] test-glibc-symver: Add test for glibc version deps | expand

Commit Message

David Nyström Nov. 30, 2026, 1:06 p.m. UTC
A symbol version the host's glibc doesn't have makes every process
libpseudo.so is preloaded into die, so it is worth noticing at build
time rather than on whichever host is oldest.  Fail on the __isoc23_*
redirects, and on anything future needing more than
PSEUDO_MAX_GLIBC_VERSION (2.34 today)

Checked against both revisions of the io_uring mode parsing: it fails
on strtol() and passes on pseudo_strtol_wrapper().

AI-Generated: Uses Kiro CLI (claude-opus-5)
Signed-off-by: David Nyström <david.nystrom@est.tech>
---
 test/test-glibc-symver.sh | 68 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100755 test/test-glibc-symver.sh
diff mbox series

Patch

diff --git a/test/test-glibc-symver.sh b/test/test-glibc-symver.sh
new file mode 100755
index 0000000..da3d4c3
--- /dev/null
+++ b/test/test-glibc-symver.sh
@@ -0,0 +1,68 @@ 
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# libpseudo.so is preloaded into every process of a build, and a native build
+# of pseudo is shared between hosts (Yocto ships one in sstate).  A symbol
+# version the running host's glibc doesn't have is not ignored like a missing
+# preload: it is a fatal relocation error for every process, which is the
+# bitbake fakeroot worker dying before it reads its first byte.
+#
+# glibc 2.38 and later headers turn strtol(), strtoll() and atoi() into
+# __isoc23_* calls when _GNU_SOURCE is defined, which pseudo defines
+# everywhere, so those have to be reached through the wrappers in strtol.c and
+# pseudo_client_scanf.c.  This checks none of them, and nothing else newer
+# than PSEUDO_MAX_GLIBC_VERSION, has crept back in.
+#
+# A host whose own glibc is no newer than PSEUDO_MAX_GLIBC_VERSION cannot link
+# anything too new in the first place, so a pass there says nothing about the
+# source: pre-2.38 headers emit no __isoc23_* redirect at all, and the same
+# tree built on a newer host can still fail.
+
+: "${PSEUDO_PREFIX:=$PWD}"
+: "${PSEUDO_MAX_GLIBC_VERSION:=2.34}"
+
+if ! command -v nm >/dev/null 2>&1; then
+	echo "no nm to read symbol versions with" >&2
+	exit 255
+fi
+
+files=()
+for f in "$PSEUDO_PREFIX"/lib*/libpseudo.so \
+	 "$PSEUDO_PREFIX"/lib*/*/libpseudo.so \
+	 "$PSEUDO_PREFIX"/bin/pseudo "$PSEUDO_PREFIX"/bin/pseudodb; do
+	[ -f "$f" ] && files+=("$f")
+done
+
+if [ ${#files[@]} -eq 0 ]; then
+	echo "nothing built to check in $PSEUDO_PREFIX" >&2
+	exit 255
+fi
+
+newer_than_max() {
+	[ "$(printf '%s\n%s\n' "$1" "$PSEUDO_MAX_GLIBC_VERSION" | sort -V |
+	     tail -n 1)" != "$PSEUDO_MAX_GLIBC_VERSION" ]
+}
+
+# nm -D -u lists the symbols an object needs from elsewhere with the version
+# each resolves against, "U strtol@GLIBC_2.2.5", so what is left of those
+# lines once sed drops the symbol is the set of versions needed.
+rc=0
+seen=
+for f in "${files[@]}"; do
+	for v in $(nm -D -u "$f" 2>/dev/null | sed -n 's/.*@GLIBC_//p' | sort -u -V); do
+		seen=y
+		newer_than_max "$v" || continue
+
+		echo "$f needs GLIBC_$v, newer than the" >&2
+		echo "  GLIBC_$PSEUDO_MAX_GLIBC_VERSION pseudo has to run against" >&2
+		rc=1
+	done
+done
+
+# nm prints @GLIBC_ only from binutils 2.35(2020) on, and everything checked here
+# needs something from glibc, so no versions at all means the check could not
+# be made rather than that it passed.
+[ -n "$seen" ] || { echo "nm reports no symbol versions" >&2; exit 255; }
+
+exit $rc