Skip to content

make-binary-drop: count the embedded ELF images, not the fatbin's spelling of amdgcn-amd-amdhsa - #1452

Merged
bong-water-water-bong merged 1 commit into
mainfrom
verify/1443-drop-el-magic
Nov 8, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
verify/1443-drop-el-magic

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #1443

The bug, reproduced

scripts/make-binary-drop.sh (:158-159 on current main; the report cites :222-224, the script has moved since) refused the
shipped library and accepted a different one:

n=$(strings -a "$stage/hrx/llama/bin/libggml-hrx.so" | grep -c amdgcn-amd-amdhsa || true)
[ "$n" != 0 ] || fail "libggml-hrx.so carries no HIP code objects"

Exact byte counts (python3 over the files, and the shell check agrees):

library size \x7fELF images gfx1151 amdgcn-amd-amdhsa old check new check
shipped c31 payload …/1bit/hrx/llama/bin/libggml-hrx.so.0.18.0 11,213,184 56 64 0 FAIL PASS
~/wt/tprs-hrx-154/bin/libggml-hrx.so.0.18.0 5,513,432 3 16 2 PASS PASS

So the 56-code-object library was refused and the 3-code-object one accepted: the string is an artefact of how the fatbin was
assembled, not evidence that kernels are in it.

The change

Count the embedded ELF images instead — the library's own header is one, every embedded code object adds one, so a library with kernels
compiled in always has more than one — and put the count in the failure message so a future refusal is diagnosable from the log alone:

elf_images=$(LC_ALL=C grep -ao $'\x7fELF' "$stage/hrx/llama/bin/libggml-hrx.so" | wc -l)
[ "$elf_images" -gt 1 ] || fail "libggml-hrx.so carries no embedded code objects (${elf_images} ELF image(s): only the library's own header, so no fatbin entries)"

No new dependency: the script uses no python3 today, so this stays in the shell. I did not take the llvm-readobj --offloading
option (authoritative, but it adds an SDK tool to a path whose whole job is to work on a machine that may not have one); the
gfx1151-either-spelling option was also skipped because a count of embedded images says the property rather than two spellings of it.

Verification

  • bash -n scripts/make-binary-drop.sh — clean.
  • shellcheck -S warning — only the pre-existing SC2043 at line 103 (single-item for loop), untouched by this change.
  • The new condition run against both real libraries above: 56 → PASS, 3 → PASS; the old one FAIL/PASS.
  • Not run: the whole make-binary-drop.sh. It needs a release build to stage, and the box was at load 78 with the GPU queue
    12 deep; the one thing this PR changes is the check, and the check is exercised on the two libraries the issue measured. A reviewer
    with a build should run the full script once before this merges — that is the only step I could not do at the time.

…lling of amdgcn-amd-amdhsa

The check refused the shipped c31 library while accepting a smaller build: the c31
libggml-hrx.so carries 56 embedded code objects and zero occurrences of the string
`amdgcn-amd-amdhsa`, and a 3-object build carries two -- the string depends on how the fatbin was
assembled, so it cannot stand in for "the kernels are compiled in" (engine#1443). Count the embedded
ELF images instead: the library's own header is one and every code object adds one, so a library with
the kernels compiled in always has more than one. The count goes into the failure message so a future
refusal is diagnosable from the log alone.

Measured on the two libraries the issue names, python3 and this grep agree:

  c31 payload   11,213,184 B  ELF images 56  old string 0  ->  old FAIL, new PASS
  tprs-hrx-154   5,513,432 B  ELF images  3  old string 2  ->  old PASS, new PASS

No new dependency (the script uses no python3 today, so the grep stays in the shell).

Fixes #1443
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at d56c5b101 (pi-prs). One hunk in scripts/make-binary-drop.sh: the code-object check counts embedded \x7fELF images instead of grepping amdgcn-amd-amdhsa, with the count in the failure message. Verified on the two libraries the issue measured (c31: 56 images/0 strings — old FAIL, new PASS; tprs-hrx-154: 3/2 — both PASS), bash -n clean, shellcheck shows only the pre-existing SC2043. The full script was not run (needs a release build to stage; box at load 78, GPU queue 12) — a reviewer with a build should run it once before merge.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at d56c5b101d8326b4303e4b190c0d64dda752ccb9

The right fix for #1443: count what the property is (embedded code-object ELF images), not a string whose presence depends on how the fatbin was assembled.

Reproduced with the PR's exact expression (LC_ALL=C grep -ao $'\x7fELF' … | wc -l) on the two libraries it measured:

~/wt/release-rc/work/lemonade/1bit/hrx/llama/bin/libggml-hrx.so.0.18.0   elf_images=56  amdgcn-amd-amdhsa=0   old FAIL, new PASS
~/wt/tprs-hrx-154/bin/libggml-hrx.so.0.18.0                              elf_images=3   amdgcn-amd-amdhsa=2   old PASS, new PASS

My copy of the release-rc library is 11,235,176 B against your 11,213,184 B (a later build at the same path), with the same counts. bash -n passes at this head, and the failure message now carries the count, which makes a future refusal readable from the log.

Two notes for the future, not blocking:

  • Compressed offload bundles would defeat this. With --offload-compress, each code object is a CCOB blob and its ELF magic isn't in the file, so a library full of kernels would count 1 and be refused. Both libraries above have 0 CCOB occurrences, so it's not today's problem, and it fails loudly rather than silently. A comment saying "if the build ever compresses offload bundles, count CCOB too" would save the next person the search.
  • "More than one ELF image" proves kernels are present, not that they're for this GPU. A gfx1100-only build passes too. Since the drop is a gfx1151 artifact, adding grep -c gfx1151 as a second condition (the library above has 64) would make the check say the whole property.

@bong-water-water-bong
bong-water-water-bong merged commit 7ee454d into main Nov 8, 2026
8 of 9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the verify/1443-drop-el-magic branch November 8, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant