Fix critical correctness bugs in SASS rewriter and interceptor#1
Open
Zorg33 wants to merge 1 commit into
Open
Conversation
Resolves multiple correctness issues that made the rewriter either
a no-op or produce corrupt output for non-trivial cubins:
- Fix ELF header parsing: e_phnum/e_shnum were read from offset 48/50
(inside e_flags) instead of 56/60, causing zero sections to be processed
- Fix multi-kernel ELF splice: remove cum_growth double-counting that
corrupted binaries with 2+ .text sections
- Fix predicated FFMA split: preserve original predicate on FMUL to
avoid clobbering r_dest when predicate is false
- Fix opcode matching: use startswith('FFMA') to avoid matching DFMA/HFMA2
- Use verified_jump_tables to filter .nv.constant patching, preventing
corruption of float/integer literals
- Track per-kernel max register for REGCOUNT instead of global max
- Update program headers (p_filesz/p_memsz/p_offset) after .text expansion
- Fix get_elf_size to walk section data extents instead of header+8192 guess
- Use declared g_mutex in patch_and_load for actual thread safety
- Add write() return value check, file-open guards, R255 filtering,
symtab bounds checks, SHT_DYNSYM support
Incorporates and extends c500a4c (Fix elf processing) with additional
correctness fixes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
e_phnum/e_shnumwere read from offset 48/50 (insidee_flagsfield) instead of the correct 56/60, causing the rewriter to process zero sections and produce unmodified outputcum_growthdouble-counted offsets already shifted by the inner loop, corrupting binaries with 2+.textsections0xFF), clobberingr_destwhen the predicate is false andtemp_reg == r_dest"FMA" in opincorrectly matchedDFMA(double) andHFMA2(half), splitting them with float FMUL/FADD opcodesverified_jump_tableswas computed via BRX/LDC tracing but never consulted —.nv.constant*values matching PCs were blindly patched, risking corruption of float/integer literalsmax_regset every kernel's register count to the max across all kernels, reducing occupancyp_filesz/p_memsz/p_offsetwere not updated after.textexpansionget_elf_size: computed size from header positions + 8192 padding instead of walking section data extentsg_mutexwas never locked inpatch_and_loadwrite()return check, file-open guards in tests, R255 filtering, symtab bounds checks, SHT_DYNSYM support, unused deps removedBuilds on c500a4c (Fix elf processing) with additional correctness fixes.
Test plan
./build.shon sm_70 hardware./run_test.sh— all 4 suites (basic, comprehensive, stress, runtime JIT) should pass[Rewriter] Patch Completeoutput showsSections: Nwhere N > 0🤖 Generated with Claude Code