Skip to content

package-linux: the HSA runtime set ships with RUNPATH $ORIGIN, so a package from the pinned toolchain passes payload-runpath (engine#3287) - #3313

Merged
bong-water-water-bong merged 3 commits into
mainfrom
1bit/pkg-hsa-set-origin
Nov 22, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
1bit/pkg-hsa-set-origin

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #3287 (release tooling: the cut must reproduce the tested payload from a fresh build).

Problem. scripts/package-linux.sh stages TheRock's HSA runtime set (libhsa-runtime64.so.1, aqlprofile, rocprofiler-register, the 8 rocm_sysdeps libraries) as built. TheRock links them with RPATHs into its own pip tree ($ORIGIN/../../_rocm_sdk_core/lib/llvm/lib, $ORIGIN/rocm_sysdeps/lib, ...), so a package made from the pinned toolchain (config/hrx-toolchain.config, 10.3.0a20261031) carries 11 non-$ORIGIN RPATHs and fails 1bit-release-check's payload-runpath row. The c35 payload passed only because its set had been rewritten outside the tree.

Fix. pack_origin_rpath <dir> in scripts/pack-elf.sh: every dynamic ELF directly in <dir> that carries an RPATH/RUNPATH gets $ORIGIN alone; files with none, or already $ORIGIN, stay byte-identical; no recursion, symlinks untouched. package-linux.sh calls it on hrx/llama/bin after staging the set and before the set's own ldd check. NOTICE-BINARY now says the RUNPATH is the one change to the set.

Measured (ryzen, 2026-11-22), packaging an engine build made with the pinned toolchain at /opt/rocm-sdk/rocm-sdk-10.3.0a20261031-gfx1151:

  • before: 11 files in the package with RPATHs other than $ORIGIN (all in the HSA set)
  • after: hrx/llama/bin: + the HSA runtime set (12 files ...; 11 RUNPATH(s) set to $ORIGIN), 0 non-$ORIGIN RUNPATHs in the package
  • the 12 HSA-set files are byte-for-byte the tested c35 payload's (cmp against rel-c35/payload/1bit/hrx/llama/bin; libhsa-runtime64.so.1 sha256 f5462dc3…, from the pin's 21a66824…)

Tests. tests/pack_origin_rpath_test.sh (ctest pack_origin_rpath): compiled fixtures with a TheRock-shaped DT_RPATH and a RUNPATH are rewritten and still resolve their sibling with no LD_LIBRARY_PATH; $ORIGIN-only and rpath-less libraries, a subdirectory, a symlink and a non-ELF file are untouched; a second run changes nothing; package-linux.sh calls it between staging the set and checking it. pack_modes and pack_check still pass. scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.

Hardware: not yet run on strixhalo with this exact package (queued behind the GPU lock); I will add the result as a comment.

🤖 Generated with Claude Code

…ackage from the pinned toolchain passes payload-runpath (engine#3287)

TheRock links libhsa-runtime64.so.1 and its siblings with RPATHs into its own pip tree
($ORIGIN/../../_rocm_sdk_core/lib/llvm/lib, ...). package-linux.sh staged the set as built, so a package made
from the pinned toolchain (config/hrx-toolchain.config) carried 11 non-$ORIGIN RPATHs and failed the release
check's payload-runpath row; the c35 payload passed only because its set had been rewritten outside the tree.

pack_origin_rpath (scripts/pack-elf.sh) gives every dynamic ELF directly in a directory that carries an RPATH
$ORIGIN alone, leaving files with none or with $ORIGIN already byte-identical. package-linux.sh runs it on
hrx/llama/bin after staging the set and before the set's ldd check. Measured: a package from the pinned toolchain
now has 0 non-$ORIGIN RUNPATHs and its 12 HSA-set files are byte-for-byte the tested c35 payload's
(libhsa-runtime64.so.1 sha256 f5462dc3...). NOTICE-BINARY says the RUNPATH is the one change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 4bc3e26)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3287 - Partially compliant

