feat(cuda): bundle + auto-link the glibc≥2.38 isoc23 link shim - #18
Open
NicolasRouquette wants to merge 1 commit into
Open
feat(cuda): bundle + auto-link the glibc≥2.38 isoc23 link shim#18NicolasRouquette wants to merge 1 commit into
NicolasRouquette wants to merge 1 commit into
Conversation
NicolasRouquette
force-pushed
the
cuda-isoc23-shim
branch
from
July 20, 2026 15:07
5a08224 to
826604a
Compare
Member
|
Thanks, Nicolas — this looks good to me. Since |
NicolasRouquette
force-pushed
the
cuda-isoc23-shim
branch
from
July 23, 2026 19:21
826604a to
3975292
Compare
NicolasRouquette
added a commit
to NicolasRouquette/TorchLean
that referenced
this pull request
Jul 23, 2026
NicolasRouquette
force-pushed
the
cuda-isoc23-shim
branch
2 times, most recently
from
August 3, 2026 18:01
16e7aad to
eb3c8b4
Compare
On glibc ≥ 2.38, nvcc's host pass (under _GNU_SOURCE) references __isoc23_strto*,
which an older link-time glibc (as bundled by the Lean toolchain) does not export —
breaking the CUDA link with `undefined reference to __isoc23_strtoull` (e.g. from the
getenv/strtoull parsing in csrc/cuda/common/torchlean_cuda_deterministic_reductions_env.h).
Bundle a tiny object (csrc/cuda/common/torchlean_isoc23_shim.c) that DEFINES the four
referenced names (__isoc23_strto{ull,ll,ul,l}) as weak wrappers over the plain strto*,
and compile + link it automatically into the CUDA build via a Lake target added to the NN
library's moreLinkObjs. No user action or -K flag is needed.
The symbols are weak, so a link-time glibc that already exports the real __isoc23_strto*
takes precedence; the shim is inert on hosts whose objects never reference these names
(older glibc, non-CUDA builds — byte-for-byte unchanged, as the object is only linked
when -K cuda=true). A -Wl,--defsym alias does not work: lld resolves the target among
defined symbols, but the C23 redirect leaves nothing referencing the plain strtoull.
NicolasRouquette
force-pushed
the
cuda-isoc23-shim
branch
from
August 4, 2026 19:48
eb3c8b4 to
3f7855b
Compare
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.
On glibc ≥ 2.38 (Ubuntu 24.04, Fedora ≥ 38, Debian 13, recent EL9, …) the
strto*family is redirected to
__isoc23_strto*under_GNU_SOURCE, which nvcc's host passforces. nvcc-compiled host objects then reference
__isoc23_strtoull/etc.; when thefinal executable is linked against an older glibc than nvcc compiled with — the case
whenever the Lean toolchain bundles a pre-2.38 glibc — those symbols are undefined and
the CUDA link fails:
This bundles a tiny object (
csrc/cuda/common/torchlean_isoc23_shim.c) that definesthe four referenced names as weak wrappers over the plain
strto*(declareddirectly, so the file itself skips the C23 redirect), and compiles + links it
automatically into the CUDA build via a Lake target in the
NNlibrary'smoreLinkObjs— only when
-K cuda=true. No-Kflag or user-supplied object path is needed.The symbols are
weak, so a link-time glibc that already exports the real__isoc23_strto*takes precedence, and the shim is inert on hosts whose objects neverreference these names (older glibc; and non-CUDA builds, which stay byte-for-byte
unchanged since the object is only linked under
-K cuda=true). A-Wl,--defsym=__isoc23_strtoull=strtoullalias does not work: lld resolves thedefsym target among defined symbols, but the C23 redirect leaves nothing referencing
the plain
strtoull, so lld reportssymbol not found: strtoull— a real definition isrequired.
Verified: a
-K cuda=truebuild (no extra flags) links cleanly and runs the full CUDAtest suite on Ubuntu 24.04 (glibc 2.39); without the shim the same build fails at link
with the undefined
__isoc23_strtoull. This also unblocks #10 (its byte-cap parsesTORCHLEAN_CUDA_CACHE_CAP_BYTESwithstrtoull, hitting the same reference) onglibc ≥ 2.38.