Skip to content

debug: fix LLVM 23 silently dropping device debug info for kernel-local statics - #1216

Merged
nihalpasham merged 1 commit into
mainfrom
fix/llvm23-function-local-static-debuginfo
Sep 2, 2026
Merged

nihalpasham merged 1 commit into
mainfrom
fix/llvm23-function-local-static-debuginfo

Conversation

@nihalpasham

@nihalpasham nihalpasham commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Since the nightly bump to LLVM 23 (#1201), every module that contains a kernel-local static (a shared-memory tile, a Barrier, ...) loses all device debug info under CUDA_OXIDE_DEBUG=full: no .file, no .loc, no DWARF sections, and the PTX .target loses its debug modifier. 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; vecadd was unaffected because it has no kernel-local static.

The exporter (#1129) describes a kernel-local static as a DIGlobalVariable scoped to the kernel's DISubprogram and lists its DIGlobalVariableExpression in the compile unit's globals: tuple. LLVM 21 and 22 require that form. LLVM 23's verifier rejects it:

function-local variables are not allowed in a DICompileUnit's global variables list
warning: ignoring invalid debug info in debuginfo.ll

and, rather than failing, strips every debug node in the module. llc still exits 0, and the pipeline never read its stderr, so the stripped PTX shipped.

LLVM 21 / 22 (required)                 LLVM 23+ (required)

!DICompileUnit(..., globals: !{!E})     !DISubprogram(..., retainedNodes: !{!E})
  !E = !DIGlobalVariableExpression        !E = !DIGlobalVariableExpression
       (var: !V ...)                           (var: !V ...)
  !V = !DIGlobalVariable(scope: !SP)      !V = !DIGlobalVariable(scope: !SP)

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

  • llvm-export: new FunctionLocalStaticPlacement config option (CompileUnitGlobals | SubprogramRetainedNodes, for_llvm_major(23) => SubprogramRetainedNodes). Under the retained-nodes placement the exporter splices function-local static expressions into the owning DISubprogram's retainedNodes: tuple at finalize time; module-level globals always stay in the compile unit.
  • cuda-oxide-codegen: the PTX path resolves the LLVM toolchain before export (discover_llvm_toolchain split out of generate_ptx) and derives the placement from llc_major; libNVVM output keeps the compile-unit form. llc and opt stderr is now checked: ignoring invalid debug info under a debug build is a hard PipelineError instead of a silently stripped artifact.
  • shared_debug: smoketest builds it with --device-debug; verify-debug-info.sh accepts both placements and validates with LLVM tools whose major matches (previously it drove a PATH llvm-as regardless of version).

Before / after (debuginfo example, b main.rs:174, RTX 5090, cuda-gdb 13.3)

build PTX .target .file .section .debug_* cuda-gdb
main @ 97f8b2b, llc 23 sm_120a 0 0 stops on host main.rs:216 only, No CUDA kernels
this PR, llc 23 sm_120a, debug 13 3 CUDA thread hit Breakpoint 1, debuginfo_scalars<<<...>>> at src/main.rs:174
this PR, CUDA_OXIDE_LLC = llc 22 sm_120a, debug 13 5 same device hit

Cross-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_variable child of its kernel with DW_AT_address_class 8 in the ptxas cubin.

Tests

  • llvm-export: both placements for a function-local AS3 static, module-level globals staying in the compile unit, and an llvm-as boundary test that exports both forms through every reachable llvm-as (LLVM 22 and 23 locally, llvm-as-22 on CI) and asserts the selected form verifies while the other is rejected with the known message. The three pre-existing llvm-as parse gates now read stderr: exit status alone is 0 even when the graph is stripped.
  • cuda-oxide-codegen: for_llvm_major mapping; fake llc/opt that print the warning and exit 0 must fail full-debug and line-tables builds and pass debug-off builds.
  • Existing suites: cargo test --workspace, clippy -D warnings, fmt, and all nine status-guard scripts pass; debug, shared_debug, device_global run with --device-debug and 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=full on all 222 examples (not a CI configuration) fails 77 of them on unpatched main and on this branch alike: a dozen verify-code-shape.sh gates 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".

…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.
@nihalpasham nihalpasham added bug Something isn't working debug info Debug information in generated PTX/IR (line/source maps) codegen Device code-generation pipeline (Rust MIR to IR to PTX) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) labels Sep 2, 2026
@nihalpasham
nihalpasham merged commit 073b5bd into main Sep 2, 2026
52 checks passed
@nihalpasham
nihalpasham deleted the fix/llvm23-function-local-static-debuginfo branch September 5, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) debug info Debug information in generated PTX/IR (line/source maps) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant