mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-27 01:47:18 -04:00
fix(gpu-libs): bundle transitive deps of GPU runtime libs The per-vendor packagers in package-gpu-libs.sh copy an explicit allowlist of top-level GPU runtime libraries (libamdhip64, libhipblas, librocblas, the CUDA/Intel equivalents, ...) but never resolved their transitive dependencies. Backends run through the bundled lib/ld.so with LD_LIBRARY_PATH=lib, so any transitive dep not in the allowlist is a fatal "cannot open shared object file" at load time. On recent ROCm (base image rocm 7.2.1) the runtime libs link against librocprofiler-register.so.0, which is not in the allowlist, so the rocm llama-cpp backend (and every other GPU backend sharing this script) failed to load with: librocprofiler-register.so.0: cannot open shared object file The Vulkan path already solved this class of problem with copy_elf_deps (ldd-based transitive resolution), but that sweep was only wired into the Vulkan ICD path. This adds a generic sweep_transitive_deps that runs the same ldd resolution over everything the allowlist already bundled, and wires it into the ROCm, CUDA and Intel packagers. ldd returns the full recursive closure, so one pass suffices; core libc-family deps are skipped via is_core_lib so we never shadow the loader's own libc/libstdc++. Adds a self-contained regression test (gcc + ldd) that fabricates a primary lib linking a transitive lib and asserts the sweep bundles the dependency. Fixes #10537 Assisted-by: Claude:opus-4.8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
55 lines
2.0 KiB
Bash
Executable File
55 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Regression test for scripts/build/package-gpu-libs.sh.
|
|
#
|
|
# Guards issue #10537: the per-vendor packagers copy an explicit allowlist of
|
|
# top-level GPU runtime libs but used to miss their transitive dependencies
|
|
# (e.g. ROCm's librocprofiler-register.so.0). Since backends run through the
|
|
# bundled lib/ld.so with LD_LIBRARY_PATH=lib, an unbundled transitive dep is a
|
|
# fatal "cannot open shared object file" at load time.
|
|
#
|
|
# This test fabricates a primary lib that links a transitive lib, simulates the
|
|
# allowlist step (primary copied, transitive not), and asserts the transitive
|
|
# sweep pulls the dependency in. Requires gcc + ldd (present in build images).
|
|
set -euo pipefail
|
|
|
|
CURDIR=$(dirname "$(realpath "$0")")
|
|
SCRIPT="$CURDIR/package-gpu-libs.sh"
|
|
|
|
if ! command -v gcc >/dev/null 2>&1 || ! command -v ldd >/dev/null 2>&1; then
|
|
echo "SKIP: gcc/ldd not available"
|
|
exit 0
|
|
fi
|
|
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
# Transitive dependency (stand-in for librocprofiler-register.so.0).
|
|
echo 'int transitive_fn(void){return 42;}' > "$WORK/transitive.c"
|
|
gcc -shared -fPIC -o "$WORK/libfaketransitive.so.0" "$WORK/transitive.c"
|
|
|
|
# Primary allowlisted lib (stand-in for libhipblas.so) that links it.
|
|
echo 'int transitive_fn(void); int primary_fn(void){return transitive_fn();}' > "$WORK/primary.c"
|
|
gcc -shared -fPIC -o "$WORK/libfakeprimary.so.0" "$WORK/primary.c" \
|
|
-L"$WORK" -l:libfaketransitive.so.0 -Wl,-rpath,"$WORK"
|
|
|
|
# Simulate the allowlist step: primary already bundled, transitive not.
|
|
TARGET="$WORK/target"
|
|
mkdir -p "$TARGET"
|
|
cp "$WORK/libfakeprimary.so.0" "$TARGET/"
|
|
|
|
# Make the transitive dep resolvable like /opt/rocm libs are in the build image.
|
|
export LD_LIBRARY_PATH="$WORK:${LD_LIBRARY_PATH:-}"
|
|
|
|
# shellcheck source=/dev/null
|
|
source "$SCRIPT" "$TARGET"
|
|
sweep_transitive_deps "$TARGET"
|
|
|
|
if [ -e "$TARGET/libfaketransitive.so.0" ]; then
|
|
echo "PASS: transitive dependency was bundled by sweep_transitive_deps"
|
|
exit 0
|
|
fi
|
|
|
|
echo "FAIL: transitive dependency was NOT bundled (regression of #10537)"
|
|
ls -la "$TARGET"
|
|
exit 1
|