Recommendation: Changes Requested
This PR solves a real, well-scoped memory and load-time problem in the right layer (export-only, zero Helios runtime/wire/CLI changes), and the core design—preserving .symtab indices while compacting dead .text.* sections and companion metadata, and re-enumerating globals from &exported—is sound. However, direct verification of heliopause/src/export/cubin.rs at 9ea2491 uncovered two concrete ELF64/CUDA binary-corruption paths on valid cubins (.nv.merc.*/Mercury symbol tables and unrecognized non-zero sh_info, plus .nv.callgraph indirect-call/prototype subsections), an unsafe break in the EIATTR_EXTERNS walk, and zero CI or SM103/SM120/SM121 verification for an unconditional export-path binary rewriter. All technical blockers can be closed cleanly with small fail-safe passthrough guards and targeted unit tests, plus at least one SM120/SM121 export+serve validation pass.
Merge Risk
Level: Medium
- Blast radius: Unconditional binary ELF64 rewriting on every exported module (
heliopause/src/export/capture.rs:3288). Previously exported cores and the Helios runtime reader (helios/src/runtime_core/mod.rs:785-850) are untouched, and multi-rank export captures per-rank cubin resources independently (heliopause/src/export/core.rs:2013-2061). - Failure visibility:
strip_and_pruneonly self-checks its output with header/bounds-onlyElf::parse(&pruned)?(heliopause/src/export/cubin.rs:365,:69-107), so semantic ELF corruption passes export silently and surfaces only at serving time oncuModuleLoadData(helios/src/runtime_core/mod.rs:795-798). - Hardware & CI gap: No CI workflow runs
cargo testonheliopause, and all live validation was performed on SM87 while the charter's target architectures (SM103/SM120/SM121—where CUDA 12.8+/13.x Mercury sections and large CUTLASS/FlashInfer cubins live) were not exercised.
Walkthrough
heliopause/src/export/cubin.rs:254-370: Addsstrip_and_prune(wrappingstrip_debug, returning early for empty keep sets, and falling back to debug-stripped bytes onOk(None)) along with helpers for debug-section matching,sh_infosection-index classification, alignment padding, and filtering dead-symbol records out of global.nv.info(0x11/0x12/0x2f) and.nv.callgraph.heliopause/src/export/cubin.rs:372-904: Addstry_prune_unused_kernels, which gates on standardEM_CUDAzero-vaddr ELF64 layouts, computes transitive.text.*reachability from captured symbols plus non-debug relocations,.nv.callgraph, and per-function.nv.info.<fn>EIATTR_EXTERNS(0x0f), cascades drops across companionsh_infosections, rebuilds.shstrtab/.strtab/.symtab(zeroing dead slots in place to preserve symbol indices), and re-emits sections, section headers, andPT_PHDR/PT_LOADprogram headers.heliopause/src/export/cubin.rs:1032-1282: Adds two isolated in-memory unit tests covering dead-kernel pruning,.nv.callgraphandEIATTR_EXTERNScallee retention, non-SHF_INFO_LINK.nv.constant0.<fn>sh_inforemapping, global symbol survival, and standalone/no-PT_PHDRpassthrough.heliopause/src/export/capture.rs:3282-3315: Builds each module'skeep_functionsset fromoutput.index.ranks[0].functions, replacescubin::strip_debugwithcubin::strip_and_prune, and enumerates module globals viacubin::global_symbols(&exported)so pruned dead-kernel constant symbols are not queried or recorded.
Pre-merge Checks
- [PASS] Security / malicious screen: Export-only local ELF transformation; no external I/O, auth/signing changes, or suspicious patterns found.
- [PASS] Charter & value fit: Solves a real measured memory/load-time issue in the export layer with zero Helios runtime, wire-format, or per-model changes; priority contributor
@lukealonso. - [PASS] Related / duplicate / conflict check: No conflicting changes on
main; standalonekv_codecmodules pass through via the empty-keep_functionsbranch (capture.rs:3282-3288,cubin.rs:360-362). - [WARN] Tests & verification evidence: Unit tests are isolated and clean, but no CI workflow runs
heliopausetests (tests/preparation/test_cubin.pyonly exercisesstrip_debug/global_symbols), and live export+serve validation was run only on SM87 rather than the charter's SM103/SM120/SM121 matrix (docs/design-review.mdPrinciples 4 & 12).
Blockers
-
Mercury (
.nv.merc.*/0x70000085) sections and unrecognized non-zerosh_infosilently corrupt pruned cubins (heliopause/src/export/cubin.rs:145,:412-432,:674-734,:790-792,:849-856).- Verified behavior & impact: The file already recognizes CUDA Mercury symbol tables (
s.kind == 0x70000085) atcubin.rs:145, andtests/preparation/test_cubin.py:14,35explicitly models.nv.merc.symtab(kind = 0x70000085,flags = 0x10000000,sh_link = .strtab). However,try_prune_unused_kernels's layout gate (cubin.rs:412-432) only checksSHT_SYMTAB(2). When a cubin contains.nv.merc.symtab(standard on Blackwell SM100/SM103/SM120/SM121 toolchains), pruning compacts.strtab(cubin.rs:674-734) and renumbers sections (cubin.rs:652-659), while copying.nv.merc.symtabverbatim (cubin.rs:790-792) and remapping itssh_link(cubin.rs:841-848). Every entry in.nv.merc.symtabis left with stale pre-compactionst_shndx(pointing to wrong sections or paste_shnum) and stalest_nameoffsets into the compacted.strtab. Similarly,cubin.rs:849-856copiess.inforaw for any surviving section not matched bysh_info_is_section(cubin.rs:261-280), leaving stale section indices on any unrecognized companion section that omitsSHF_INFO_LINK. - Fix: In the layout gate (
cubin.rs:412-432), bail toOk(None)(passthrough) if any section hass.kind == 0x7000_0085(or Mercury section kinds0x7000_0080..=0x7000_00ff/SHF_CUDA_MERCURY0x1000_0000/ name prefix.nv.merc). In the section-header emitter (cubin.rs:849-856), ifs.info != 0on a surviving section that is neitherSHT_SYMTAB,.text.*, nor recognized bysh_info_is_section, returnOk(None)instead of passings.infothrough raw. Add unit tests covering both cases.
- Verified behavior & impact: The file already recognizes CUDA Mercury symbol tables (
-
.nv.callgraphprototype and indirect-call subsections (0xfffffffe/0xfffffffd) leave dangling.strtaboffsets and mis-filter entries (heliopause/src/export/cubin.rs:330-347,:522-537,:674-722).- Verified behavior & impact: NVIDIA's
.nv.callgraphgroups 8-byte(a, b)records into subsections headed by(0, marker)sentinels:(0, 0xffff_ffff)introduces(caller_sym, callee_sym)pairs, whereas(0, 0xffff_fffe)(CG_PROTO) and(0, 0xffff_fffd)(CG_ICALL) introduce(sym_idx, strtab_offset)pairs wherebis a byte offset into.strtab, not a symbol index. Currently: (a).strtabcompaction (cubin.rs:674-722) retains only strings referenced by surviving.symtabst_name, deleting prototype strings and shifting offsets, leaving dangling/out-of-bounds.strtaboffsets in.nv.callgraph; (b)filter_callgraph(cubin.rs:340) checksdead_syms.contains(&(b as usize)), treating a.strtabbyte offset as a symbol index and dropping live prototype/indirect-call entries whenever the offset numerically collides with a dead symbol index; and (c) reachability (cubin.rs:532) does not follow indirect-call prototype matches. - Fix: In
.nv.callgraphparsing (cubin.rs:522-537) andfilter_callgraph(cubin.rs:330-347), bail toOk(None)(passthrough) whenever a non-direct-call sentinel appears (any(a, b)witha == 0 && b != 0xffff_fffforb >= 0xffff_fff0 && !(a == 0 && b == 0xffff_ffff)), or explicitly parse the subsections and preserve/remap referenced.strtabprototype strings. Add a unit test covering(0, 0xffff_fffe)/(0, 0xffff_fffd)passthrough.
- Verified behavior & impact: NVIDIA's
Should Fix
-
Unsafe
breakon unrecognized/malformed.nv.info.<fn>records inEIATTR_EXTERNSwalk (heliopause/src/export/cubin.rs:577-587).- While
filter_global_nvinfo(cubin.rs:301-315) returnsNone(safe passthrough) on unknownfmtor out-of-boundsrec_len, the per-function.nv.info.<fn>reachability loop (cubin.rs:580-587) usesbreak. Truncating the walk early can miss a subsequentEIATTR_EXTERNS(0x0f) record and drop a live callee. - Fix: Extract a single EIATTR record-framing parser/iterator shared by
filter_global_nvinfoand theEIATTR_EXTERNSwalk, and returnOk(None)on any unknownfmtor truncated record.
- While
-
rx_allocSHT_NOBITShandling andPT_LOADsegment alignment (heliopause/src/export/cubin.rs:779-783,:801-832,:883).- If any section in
rx_allochass.kind == SHT_NOBITS,place(cubin.rs:779-783) does not advanceout.len(), sorx_end - rx_start(cubin.rs:806,:887) omits its size fromp_memszand allows subsequent sections to overlap itssh_offset. rx_start(cubin.rs:801) andrw_start(cubin.rs:813) are only padded to 8 bytes and everyPT_LOADhardcodesp_align = 8(cubin.rs:883), even when sections inside the segment require higher alignment (e.g.,.text.*sh_align = 128atcubin.rs:1164, or aligned.nv.globalSHT_NOBITS). As a result,(sh_offset - p_offset) % sh_alignis not guaranteed to be zero, and anSHT_NOBITS-onlyrw_allocsection withsh_align > 8gets itssh_offsetpushed into the section-header table range (cubin.rs:825-826).- Fix: Return
Ok(None)if anyrx_allocsection isSHT_NOBITS. Padrx_startandrw_startto the maxsh_alignof their respective sections (at least 8) and emit that alignment inp_align(or preserve inputp_align).
- If any section in
-
Charter-target validation, post-prune cross-reference self-check, and CI wiring (
heliopause/src/export/cubin.rs:365,.github/workflows/).- All live validation was run on SM87; SM103/SM120/SM121 were not exercised (
docs/design-review.md:62,:106-115), and no CI workflow compiles or testsheliopause(.github/workflows/native-serving.yml(not opened),python-cpu.yml). - Fix: (a) Run at least one SM120 or SM121 export +
flare runon a multi-kernel CUTLASS/FlashInfer workload before merge and attach the pruned/skipped module breakdown; (b) wirecargo test --locked --release --manifest-path heliopause/Cargo.toml --libinto CI; and (c) strengthen the post-prune validation atcubin.rs:365beyond header-onlyElf::parseto verify all survivingsh_link,sh_info,st_shndx,st_name, andPT_LOADbounds.
- All live validation was run on SM87; SM103/SM120/SM121 were not exercised (
Subtract / Simplify
- Deduplicate
is_debug_sectionand reuseSHT_*/SHF_*constants (heliopause/src/export/cubin.rs:189-193,:254-259,:113,:126,:145,:200,:208,:224).strip_debug(cubin.rs:189-193) retains an exact 5-line inline copy of the newly addedis_debug_sectionhelper (cubin.rs:254-259). Callis_debug_section(name)instrip_debugto delete the duplicate policy, and replace raw section-type/flag literals (2,3,8,& 2) in the same file with the constants just added atcubin.rs:14-23.
- Delete
align_upin favor ofusize::next_multiple_of(heliopause/src/export/cubin.rs:282-289).heliopause/Cargo.toml:6pinsrust-version = "1.88", and the crate already usesnext_multiple_of(heliopause/src/export/archive.rs:209,heliopause/src/export/io.rs:252(not opened),:647). Replacealign_up(value, align)withvalue.next_multiple_of(align.max(1))at its three call sites (cubin.rs:292,:780,:825).
- Deduplicate the triplicated
.text.*callee check and splittry_prune_unused_kernels(heliopause/src/export/cubin.rs:372-904,:513-516,:560-567,:592-599).- Extract a small
callee_text_section(syms, sec_names, sym_idx) -> Option<usize>helper used across the relocation,.nv.callgraph, andEIATTR_EXTERNSarms (dropping the redundant!keep_text.contains(&shx)checks at:564and:596sincekeep_text.insert(shx)deduplicates at:607), and split the 530-line body along its existing comment boundaries (layout gate, reachability, emit).
- Extract a small
Nits
- Update design docs to match the new symbol-pruning behavior:
docs/core-format-design.md:380-381currently states "The exporter preserves kernel and global symbol names in cubins" anddocs/runtime-core-design.md:76lists only "cubin debug stripping". Update both to reflect that unreferenced kernel symbols/sections may be pruned while referenced kernels and surviving globals are preserved. - Export progress observability (
heliopause/src/export/capture.rs:3384-3387): Optionally include pruned vs passthrough module counts inmodule_phase.finishso operators can see pruning effectiveness per export without external tooling. - Conservative over-retention from dead-kernel relocations (
heliopause/src/export/cubin.rs:493-519): Non-debug relocation tables targeting dead.text.*or.nv.constant*.<dead>sections are scanned unconditionally before reachability, conservatively retaining any.text.*targets referenced only by dead kernels. Safe as-is, but scoping relocation scanning to live/module-wide target sections would reclaim more kernels when dead kernels carry relocations.
Dropped on verification
- Upstream claim that
text_by_fn.len() <= keep_functions.len()(cubin.rs:434-436) and unmatchedtext_by_fn.get(fn_name)(cubin.rs:451-457) are "Major silent all-or-nothing passthrough bugs": Dropped. Whentext_by_fn.len() <= keep_functions.len()(e.g., all single-kernel Triton/Inductor/custom modules), there are zero unreferenced.text.*sections to prune, so skipping ELF rebuild is a valid fast-path—not a bug—and naturally accounts for most of the 88 unpruned modules. Bailing to passthrough on an unmatched captured name is the correct fail-safe to avoid dropping a live kernel. - Upstream claim that
capture.rs:3293-3298relaxes the standalone-module globals check ("a module whose globals were pruned away can no longer trip the error"): Dropped as false. Thatelsebranch runs only whenkernels.iter().find(|k| k.module == name)isNone, which meanskeep_functions(derived 1-to-1 fromkernelsatcapture.rs:3059-3141) is guaranteed empty, sostrip_and_prunereturnsstrip_debug(&image)without pruning (cubin.rs:360-362). - Upstream claim that
capture.rs:3282-3287unnecessarily rescansoutput.index.ranks[0].functionsinstead of reusing local state: Dropped.kernelsdoes not store.symbol(onlywire::Functiondoes), andoutput.index.ranks[0].functionsis never mutated between line 3187 and line 3282; keeping a cloned copy before the move would add code and allocation for zero benefit. - Upstream claim to delete or downgrade
Elf::parse(&pruned)?(cubin.rs:365) todebug_assert!: Dropped. Header/table parsing takes microseconds on an in-memory buffer and acts as a release-mode guard before writing artifacts; it should be strengthened (see Should Fix #3), not removed. - Upstream claim about "absence of any post-rewrite assertion that every kept
.textsurvived the cascade": Dropped as mathematically impossible.sh_info_is_section(cubin.rs:262) unconditionally returnsfalseforname.starts_with(b".text."), so the cascade loop (cubin.rs:625-642) can never drop any.text.*section. - Upstream claim that export-time peak memory "roughly triples" (
cubin.rs:359-368): Dropped as exaggerated/low-signal. Modules are processed sequentially one at a time (capture.rs:3280),prunedis typically ~12% of the input image size,cleanis required for the passthrough fallback, and buffers are dropped at the end of each loop iteration.