Repository navigation
debug: fix LLVM 23 silently dropping device debug info for kernel-local statics - #1216
Merged
Merged
Conversation
…al statics Since the nightly bump to LLVM 23 (#1201), any module with a kernel-local static (shared tile, Barrier) lost all device debug info under CUDA_OXIDE_DEBUG=full: the exporter (#1129) lists such a static, whose scope is the kernel's DISubprogram, in the compile unit's `globals:` tuple. LLVM 21/22 require that form; LLVM 23's verifier rejects it ("function-local variables are not allowed in a DICompileUnit's global variables list"), strips every debug node, and llc exits 0. The pipeline never read llc's stderr, so PTX with no .file/.loc/DWARF shipped and cuda-gdb could only bind source breakpoints to host shadow lines. llvm-export: add `FunctionLocalStaticPlacement`; under `SubprogramRetainedNodes` (LLVM 23+) function-local static expressions are spliced into the owning DISubprogram's `retainedNodes:` at finalize time. Module-level globals always stay in the compile unit. cuda-oxide-codegen: resolve the LLVM toolchain before export (`discover_llvm_toolchain`) and derive the placement from `llc_major`; libNVVM output keeps the compile-unit form. Treat "ignoring invalid debug info" on llc/opt stderr as a hard error whenever debug info was requested. shared_debug: build with --device-debug in smoketest; verify-debug-info.sh accepts both placements and validates with LLVM tools of the matching major. Tests: both placements, module globals staying in the CU, an llvm-as boundary test over every reachable LLVM major, fake llc/opt fail-closed tests, and the existing llvm-as gates now read stderr (exit status is 0 even when the graph is stripped). Validated on an RTX 5090 with cuda-gdb 13.3: `b main.rs:174` in the debugger assessment example stops in the kernel under llc 23 and llc 22; debug-smoketest.sh (compiler_features, shared_debug) passes; compile-only smoketest 222/222.
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.
Problem
Since the nightly bump to LLVM 23 (#1201), every module that contains a kernel-local
static(a shared-memory tile, aBarrier, ...) loses all device debug info underCUDA_OXIDE_DEBUG=full: no.file, no.loc, no DWARF sections, and the PTX.targetloses itsdebugmodifier. cuda-gdb then binds a source breakpoint only to the host shadow of the line and never stops in the kernel. Reported by Dmitry (cuda-devtools) against his debugger assessment example;vecaddwas unaffected because it has no kernel-local static.The exporter (#1129) describes a kernel-local static as a
DIGlobalVariablescoped to the kernel'sDISubprogramand lists itsDIGlobalVariableExpressionin the compile unit'sglobals:tuple. LLVM 21 and 22 require that form. LLVM 23's verifier rejects it:and, rather than failing, strips every debug node in the module.
llcstill exits 0, and the pipeline never read its stderr, so the stripped PTX shipped.Each version rejects the other form (LLVM 21/22:
invalid retained nodes, expected DILocalVariable, DILabel or DIImportedEntity), so no single form works for both the CI floor (llc-22) and the pinned toolchain (LLVM 23).Fix
FunctionLocalStaticPlacementconfig option (CompileUnitGlobals|SubprogramRetainedNodes,for_llvm_major(23) => SubprogramRetainedNodes). Under the retained-nodes placement the exporter splices function-local static expressions into the owningDISubprogram'sretainedNodes:tuple at finalize time; module-level globals always stay in the compile unit.discover_llvm_toolchainsplit out ofgenerate_ptx) and derives the placement fromllc_major; libNVVM output keeps the compile-unit form.llcandoptstderr is now checked:ignoring invalid debug infounder a debug build is a hardPipelineErrorinstead of a silently stripped artifact.--device-debug;verify-debug-info.shaccepts both placements and validates with LLVM tools whose major matches (previously it drove a PATHllvm-asregardless of version).Before / after (
debuginfoexample,b main.rs:174, RTX 5090, cuda-gdb 13.3).target.file.section .debug_*sm_120amain.rs:216only,No CUDA kernelssm_120a, debugCUDA thread hit Breakpoint 1, debuginfo_scalars<<<...>>> at src/main.rs:174CUDA_OXIDE_LLC= llc 22sm_120a, debugCross-check: main's IR through llc 22 is fine, and main's tree through llc 23 with only the IR form swapped is fine, so the placement is the whole cause. The retained-nodes form nests TILE as a
DW_TAG_variablechild of its kernel withDW_AT_address_class 8in the ptxas cubin.Tests
llvm-export: both placements for a function-local AS3 static, module-level globals staying in the compile unit, and anllvm-asboundary test that exports both forms through every reachablellvm-as(LLVM 22 and 23 locally,llvm-as-22on CI) and asserts the selected form verifies while the other is rejected with the known message. The three pre-existingllvm-asparse gates now read stderr: exit status alone is 0 even when the graph is stripped.cuda-oxide-codegen:for_llvm_majormapping; fakellc/optthat print the warning and exit 0 must fail full-debug and line-tables builds and pass debug-off builds.cargo test --workspace, clippy-D warnings, fmt, and all nine status-guard scripts pass;debug,shared_debug,device_globalrun with--device-debugand their verify scripts pass under both llc 22 and llc 23;scripts/debug-smoketest.sh(cuda-gdb consumption of the DWARF, incl. the closure/enum/projection passes) passes.Follow-ups
Forcing
CUDA_OXIDE_DEBUG=fullon all 222 examples (not a CI configuration) fails 77 of them on unpatched main and on this branch alike: a dozenverify-code-shape.shgates that assert on optimized output, the rest importer/lowering gaps that only appear at-Zmir-opt-level=0. None involve debug metadata (the fail-closed check never fires there). Worth its own issue.libNVVM output keeps the compile-unit form and has no fail-closed check; when libNVVM moves to LLVM 23 the same break would recur on that path.
The nightly-bump runbook should include "build a full-debug example that owns a kernel-local static and grep llc stderr for
invalid debug info".