From 9001b768c1455e640dcbf89b5bbe4c417fe4c562 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Tue, 3 Nov 2026 00:02:24 +0800 Subject: [PATCH] fix(packaging): record required library ABIs on Arch and OpenBSD --- Makefile | 2 + crates/openconnect/build.rs | 2 +- .../globalprotect-openconnect-git/PKGBUILD | 2 + packaging/pkgbuild/PKGBUILD.in | 2 + scripts/openbsd-library-dependencies.sh | 16 ++++++++ scripts/tests/openbsd-library-dependencies.sh | 41 +++++++++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 scripts/openbsd-library-dependencies.sh create mode 100644 scripts/tests/openbsd-library-dependencies.sh diff --git a/Makefile b/Makefile index 76a23ad..8e531fc 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,9 @@ package-openbsd: clean-bsd-package $(MAKE) install-bsd DESTDIR=$(CURDIR)/.build/openbsd/pkgroot PREFIX=$(PREFIX) GPGUI_BINARY="$(GPGUI_BINARY)" cp packaging/bsd/openbsd/COMMENT .build/openbsd/+COMMENT cp packaging/bsd/openbsd/DESC .build/openbsd/+DESC + sh scripts/openbsd-library-dependencies.sh .build/openbsd/pkgroot > .build/openbsd/WANTLIB { \ + cat .build/openbsd/WANTLIB; \ echo '@unexec-delete /bin/rm -f /usr/local/libexec/gpclient/gpgui /var/db/gpclient/scripts/vpnc-script /var/db/gpclient/scripts/vpnc-script.metadata || echo "Warning: failed to remove gpclient runtime files" >&2'; \ echo '@unexec-delete /bin/rmdir /usr/local/libexec/gpclient 2>/dev/null || true'; \ echo '@unexec-delete /bin/rmdir /var/db/gpclient/scripts 2>/dev/null || true'; \ diff --git a/crates/openconnect/build.rs b/crates/openconnect/build.rs index 4d5d1c5..c5b7ca5 100644 --- a/crates/openconnect/build.rs +++ b/crates/openconnect/build.rs @@ -224,7 +224,7 @@ fn main() { pkg_config::probe_library("liblz4").unwrap(); pkg_config::probe_library("gnutls").unwrap(); - // Below are required by gnutls + // OpenConnect also uses Hogweed/GMP directly for its GnuTLS backend. pkg_config::probe_library("p11-kit-1").unwrap(); pkg_config::probe_library("hogweed").unwrap(); pkg_config::probe_library("nettle").unwrap(); diff --git a/packaging/aur/globalprotect-openconnect-git/PKGBUILD b/packaging/aur/globalprotect-openconnect-git/PKGBUILD index 0d011e5..dc3a358 100644 --- a/packaging/aur/globalprotect-openconnect-git/PKGBUILD +++ b/packaging/aur/globalprotect-openconnect-git/PKGBUILD @@ -43,6 +43,8 @@ build() { } package() { + # Record the Hogweed ABI used by OpenConnect. + depends+=('libhogweed.so') cd "${_pkgname_prefix}" DESTDIR="$pkgdir" make install diff --git a/packaging/pkgbuild/PKGBUILD.in b/packaging/pkgbuild/PKGBUILD.in index 4757a0d..26f1a83 100644 --- a/packaging/pkgbuild/PKGBUILD.in +++ b/packaging/pkgbuild/PKGBUILD.in @@ -31,6 +31,8 @@ build() { } package() { + # Record the Hogweed ABI used by OpenConnect. + depends+=('libhogweed.so') cd "$pkgname-$pkgver" make install DESTDIR="$pkgdir" diff --git a/scripts/openbsd-library-dependencies.sh b/scripts/openbsd-library-dependencies.sh new file mode 100644 index 0000000..0672419 --- /dev/null +++ b/scripts/openbsd-library-dependencies.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Record the library ABIs required by the staged OpenBSD executables. +set -eu + +root=$1 +temp=$(mktemp -d) +trap 'rm -rf "$temp"' EXIT HUP INT TERM +find "$root" -type f > "$temp/files" +while IFS= read -r file; do + case $(file -b "$file") in + ELF*) objdump -p "$file" >> "$temp/headers" ;; + esac +done < "$temp/files" +test -s "$temp/headers" +sed -n 's/^[[:space:]]*NEEDED[[:space:]]*lib\([^[:space:]]*\)\.so\.\([0-9][0-9]*\.[0-9][0-9]*\)[[:space:]]*$/@wantlib \1.\2/p' \ + "$temp/headers" | LC_ALL=C sort -u diff --git a/scripts/tests/openbsd-library-dependencies.sh b/scripts/tests/openbsd-library-dependencies.sh new file mode 100644 index 0000000..4d33907 --- /dev/null +++ b/scripts/tests/openbsd-library-dependencies.sh @@ -0,0 +1,41 @@ +#!/bin/sh +set -eu +root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) +temp=$(mktemp -d) +trap 'rm -rf "$temp"' EXIT HUP INT TERM +mkdir -p "$temp/bin" "$temp/stage/bin" +touch "$temp/stage/bin/gpclient" "$temp/stage/bin/gpauth" "$temp/stage/bin/script" +cat > "$temp/bin/file" <<'EOF' +#!/bin/sh +case $2 in + */script) echo 'POSIX shell script, ASCII text executable' ;; + *) echo 'ELF 64-bit LSB shared object, x86-64' ;; +esac +EOF +cat > "$temp/bin/objdump" <<'EOF' +#!/bin/sh +case $2 in + */gpclient) + printf 'Dynamic Section:\n NEEDED libhogweed.so.3.1\n NEEDED libc.so.103.0\n' + ;; + */gpauth) + printf ' NEEDED libc.so.103.0\n NEEDED libc++abi.so.9.0\n' + ;; + *) exit 1 ;; +esac +EOF +chmod +x "$temp/bin/file" "$temp/bin/objdump" +PATH="$temp/bin:$PATH" sh "$root/scripts/openbsd-library-dependencies.sh" "$temp/stage" > "$temp/actual" +cat > "$temp/expected" <<'EOF' +@wantlib c++abi.9.0 +@wantlib c.103.0 +@wantlib hogweed.3.1 +EOF +diff -u "$temp/expected" "$temp/actual" +# Failure to inspect an ELF file must stop packaging, not omit its requirements. +printf '#!/bin/sh\nexit 1\n' > "$temp/bin/objdump" +if PATH="$temp/bin:$PATH" sh "$root/scripts/openbsd-library-dependencies.sh" "$temp/stage" > /dev/null; then + echo 'Expected ELF inspection failure' >&2 + exit 1 +fi +echo 'OpenBSD library dependency checks passed.'