fix(gpu-libs): bundle transitive deps of GPU runtime libs (#10537)#10539
Conversation
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>
Validation against the real released imageReproduced and verified against Bug reproduced: the image bundles Confirmed it's a Full audit of every bundled lib's A naive "add Residual note: this was validated by static |
What
Fixes #10537 — the ROCm
llama-cppbackend (and every other GPU backend) fails to load with:Root cause
scripts/build/package-gpu-libs.shis the shared GPU-lib packager used by all GPU backends. Its per-vendor packagers (package_rocm_libs,package_cuda_libs,package_intel_libs) copy a fixed allowlist of top-level runtime libs (libamdhip64,libhipblas,librocblas, ...) but never resolved their transitive dependencies.Backends run through the bundled
lib/ld.sowithLD_LIBRARY_PATH=lib(seerun.sh), so the binary only sees what's inlib/. On recent ROCm (base imagerocm 7.2.1) the runtime libs link againstlibrocprofiler-register.so.0, which is not in the allowlist, so it's never bundled — a hard load failure.libhipblas.soitself loads fine (it is allowlisted), which matches the issue report.This is not related to the llama.cpp shared-libs change.
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.Fix
sweep_transitive_depsthat runs the existingcopy_elf_deps(ldd) over everything the allowlist already bundled.lddreturns the full recursive closure, so one pass suffices.is_core_lib, so we never shadow the loader's ownlibc/libstdc++.Because the script is shared, this fixes the missing-transitive-dep class for llama-cpp, whisper, stablediffusion-ggml, turboquant, ds4, and the rest in one place.
Testing
scripts/build/package-gpu-libs_test.sh: a self-contained regression test (gcc + ldd) that fabricates a primary lib linking a transitive lib, simulates the allowlist step, and asserts the sweep bundles the transitive dep. Red before the fix, green after.cpuandhipblas-without-/opt/rocmpaths (graceful no-op / warning).🤖 Generated with Claude Code