Compliant requirements:

  • The cut must use the freshly rolled payload

Non-compliant requirements:

  • The pre-write probe must be able to stop the write
  • Keep the shipped image

Requires further human verification:

  • The pre-write probe must be able to stop the write
  • Keep the shipped image
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential RPATH Handling Issue

The pack_origin_rpath function modifies the RPATH/RUNPATH of ELF files directly in a given directory. While it correctly identifies and changes non-$ORIGIN RPATHs, it does not handle cases where multiple RPATH entries exist and only one needs to be changed. This could lead to unintended behavior if the original RPATH contains multiple paths, and only some are valid for the payload's structure.

pack_origin_rpath() {  # <dir>
    local d=$1 f rp n=0
    for f in "$d"/*; do
        [ -f "$f" ] && [ ! -L "$f" ] || continue
        pack_is_dynelf "$f" || continue
        rp=$(readelf -d "$f" 2>/dev/null | sed -n 's/.*(R\(UN\)\{0,1\}PATH).*path: \[\(.*\)\]/\2/p' | head -1)
        [ -n "$rp" ] && [ "$rp" != '$ORIGIN' ] || continue   # none, or already $ORIGIN: the bytes stay as they are
        patchelf --set-rpath '$ORIGIN' "$f" || { echo "pack_origin_rpath: cannot set the RUNPATH of $f" >&2; return 1; }
        n=$((n + 1))
    done
    echo "$n"
}
Assumption about HSA Set Structure

The script assumes that the HSA runtime set is flat in the hrx/llama/bin directory and that it will be correctly resolved by the $ORIGIN path. If the set is not structured as expected or if there are dependencies not correctly handled, this could lead to runtime failures or incorrect behavior.

n_origin=$(pack_origin_rpath "$stage/hrx/llama/bin") || exit 1

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Hardware (strixhalo, AI MAX+ 395, c35 appliance, 2026-11-22): this branch's package (built on ryzen with the pinned toolchain), served through its OWN rewritten HSA set:

box-hold gpu sudo -n sh -c 'ulimit -l unlimited; sh serve-probe.sh pkg-hsa/1bit Qwen3-0.6B-Q4_K_M.gguf hrx 18436 --ctx-size 4096 --hrx-libhsa pkg-hsa/hrx/llama/bin/libhsa-runtime64.so.1'
1bit serve: HRX: HSA runtime .../pkg-hsa/hrx/llama/bin/libhsa-runtime64.so.1 sha256 f5462dc36b0a18a874cea3050de710e4f05b10e9bf53b3172515515edb3638de
known-answer (17+25 -> 42, capital of France -> Paris, first five primes) at temperature 0, three runs each: 9/9, decode ~300 tok/s

So the set loads and drives HRX0 with RUNPATH $ORIGIN alone. (--hrx-libhsa is needed to make serve pick the package's copy on a box that has /opt/rocm-therock; serve ignores a user-set IREE_HAL_AMDGPU_LIBHSA_PATH - filed separately.)

…the CI container instead of skipping

The build job installs gcc-16 (no bare cc), patchelf and binutils; the test looked for cc/gcc/clang only and returned 77.
A missing tool is now a failure, not a skip, and the SKIP_RETURN_CODE property is gone. Run in ubuntu:26.04 (the CI
image, unprivileged) with gcc-16 binutils patchelf: PASS, all 12 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 7c40cb5

…d print ldd/readelf when it does not resolve

CI's build job reported 'librunpath.so.1 does not resolve libdep.so.1 beside itself' once; 16 parallel runs in the
same ubuntu:26.04 image with gcc-16 pass. The row now says what ldd resolved and shows the dynamic section, so the
next failure names its cause instead of a bare FAIL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 4bc3e26

@bong-water-water-bong
bong-water-water-bong merged commit f845d2a into main Nov 22, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/pkg-hsa-set-origin branch November 22, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant