JIT: Superpmi wasm32 neardiff#128967
Conversation
Teach the SuperPMI near-differ how to route wasm32 collections through the coredistools framing-aware code paths, and add a wasm-specific offset comparator that consults the JIT-recorded relocation table. Changes: * NearDiffer::InitAsmDiff: map `wasm` / `wasm32` target architecture to Target_Wasm32. Existing NearDiffCodeBlocks / DumpCodeBlock / DumpDiffBlocks auto-route to the framed implementations in coredistools when configured for Target_Wasm32, so no plumbing through new entry points is needed. * NearDiffer::compareOffsets: dispatch to new compareOffsetsWasm when SpmiTargetArchitecture is WASM32 instead of replaying the generic IP-relative heuristics, which do not apply to wasm. * NearDiffer::compareOffsetsWasm: look up recorded relocations in cr1 and cr2 at the immediate-payload byte (a small window starting one byte past the opcode) and accept iff both sides have a reloc with matching kind and equal target (after addlDelta correction). Asymmetric relocs, different kinds, and different targets are treated as real diffs in v1. * CompileResult::findRelocationInRange: linear-scan helper that maps a buffer-relative offset window back to a recorded Agnostic_RecordRelocation entry. Used by compareOffsetsWasm. * CompileResult::applyRelocs: skip patching for wasm32. The JIT emits PADDED_RELOC_SIZE bytes of `80 80 80 80 00` (a ULEB/SLEB that decodes to zero) at every reloc site. Both baseline and diff JITs emit identical placeholder bytes there, so byte-by-byte comparison already succeeds at reloc sites without any patching; compareOffsetsWasm handles the case where bytes actually do differ. Requires coredistools >= 1.7.0 for the Target_Wasm32 enum value. The eng/Versions.props bump to MicrosoftNETCoreCoreDisToolsVersion=1.7.0 is left to a follow-up once the dotnet/jitutils PR dotnet#437 lands and a real 1.7.0 nupkg publishes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Picks up the wasm32 disassembly + framed near-differ entry points added in dotnet/jitutils PR dotnet#437. Changes: * eng/Versions.props: MicrosoftNETCoreCoreDisToolsVersion 1.6.0 -> 1.7.0 to match the published nupkg containing the framed Wasm code-buffer support. * src/coreclr/inc/coredistools.h: re-sync from dotnet/jitutils/src/coredistools/coredistools.h: - Adds Target_Wasm32 to the TargetArch enum (must match the value used inside coredistools.dll). - Declares the framed entry points NearDiffCodeBlocksFramed, DumpCodeBlockFramed, DumpDiffBlocksFramed for callers that want to invoke them directly. The non-framed entry points (NearDiffCodeBlocks, DumpCodeBlock, DumpDiffBlocks) automatically delegate to the framed implementations when the differ is configured for Target_Wasm32, so the existing SuperPMI neardiffer wiring (added in the parent commit) needs no changes beyond passing Target_Wasm32 at init time. Together with the parent commit `SuperPMI: wasm32 near-differ support'', this enables `superpmi.py asmdiffs -target_os browser -target_arch wasm'' to produce textual asm diffs against wasm32 collections. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
@dotnet/wasm-contrib PTAL This is the last piece of SPMI support. Validated locally by modifying the JIT to insert NOPs in some random places, and got reasonable looking diff reports. The reloc comparison may need some fine-tuning; we'll have to see how well it holds up over time. Note the collection and asmdiff currently pass The 381 missing methods are largely unsupported runtime async. |
There was a problem hiding this comment.
Pull request overview
This PR updates SuperPMI’s asm near-diffing pipeline to understand wasm32 code streams by (1) bumping CoreDisTools to a version that supports wasm disassembly/framing and (2) adding wasm-specific offset/relocation handling in SuperPMI’s NearDiffer / CompileResult glue.
Changes:
- Update CoreDisTools package version to
1.7.0and extend the localcoredistools.hinterface withTarget_Wasm32plus framed entrypoints. - Teach SuperPMI
NearDifferto configure CoreDisTools for wasm32 (Target_Wasm32) and route offset equivalence checks through a wasm-specific comparator. - Add a
CompileResulthelper to locate relocations by location range, and skipapplyRelocsfor wasm32.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/superpmi/superpmi/neardiffer.h | Adds a wasm-specific offset comparator declaration. |
| src/coreclr/tools/superpmi/superpmi/neardiffer.cpp | Maps wasm/wasm32 to CoreDisTools Target_Wasm32 and implements compareOffsetsWasm. |
| src/coreclr/tools/superpmi/superpmi-shared/compileresult.h | Declares findRelocationInRange for wasm near-diff relocation lookup. |
| src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp | Skips applyRelocs for wasm32 and implements relocation range lookup. |
| src/coreclr/inc/coredistools.h | Adds Target_Wasm32 and framed near-diff/disasm API surface. |
| eng/Versions.props | Updates MicrosoftNETCoreCoreDisToolsVersion to 1.7.0. |
|
|
||
| const DiffData* data = (const DiffData*)payload; | ||
|
|
||
| // Payload byte for an un-prefixed wasm opcode is opcode-byte + 1. For prefixed |
There was a problem hiding this comment.
For some un-prefixed memory instructions, we do have a reloc type we can emit which is a reloc of the internal offset immediate for loads/stores, so we'd have <memop> <align>:u32 <relocated-offset>:u32 where the relocated piece would be at opcode-byte + 2 in practice. Can we update the comment here to reflect this?
There was a problem hiding this comment.
fixed the comment to indicate it will scan for relocs at any location after the opcode byte
- compileresult.cpp findRelocationInRange: guard against size_t wraparound on rangeLo + windowSize, and short-circuit when windowSize == 0 so the helper's half-open range contract is self-contained (Copilot review). - neardiffer.cpp compareOffsetsWasm: clarify the docstring and inline comment to note that the recorded reloc payload sits at opcode-byte + 1 for un-prefixed i32.const/call/etc., but at opcode-byte + 2 for un-prefixed memory ops (i32.load/i32.store/...) after the align u32. The existing immediate-window scan covers both cases unchanged; this is a comment-only update (adamperlin review). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update coredistools version to 1.7.0 to pick up Wasm disassembly support.
Implement neardiff support for Wasm.