internal/nvsandboxutils: Look up entry points with dlsym - #2087
Open
rautyrauty wants to merge 2 commits into
Open
rautyrauty wants to merge 2 commits into
rautyrauty wants to merge 2 commits into
Conversation
rautyrauty
requested review from
cdesiniotis,
henry118 and
tariq1890
as code owners
September 13, 2026 18:42
rajatchopra
requested changes
Sep 21, 2026
rajatchopra
left a comment
Contributor
There was a problem hiding this comment.
Useful PR.
Can we have a mock_nvsandbox.so and build a unit test case around the five calls?
This is necessary so that binaries linking these bindings carry no unresolved dynamic symbols: distributions that check packages for them reject such binaries on platforms where the library is not packaged at all, and a call made before Init() succeeds is then terminated by the dynamic linker instead of returning an error. The wrappers resolve against RTLD_DEFAULT, which reaches the library only because it is opened with RTLD_GLOBAL; narrowing those load flags would leave every entry point unresolvable. Signed-off-by: Ajrat Makhmutov <rauty@altlinux.org>
…k library The dynamicLibrary mock stops at the Go boundary and cannot cover the dlsym wrappers, so this builds a real shared object at test time and loads it through the normal path. Calling an entry point before the library is loaded is checked too: that is the case that used to jump to a NULL address. Signed-off-by: Ajrat Makhmutov <rauty@altlinux.org>
rautyrauty
force-pushed
the
fix-nvsandboxutils-unresolved-symbols
branch
from
September 22, 2026 13:21
31ab95f to
2e75bad
Compare
Contributor
Author
|
Added in a follow-up commit: testdata/mock_nvsandbox.c is compiled and dlopen'ed by the test, so all five entry points go through the real dlsym path - on main it fails with undefined symbol: nvSandboxUtilsShutdown. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The generated bindings reference the
libnvidia-sandboxutilsentry points at link time and link with-Wl,--unresolved-symbols=ignore-in-object-files, so every binary using them keeps five unresolved dynamic symbols, boundlazily against the library
lib.godlopens withRTLD_GLOBAL.Two consequences:
pkg/nvcdi) on ALT Linux i586 and aarch64, where nothingprovides
libnvidia-sandboxutils.so.1:Init()terminates the process with a dynamic linker symbol lookup error instead of returning a code.The entry points are now resolved with
dlsym(RTLD_DEFAULT)— the same global scope the dynamic linker searched, so a loaded library is found exactly as before, and an absent one yieldsNVSANDBOXUTILS_ERROR_LIBRARY_LOAD.The wrappers are a plain
.c/.hpair pulled into the preamble viaIncludesin the c-for-go configuration, so regenerating the bindings keeps them; the generated files change only as that configuration dictates.nvml*symbols from
go-nvmlare untouched — the same treatment there would span several hundred generated functions and is better done separately.Checklist
make test)make lint)Testing
make testpasses;golangci-lint run ./internal/nvsandboxutils/...reports 0 issues.nm -D --undefined-only nvidia-ctk | grep nvSandboxUtils: 5 symbols before, 0 after.libnvidia-sandboxutils.so.1:Init,GetDriverVersionandShutdownreturn the stub's values; with no library presentInitreturnsERROR_LIBRARY_LOADinstead of crashing.lxdpackage with these bindings vendored: the repository-wide ELF symbols check, which previously reported five newnvSandboxUtils*symbols, now passes on x86_64, i586 and aarch64, and the resultingi586 binary has no unresolved
nvSandboxUtils*left.