Repository navigation
hrx: tensor_is_host_resident has external linkage again (#403 left libggml-hrx.so with an undefined symbol) - #405
Conversation
…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
left a comment
There was a problem hiding this comment.
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.hdeclares it asggml::hrx::tensor_is_host_residentandggml-hrx.cppcalls it; insidenamespace {it had internal linkage, solibggml-hrx.solinked 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:
- The declaration is in a public header — so the symbol is part of the library's interface.
- The definition was inside
namespace {— internal linkage, so the interface had no implementation. - The
.solinked anyway. A shared library is allowed to have undefined symbols by default — that is what-Wl,--no-undefinedexists 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 samerc 0failure 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
left a comment
There was a problem hiding this comment.
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).
|
VERDICT: READY 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: " The reason it is invisible until runtime is worth stating in the message, because it is the shape of the bug: a declaration in Two asks:
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. |
1bit/hrx-vulkan-patchedat 0a4126f (#403) builds alibggml-hrx.sowith an undefined symbol. The first graph that reachesggml-hrx.cpp:672aborts:(Hit loading Qwen3.8-Flash-Next with
llama-completionon the branch tip. Both arms of my test died there, after the model had loaded.)Cause
host-weight-placement.hdeclaresggml::hrx::tensor_is_host_resident, andggml-hrx.cppcalls it, buthost-weight-placement.cppdefines it insidenamespace {. 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)
nm -D --defined-only libggml-hrx.so | grep -c tensor_is_host_residentldd -r llama-completionundefined symbolsldd -r llama-server/libggml-hrx.soundefined symbolsEngine 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
--pleport) 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