Final review report · NVIDIA/hyperflare-inference #652

Raw Markdown for agents: https://autobot.eidonix.com/p/b85014bc-0408-4099-8cd8-eb41abe2f16f.md

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

Walkthrough

Pre-merge Checks

Blockers

  1. Mercury (.nv.merc.* / 0x70000085) sections and unrecognized non-zero sh_info silently 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) at cubin.rs:145, and tests/preparation/test_cubin.py:14,35 explicitly models .nv.merc.symtab (kind = 0x70000085, flags = 0x10000000, sh_link = .strtab). However, try_prune_unused_kernels's layout gate (cubin.rs:412-432) only checks SHT_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.symtab verbatim (cubin.rs:790-792) and remapping its sh_link (cubin.rs:841-848). Every entry in .nv.merc.symtab is left with stale pre-compaction st_shndx (pointing to wrong sections or past e_shnum) and stale st_name offsets into the compacted .strtab. Similarly, cubin.rs:849-856 copies s.info raw for any surviving section not matched by sh_info_is_section (cubin.rs:261-280), leaving stale section indices on any unrecognized companion section that omits SHF_INFO_LINK.
    • Fix: In the layout gate (cubin.rs:412-432), bail to Ok(None) (passthrough) if any section has s.kind == 0x7000_0085 (or Mercury section kinds 0x7000_0080..=0x7000_00ff / SHF_CUDA_MERCURY 0x1000_0000 / name prefix .nv.merc). In the section-header emitter (cubin.rs:849-856), if s.info != 0 on a surviving section that is neither SHT_SYMTAB, .text.*, nor recognized by sh_info_is_section, return Ok(None) instead of passing s.info through raw. Add unit tests covering both cases.
  2. .nv.callgraph prototype and indirect-call subsections (0xfffffffe / 0xfffffffd) leave dangling .strtab offsets and mis-filter entries (heliopause/src/export/cubin.rs:330-347, :522-537, :674-722).

    • Verified behavior & impact: NVIDIA's .nv.callgraph groups 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 where b is a byte offset into .strtab, not a symbol index. Currently: (a) .strtab compaction (cubin.rs:674-722) retains only strings referenced by surviving .symtab st_name, deleting prototype strings and shifting offsets, leaving dangling/out-of-bounds .strtab offsets in .nv.callgraph; (b) filter_callgraph (cubin.rs:340) checks dead_syms.contains(&(b as usize)), treating a .strtab byte 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.callgraph parsing (cubin.rs:522-537) and filter_callgraph (cubin.rs:330-347), bail to Ok(None) (passthrough) whenever a non-direct-call sentinel appears (any (a, b) with a == 0 && b != 0xffff_ffff or b >= 0xffff_fff0 && !(a == 0 && b == 0xffff_ffff)), or explicitly parse the subsections and preserve/remap referenced .strtab prototype strings. Add a unit test covering (0, 0xffff_fffe) / (0, 0xffff_fffd) passthrough.

Should Fix

  1. Unsafe break on unrecognized/malformed .nv.info.<fn> records in EIATTR_EXTERNS walk (heliopause/src/export/cubin.rs:577-587).

    • While filter_global_nvinfo (cubin.rs:301-315) returns None (safe passthrough) on unknown fmt or out-of-bounds rec_len, the per-function .nv.info.<fn> reachability loop (cubin.rs:580-587) uses break. Truncating the walk early can miss a subsequent EIATTR_EXTERNS (0x0f) record and drop a live callee.
    • Fix: Extract a single EIATTR record-framing parser/iterator shared by filter_global_nvinfo and the EIATTR_EXTERNS walk, and return Ok(None) on any unknown fmt or truncated record.
  2. rx_alloc SHT_NOBITS handling and PT_LOAD segment alignment (heliopause/src/export/cubin.rs:779-783, :801-832, :883).

    • If any section in rx_alloc has s.kind == SHT_NOBITS, place (cubin.rs:779-783) does not advance out.len(), so rx_end - rx_start (cubin.rs:806, :887) omits its size from p_memsz and allows subsequent sections to overlap its sh_offset.
    • rx_start (cubin.rs:801) and rw_start (cubin.rs:813) are only padded to 8 bytes and every PT_LOAD hardcodes p_align = 8 (cubin.rs:883), even when sections inside the segment require higher alignment (e.g., .text.* sh_align = 128 at cubin.rs:1164, or aligned .nv.global SHT_NOBITS). As a result, (sh_offset - p_offset) % sh_align is not guaranteed to be zero, and an SHT_NOBITS-only rw_alloc section with sh_align > 8 gets its sh_offset pushed into the section-header table range (cubin.rs:825-826).
    • Fix: Return Ok(None) if any rx_alloc section is SHT_NOBITS. Pad rx_start and rw_start to the max sh_align of their respective sections (at least 8) and emit that alignment in p_align (or preserve input p_align).
  3. 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 tests heliopause (.github/workflows/native-serving.yml (not opened), python-cpu.yml).
    • Fix: (a) Run at least one SM120 or SM121 export + flare run on a multi-kernel CUTLASS/FlashInfer workload before merge and attach the pruned/skipped module breakdown; (b) wire cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib into CI; and (c) strengthen the post-prune validation at cubin.rs:365 beyond header-only Elf::parse to verify all surviving sh_link, sh_info, st_shndx, st_name, and PT_LOAD bounds.

Subtract / Simplify

  1. Deduplicate is_debug_section and reuse SHT_*/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 added is_debug_section helper (cubin.rs:254-259). Call is_debug_section(name) in strip_debug to delete the duplicate policy, and replace raw section-type/flag literals (2, 3, 8, & 2) in the same file with the constants just added at cubin.rs:14-23.
  2. Delete align_up in favor of usize::next_multiple_of (heliopause/src/export/cubin.rs:282-289).
    • heliopause/Cargo.toml:6 pins rust-version = "1.88", and the crate already uses next_multiple_of (heliopause/src/export/archive.rs:209, heliopause/src/export/io.rs:252 (not opened), :647). Replace align_up(value, align) with value.next_multiple_of(align.max(1)) at its three call sites (cubin.rs:292, :780, :825).
  3. Deduplicate the triplicated .text.* callee check and split try_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, and EIATTR_EXTERNS arms (dropping the redundant !keep_text.contains(&shx) checks at :564 and :596 since keep_text.insert(shx) deduplicates at :607), and split the 530-line body along its existing comment boundaries (layout gate, reachability, emit).

Nits

Dropped on verification