summaryrefslogtreecommitdiffstats
path: root/scripts/check-glibc.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/check-glibc.sh24
1 files changed, 19 insertions, 5 deletions
diff --git a/scripts/check-glibc.sh b/scripts/check-glibc.sh
index bb9052f..b02cd75 100755
--- a/scripts/check-glibc.sh
+++ b/scripts/check-glibc.sh
@@ -4,6 +4,10 @@
4# The dev host's 32-bit glibc is newer than Debian 12's, so a dependency can 4# The dev host's 32-bit glibc is newer than Debian 12's, so a dependency can
5# silently raise the required symbol version. Without this check the failure 5# silently raise the required symbol version. Without this check the failure
6# only shows up as "version `GLIBC_2.38' not found" on the target machine. 6# only shows up as "version `GLIBC_2.38' not found" on the target machine.
7#
8# Weak undefined symbols are ignored: they resolve to NULL on older libc and the
9# code paths using them fall back. Rust's std does this for glibc 2.39's
10# pidfd_spawnp/pidfd_getpid, for example.
7set -euo pipefail 11set -euo pipefail
8 12
9binary=${1:?usage: check-glibc.sh <binary> [ceiling, default 2.36]} 13binary=${1:?usage: check-glibc.sh <binary> [ceiling, default 2.36]}
@@ -14,21 +18,31 @@ if [ ! -f "$binary" ]; then
14 exit 2 18 exit 2
15fi 19fi
16 20
17max=$(readelf -V "$binary" 2>/dev/null \ 21required=$(readelf --dyn-syms --wide "$binary" 2>/dev/null \
22 | awk '$5 != "WEAK" { print }' \
23 | grep -oE 'GLIBC_[0-9]+\.[0-9]+' \
24 | sed 's/^GLIBC_//' \
25 | sort -Vu \
26 | tail -1 || true)
27weak=$(readelf --dyn-syms --wide "$binary" 2>/dev/null \
28 | awk '$5 == "WEAK" { print }' \
18 | grep -oE 'GLIBC_[0-9]+\.[0-9]+' \ 29 | grep -oE 'GLIBC_[0-9]+\.[0-9]+' \
19 | sed 's/^GLIBC_//' \ 30 | sed 's/^GLIBC_//' \
20 | sort -Vu \ 31 | sort -Vu \
21 | tail -1 || true) 32 | tail -1 || true)
22 33
23if [ -z "${max:-}" ]; then 34if [ -z "${required:-}" ]; then
24 echo "check-glibc: no versioned symbols (statically linked?) — nothing to check" 35 echo "check-glibc: no versioned symbols (statically linked?) — nothing to check"
25 exit 0 36 exit 0
26fi 37fi
27 38
28echo "check-glibc: max symbol version GLIBC_$max, ceiling GLIBC_$ceiling" 39echo "check-glibc: required GLIBC_$required, ceiling GLIBC_$ceiling"
40if [ -n "${weak:-}" ] && [ "$weak" != "$required" ]; then
41 echo "check-glibc: weak GLIBC_$weak (optional, resolves to NULL on older libc)"
42fi
29 43
30if [ "$(printf '%s\n%s\n' "$ceiling" "$max" | sort -V | tail -1)" != "$ceiling" ]; then 44if [ "$(printf '%s\n%s\n' "$ceiling" "$required" | sort -V | tail -1)" != "$ceiling" ]; then
31 echo "check-glibc: FAIL — binary needs GLIBC_$max, target has GLIBC_$ceiling" >&2 45 echo "check-glibc: FAIL — binary needs GLIBC_$required, target has GLIBC_$ceiling" >&2
32 exit 1 46 exit 1
33fi 47fi
34 48