Skip to content

Coredistools wasm32#437

Open
AndyAyersMS wants to merge 2 commits into
mainfrom
coredistools-wasm32
Open

Coredistools wasm32#437
AndyAyersMS wants to merge 2 commits into
mainfrom
coredistools-wasm32

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS commented May 29, 2026

Add Wasm32 support to coredistools.

AndyAyersMS and others added 2 commits May 28, 2026 19:18
Adds wasm32 as a supported target architecture for the coredistools
disassembler. This is the first step toward enabling SuperPMI asm-diffs
for collections produced by the LLVM/Wasm RyuJIT backend, which today
fall through to a host-arch decode and silently degrade to roughly
bitwise comparison of framed Wasm blobs.

Changes:
- coredistools.h: add Target_Wasm32 to TargetArch enum.
- coredistools.cpp: handle Target_Wasm32/Triple::wasm32 in setTarget()
  host-detect and explicit-target switches; set a starter Wasm feature
  string in init() covering the proposals the LLVM/Wasm JIT may emit
  (simd128, sign-ext, nontrapping-fptoint, mutable-globals,
  reference-types, bulk-memory, tail-call, exception-handling,
  multivalue). Keep this in sync with the JIT's emitted feature set on
  each LLVM bump.
- build-coredistools.{cmd,sh} and build-tblgen.{cmd,sh}: append
  WebAssembly to the default LLVMTargetsToBuild. Per-arch restricted
  matrix legs (linux-arm, linux-loongarch64, linux-riscv64, win-x86)
  are left unchanged - wasm32 diffing is not a use case for those
  hosts.

Follow-ups (not in this change):
- Frame-aware iteration: walking the per-funclet ULEB128 length prefix
  and the per-body locals declaration before disassembling.
- Wasm-aware OffsetComparator on the SuperPMI side, driven by the
  recorded relocation table.
- .wat-style dump output on diff.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The LLVM/Wasm RyuJIT backend writes its code buffer as a sequence of
length-prefixed function/funclet bodies (ULEB128 body-length followed
by the body bytes, where each body begins with the standard Wasm
locals declaration). This shape doesn't fit the existing "flat
instruction stream" assumption baked into nearDiff/dumpBlock, so
Target_Wasm32 collections currently flow through asm-diffs as opaque
bytes (or worse, get fed to the host-arch decoder).

Add a Wasm-aware path that understands the framing:
 - Internal ULEB128 reader (readULEB128) plus parseWasmLocals/
   formatWasmLocals helpers for the per-body header.
 - CorDisasm::dumpWasmFramedBlock walks each body, prints the locals
   header in (local i32 i32 ...) form, then disassembles the opcode
   stream using the existing LLVM WebAssembly MCInstPrinter (-> .wat-
   ish output).
 - CorAsmDiff::nearDiffWasmFramed walks both buffers in lockstep body
   by body, requires matching locals headers, and falls back to the
   OffsetComparator on differing integer immediates. The comparator
   is passed the opcode-byte offset measured from the start of the
   framed buffer so SuperPMI's recorded reloc tables can be looked up
   directly.
 - dumpDiffWasmFramed prints both sides with baseline/diff labels.

New entry points NearDiffCodeBlocksFramed, DumpCodeBlockFramed and
DumpDiffBlocksFramed are exported for callers that want to be
explicit; the existing NearDiffCodeBlocks / DumpCodeBlock /
DumpDiffBlocks entry points auto-route to the framed path when the
configured target is Target_Wasm32 (the framing is intrinsic to the
target, so this is safe).

Bump nuspec version to 1.7.0 to reflect the added API surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS AndyAyersMS marked this pull request as ready for review May 30, 2026 01:38
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/wasm-contrib PTAL
fyi @dotnet/jit-contrib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant