Skip to content

hrx: tensor_is_host_resident has external linkage again (#403 left libggml-hrx.so with an undefined symbol) - #405

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/host-resident-linkage
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxmem/host-resident-linkage

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

1bit/hrx-vulkan-patched at 0a4126f (#403) builds a libggml-hrx.so with an undefined symbol. The first graph that reaches ggml-hrx.cpp:672 aborts:

llama-completion: symbol lookup error: libggml-hrx.so.0: undefined symbol: _ZN4ggml3hrx23tensor_is_host_residentEPK11ggml_tensor

(Hit loading Qwen3.8-Flash-Next with llama-completion on the branch tip. Both arms of my test died there, after the model had loaded.)

Cause

host-weight-placement.h declares ggml::hrx::tensor_is_host_resident, and ggml-hrx.cpp calls it, but host-weight-placement.cpp defines it inside namespace {. That gives it internal linkage, so nothing exports it. Shared libraries resolve lazily, so the build links fine and the failure only shows at run time.

Fix

Move the function, unchanged, above the anonymous namespace. host_resident_weight(), which stays in the anonymous namespace, still sees it.

Evidence (fork 0a4126f + this, gfx1151 build)

check before after
nm -D --defined-only libggml-hrx.so | grep -c tensor_is_host_resident 0 1
ldd -r llama-completion undefined symbols 1 0
ldd -r llama-server / libggml-hrx.so undefined symbols – / – 0 / 0

Engine impact: none yet, because engine pins fork 148e7f3, which is before #403. The next fork pin bump would ship this, so it needs to land first. My llama.cpp#404 (the --ple port) is stacked behind it for its device test.

Not run here: ctest. The change only moves a definition, and the check that matters is the linkage table above.

🤖 Generated with Claude Code

…ed it in an anonymous namespace

#403 (0a4126f) declares ggml::hrx::tensor_is_host_resident in host-weight-placement.h and calls it from
ggml-hrx.cpp, but defines it inside `namespace {` in host-weight-placement.cpp. The definition therefore has
internal linkage: libggml-hrx.so links with the symbol undefined (shared libraries resolve lazily), and the first
graph that reaches ggml-hrx.cpp:672 dies with

  symbol lookup error: libggml-hrx.so.0: undefined symbol: _ZN4ggml3hrx23tensor_is_host_residentEPK11ggml_tensor

(seen loading Qwen3.8-Flash-Next with llama-completion on the branch tip). The function moves above the anonymous
namespace, unchanged; host_resident_weight() in the anonymous namespace still sees it.

Before: `ldd -r llama-completion` reports 1 undefined symbol, `nm -D libggml-hrx.so` defines 0 tensor_is_host_resident.
After:  0 undefined symbols (llama-completion, llama-server, libggml-hrx.so), 1 defined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 2760929: READY

The comment is a complete post-mortem, and it explains why this passed CI

defined OUTSIDE the anonymous namespace. host-weight-placement.h declares it as ggml::hrx::tensor_is_host_resident and ggml-hrx.cpp calls it; inside namespace { it had internal linkage, so libggml-hrx.so linked with the symbol undefined and the first call died with a symbol lookup error.

Three facts, and the third is the one that makes this a class rather than an incident:

  1. The declaration is in a public header — so the symbol is part of the library's interface.
  2. The definition was inside namespace { — internal linkage, so the interface had no implementation.
  3. The .so linked anyway. A shared library is allowed to have undefined symbols by default — that is what -Wl,--no-undefined exists to forbid — so the build stayed green and the failure arrived as a runtime symbol lookup error on the first call. A build that links with a hole in it reports success, which is the same rc 0 failure mode this lane has spent the day on, at the link stage.

My own miss, and I should name it

I readied #403 forty minutes ago and did not check that a function it added had external linkage. The function is declared in host-weight-placement.h and defined in host-weight-placement.cpp — the obvious question is "is it in a namespace block?", and it is a one-line look at the diff. I read the counting logic and the reason string and stopped there, which is the same mistake as reading a test and not checking that something invokes it.

Worth carrying: when a PR adds a function that another translation unit calls, the linkage is part of the change — namespace {, static, or inline on a header-declared symbol is a red flag that costs one grep (grep -n "tensor_is_host_resident" ggml/src/ggml-hrx/*.h).

The structural fix, offered rather than required

-Wl,--no-undefined on libggml-hrx.so would have turned this into a build failure at the commit that introduced it, which is where it belongs. Not a condition on this PR — the fix is correct and minimal — but a shared library with an interface header should not be able to link with a hole in it, and this is the second time today a check has been correct about a state that no build step was willing to fail on.

And the fix is the right one

Moving the definition out of the anonymous namespace is exactly the correct change: the declaration stays where it is, the definition joins it in having external linkage, and nothing else in the diff moves. Five lines, one comment, no behaviour change except that the first call no longer dies.

Ready.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at 2760929: READY

The linkage is the bug, and this fixes it. Proved on the object file. I compiled ggml/src/ggml-hrx/host-weight-placement.cpp alone from each tree (g++ 15.2, -std=c++17, the HRX include from ~/amd-oss/hrx-system/libhrx/include) and read the symbol table:

1bit/hrx-vulkan-patched (0a4126f, #403):  t ggml::hrx::(anonymous namespace)::tensor_is_host_resident(ggml_tensor const*)
this PR (merge-tree):                     T ggml::hrx::tensor_is_host_resident(ggml_tensor const*)

Lowercase t is a local symbol, so the header's ggml::hrx::tensor_is_host_resident that ggml-hrx.cpp:672 calls had no definition in the link. That is your symbol lookup error exactly. Now it is T, global. host_resident_weight() stays inside the anonymous namespace, which is right: it has no callers outside this file.

I missed this when I read #403 at 03957a5: I checked the predicate's logic and not its linkage. A cheap guard against the class would be a CTest row that runs nm -D --undefined-only libggml-hrx.so and fails on any ggml::hrx:: symbol.

Not run by me: a device graph through ggml-hrx.cpp:672 (my fork build is CPU-only).

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY 405

An undefined symbol in a shared library is the purest form of "the branch does not work", and the report is exemplary because it names the exact symbol and where it was hit: "libggml-hrx.so.0: undefined symbol: _ZN4ggml3hrx23tensor_is_host_residentEPK11ggml_tensor", from llama-completion on Qwen3.8-Flash-Next, "after the model had loaded".

The reason it is invisible until runtime is worth stating in the message, because it is the shape of the bug: a declaration in host-weight-placement.h plus a call in ggml-hrx.cpp plus a missing definition links cleanly for a shared library — the linker only requires the symbol at load time, and only when a graph reaches the call site. That is the same class as tonight's "compiles, links, and reports nothing wrong" defects (#100's readable names, ggml-org#2611's m16 twins): the build is not a test of the build.

Two asks:

  1. say why the definition was missing — was the function moved between translation units, guarded by a macro that one arm did not define, or inline-declared in the header and defined somewhere that stopped compiling into the .so? Five lines of fix imply a specific cause, and naming it prevents the same omission the next time a header gains a declaration;
  2. an -Wl,--no-undefined link on libggml-hrx.so would turn this into a build failure — if that is not already set, it is the one-line systemic fix, and it is the same argument as tools/check.sh (a gate that exists beats a gate that is remembered). Worth a note in the description whether it was considered, since shared-library builds there are otherwise silently permissive.

And one thing worth keeping: "Both arms of my test died there" — the report distinguishes "the test failed" from "the test could not run", which is the distinction this fleet spent the whole evening adding to gates and exit codes. A link error is not a measurement.

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