Skip to content

fix(finalizer): accept CUDA cubin ELF format versions - #622

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
niklebedenko:upstreaming/cubin-elf-version-validation
Aug 1, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
niklebedenko:upstreaming/cubin-elf-version-validation

Conversation

@niklebedenko

@niklebedenko niklebedenko commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #621.

Summary

cuda-artifact-finalizer rejected genuine CUDA 12.8 nvJitLink output because
it required the CUDA ELF header's e_version to equal generic ELF
EV_CURRENT. CUDA uses this field as a nonzero cubin binary-format version;
the installed toolkit emits 0x80. This accepts nonzero CUDA format versions
while keeping the validator fail-closed for zero, truncation, malformed tables,
and invalid payload ranges.

What changed

Treat e_version as CUDA's format version

  • Changed the shared is_valid_cubin rule from e_version == 1 to
    e_version != 0.
  • Kept a missing or zero field invalid.
  • Avoided an allowlist of observed values. Accepting nonzero is
    forward-compatible with CUDA's use of this field for its cubin format
    version, while all surrounding CUDA ELF identity and structural checks still
    apply.

Preserve validation boundaries and cover real output

  • Retained the existing ELF64 class, little-endian encoding, executable type,
    EM_CUDA machine, header-size, extended-count, header-table, file-backed
    segment/section, payload-bound, and meaningful-content checks unchanged.
  • Added deterministic coverage showing generic version 1 and CUDA version
    0x80 are accepted while zero is rejected.
  • Retained the existing truncated-file, empty-shell, invalid segment-size, and
    table-bound coverage.
  • Renamed and ran the existing ignored full finalizer pipeline test to make its
    installed-toolkit acceptance responsibility explicit without hardcoding
    0x80 as an evergreen toolkit invariant.
  • Audited the consumers: nvJitLink finalization and cuda-host cache validation
    both continue to use this one shared validator.

Known separate limitations

  • This remains a structural CUDA ELF validator; it does not replace loading an
    artifact through the CUDA Driver.
  • This patch does not change cubin inventory checks, cache keys, provenance,
    finalizer routing, or multi-artifact behavior.
  • Earlier issue Cubin cache rejects valid CUDA-specific ELF versions #388 and PR fix(cuda-host): accept CUDA-specific cubin ELF versions #389 were closed because no real non-1 cubin was
    available and that patch targeted a validator removed from cuda-host.
    This branch targets the current shared finalizer validator and includes a
    reproducible CUDA 12.8 nvJitLink sample whose readelf -h output reports
    e_version = 0x80.
  • The captured binary is retained for attachment to the issue. NVIDIA
    cuobjdump accepts it and decodes the same header field as toolkit version
    12.8.
  • The validator accepts any nonzero toolkit-format version rather than keeping
    an allow-list of releases known when this code was written. CUDA Driver
    loading remains the compatibility authority; zero is retained as the
    structurally invalid sentinel.
  • The installed-toolkit test remains ignored by default because it requires
    discoverable libNVVM, nvJitLink, and libdevice.

Testing

  • Upstream-red at bead880c:
    cargo test -p cuda-artifact-finalizer validation::tests::accepts_nonzero_cuda_toolkit_versions_and_rejects_zero -- --exact --nocapture
    failed specifically when the otherwise-valid fixture's e_version changed
    from 1 to 0x80.
  • Upstream-red at bead880c:
    cargo test -p cuda-artifact-finalizer live_tests::live_pipeline_accepts_toolkit_cubins_and_emits_ptx_for_both_fma_policies -- --exact --ignored --nocapture
    failed when link_ltoir returned InvalidCubin.
  • Patch-green: both focused commands above passed.
  • The live output was generated with CUDA 12.8 (ptxas V12.8.93) for sm_86.
    The 1,648-byte cubin had SHA-256
    adc1bab82a3988bb8083a4d33251a3e7403b5644ff2a509f9d27f9a7b1920c98;
    readelf -h reported ELF64, little-endian, executable, NVIDIA CUDA
    architecture, and header Version: 0x80.
  • /usr/local/cuda/bin/cuobjdump -elf accepted the retained binary and
    reported 64bit elf: type=2, abi=7, sm=86, toolkit=128.
  • Exact tool inputs for the retained binary:
    • libnvJitLink.so.12.8.93 SHA-256
      0369e6867d44b800437de4e146d72c65afc6c75adf677a15c2ecd8e6a7ac135f;
    • libnvvm.so.4.0.0 SHA-256
      dfb07dc65ffb0f7a16bc82ee1f87d7f4634b908d30aa8103d1e28afb1fe6589e;
    • libdevice.10.bc SHA-256
      25498d6e3c64782833ff15a5f56665ff09e5d21177163148a1cf008c61733449.
  • cargo test -p cuda-artifact-finalizer --all-targets — 13 passed, 1 ignored.
  • cargo clippy -p cuda-artifact-finalizer --all-targets -- -D warnings —
    passed.
  • cargo fmt --all -- --check — passed.
  • git diff --check — passed.

Checklist

  • The branch is based on current upstream main, or its dependency is explicit.
  • The regression fails on upstream main and passes on this branch.
  • Relevant sibling paths and edge cases are covered or called out above.
  • Formatting, focused tests, and relevant broader checks pass.
  • Commits include DCO signoff and new files have required headers.

@nihalpasham nihalpasham added bug Something isn't working host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) build-related Build scripts, toolchain discovery, or compilation setup labels Aug 1, 2026
@niklebedenko
niklebedenko force-pushed the upstreaming/cubin-elf-version-validation branch from 0f15c47 to 348bd74 Compare August 1, 2026 11:24
@nihalpasham

Copy link
Copy Markdown
Collaborator

LGTM.

Follow-up from closing #388 / #389 : CUDA 11.x/12.x toolchains really do write the toolkit version into e_version (I independently confirmed 0x73 = 11.5 on a real pre-13 cubin on my machine, which NVIDIA's own cuobjdump accepts), while 13.x went back to 1 — which is why every cubin in our tree matched the old check. On 12.x hosts the validator was rejecting every valid nvJitLink cubin.

Verified locally:

  • 13 unit tests plus the live-toolkit test pass; nonzero accepted, zero still rejected, every other structural check unchanged.
  • The digest-first cache read means the 4 bytes of lost strictness have no practical corruption-detection cost.

Merging;

closes #621.

@nihalpasham

Copy link
Copy Markdown
Collaborator

So this is actually stricter than "accept any nonzero": version 1 is always accepted, and the CUDA 12 encodings (120 through 129) are only accepted when the CUDA ABI byte is 7.

That's technically the version allowlist #621 said to avoid. I'm fine with it here, because this range can't rot the way an open-ended list would: the CUDA 12 series ended at 12.9, and CUDA 13 went back to writing 1, so it's a closed set of historical values.

Re-checked everything against the new head:

  • all 13 unit tests plus the live-toolkit test pass, and
  • the new finalize_nvvm_ir example walks the full finalize-and-validate path against a real toolkit.

@nihalpasham
nihalpasham merged commit c78f741 into NVIDIA:main Aug 1, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Valid CUDA cubins are rejected when ELF e_version is not EV_CURRENT

2 participants