Skip to content

[wasm64] Add browser-wasm64 CoreCLR interpreter support - #138166

Open
lewing wants to merge 15 commits into
mainfrom
feature/wasm64-interpreter
Open

lewing wants to merge 15 commits into
mainfrom
feature/wasm64-interpreter

Conversation

@lewing

@lewing lewing commented Nov 23, 2026

Copy link
Copy Markdown
Member

Adds browser-wasm64 (memory64) support to the CoreCLR interpreter. This is layer 1 of a stack: ReadyToRun (JIT/crossgen2) and library outerloop CI follow in separate PRs.

  • Build plumbing for -os browser -arch wasm64. The cross components build only the jitinterface; there is no wasm64 JIT in this layer.
  • VM/PAL/GC interpreter runtime changes, plus generated wasm64 call-helper tables under src/coreclr/vm/wasm/browser-wasm64/.
  • Browser host, JS interop, and Webcil for memory64, including the Emscripten __sig declarations for pointer-taking imports.
  • SDK/workload targeting for browser-wasm64. ReadyToRun is disabled and rejected for wasm64 until the R2R layer.
  • A wasm64 interpreter runtime-test lane, with R2R passes off, and its test exclusions.

Validated locally (macOS arm64):

  • ./build.sh clr+libs+host -os browser -arch wasm64 -c Debug -lc Release passed.
  • ./build.sh clr+libs -os browser -c Debug -lc Release passed (wasm32 regression check).
  • The call-helper generator reproduces the checked-in wasm64 and wasm32 tables with no diff.
  • A smoke app (collections, EH, GC) ran on the wasm64 corerun.js under node 26 and exited 100.

Note

This PR description was generated with GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 8 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing
lewing force-pushed the feature/wasm64-interpreter branch from c562509 to dd5154f Compare November 23, 2026 23:20
@lewing lewing added arch-wasm WebAssembly architecture area-CodeGen-Interpreter-coreclr os-browser Browser variant of arch-wasm and removed area-Build-mono labels Nov 23, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.

@lewing

lewing commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

This is the parts of #138027 required to stand up the browser-wasm64 interpreter.

Excluding the newly generated call helpers the diff is +1,311 / −647 lines

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks pretty good.

Comment thread src/coreclr/vm/codeman.cpp Resolved
Comment thread src/coreclr/vm/dynamicmethod.cpp Resolved
@lewing
lewing force-pushed the feature/wasm64-interpreter branch from dd5154f to 8370fed Compare November 24, 2026 01:06
Comment thread eng/native/build-commons.sh Resolved
Comment thread eng/build.sh Outdated
arch=wasm
# Keep the existing wasm default unless wasm64 was explicitly requested.
if [[ "$arch" != "wasm64" ]]; then
arch=wasm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps simpler to only replace the host-arch default rather than override -arch, so wasm64 (and later wasi-wasm64) goes through like any other arch and we don't need to revisit this:

diff --git a/eng/build.sh b/eng/build.sh
index c1b89e78d7e..54c3e1308ad 100755
--- a/eng/build.sh
+++ b/eng/build.sh
@@ -542,20 +542,16 @@ if [ ${#actInt[@]} -eq 0 ]; then
     arguments=("-restore" "-build" ${arguments[@]+"${arguments[@]}"})
 fi

+if [[ -z "$passedArch" && ( "$os" == "browser" || "$os" == "wasi" ) ]]; then
+    # the host arch default doesn't apply to WebAssembly targets
+    arch=wasm
+fi
 if [[ "$os" == "browser" ]]; then
-    # Keep the existing wasm default unless wasm64 was explicitly requested.
-    if [[ "$arch" != "wasm64" ]]; then
-        arch=wasm
-    fi
     # because on docker instance without swap file, MSBuild nodes need to make some room for LLVM
     # https://github.com/dotnet/runtime/issues/113724
     # this is hexa percentage: 46-> 70%
     export DOTNET_GCHeapHardLimitPercent="46"
 fi
-if [[ "$os" == "wasi" ]]; then
-    # override default arch for wasi, we only support wasm
-    arch=wasm
-fi

 # Default dynamiccodecompiled based on target OS if not explicitly set
 if [[ -z "$dynamiccodecompiled" ]]; then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, applied in 1054af9. One tweak: build.sh runs with set -u and passedArch is only set when -arch is given, so the check uses "${passedArch:-}". Otherwise ./build.sh -os browser fails with "unbound variable". build.ps1 still forces wasm for browser/wasi; I left it alone since its -arch validation doesn't allow wasm64 yet, and Windows wasm64 isn't in scope here.

Note

This reply was drafted with GitHub Copilot.

Base automatically changed from feature/wasm-arch-rename to main November 27, 2026 22:45
lewing added a commit that referenced this pull request Nov 27, 2026
This PR makes the WebAssembly predicate names consistent ahead of wasm64
support. It's split out of #138166 at @jkotas's request.

- Bare names mean 32-bit WebAssembly, matching the
`browser-wasm`/`wasi-wasm` RIDs: `TARGET_WASM`/`HOST_WASM`,
`CLR_CMAKE_*_ARCH_WASM` and MSBuild `TargetsWasm`.
- New names on the ARMARCH pattern mean any WebAssembly width:
`TARGET_WASMARCH`/`HOST_WASMARCH`, `CLR_CMAKE_*_ARCH_WASMARCH` and
`TargetsWasmArch`.
- `TARGET_WASM32` is replaced by `TARGET_WASM`.

Only 32-bit WebAssembly exists on main, so this is a mechanical rename
of the existing any-width uses and behavior is unchanged. Mono's own
sources keep their existing defines.

Validated locally with `./build.sh clr+libs+host -os browser -c Debug
-lc Release`.

> [!NOTE]
> This PR description was generated with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing and others added 10 commits November 27, 2026 16:45
Recognize the wasm64 architecture in the build scripts, CMake configuration and subsets. The wasm64 cross components build only the jitinterface needed by crossgen2; there is no wasm64 JIT yet.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
VM, PAL, GC and CoreLib changes for 64-bit pointers on browser-wasm64, plus corerun host updates.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Teach the call-helper generator and its crossgen2 calling-convention and instruction-set support about wasm64, and check in the generated tables. The tables are produced by generate-coreclr-helpers.proj.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Includes the Emscripten __sig declarations for pointer-taking browser imports.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add the browser-wasm64 RID and packs. ReadyToRun is disabled and rejected for wasm64 until R2R support lands.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add the CI lane with ReadyToRun passes disabled, wasm64 test infrastructure, and test exclusions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
memory64 lifts the 4 GB address limit; use the engine's memory64 cap rather
than the wasm32 2 GB default so large-allocation workloads can run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 081c20e)
Architecture has no Wasm64 value, so browser-wasm64 reports Architecture.Wasm.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 0d8a717)
…ated source

The ExecutionManager.md usage table is generated from data-descriptor-meanings.json,
so record the wasm-optional field description there.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
crossgen2 rejects wasm64 until ReadyToRun support is added, so tests with
AlwaysUseCrossGen2 can't run on the wasm64 interpreter lane yet.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lewing
lewing force-pushed the feature/wasm64-interpreter branch from 4ead760 to c6f6b12 Compare November 27, 2026 22:45
Replace the browser and wasi -arch overrides with a single default that applies
only when no architecture was requested, so wasm64 goes through like any other
architecture.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread src/coreclr/clrdefinitions.cmake Resolved
Comment thread src/coreclr/build-runtime.sh Resolved
@Edenlia Edenlia mentioned this pull request Nov 28, 2026
<DefineConstants Condition="'$(WasmEnableThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
<DefineConstants Condition="'$(WasmEnableJsInteropByValue)' == 'true'">$(DefineConstants);ENABLE_JS_INTEROP_BY_VALUE</DefineConstants>
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
<DefineConstants Condition="'$(TargetsWasm64)' == 'true'">$(DefineConstants);TARGET_WASM64</DefineConstants>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Libraries are not setup to be architecture specific. I think this will lead to e.g. both 32-bit and 64-bit binary overwriting each other if you build both from the same enlistment.

It would be better to refactor JSMarshalerArgumentImpl so that it does not have hardcoded architecture specific offsets.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. JSMarshalerArgumentImpl now uses a sequential layout with a nested explicit union and pointer-sized fields, so the offsets fall out of the pointer size. The TARGET_WASM64 define is gone and the assembly is identical for wasm and wasm64. I checked that the runtime layouts match marshal.ts exactly (32 and 56 bytes), and wasm32 ReadyToRun codegen is unchanged apart from relocations.

Note

This reply was drafted with GitHub Copilot.

lewing and others added 4 commits November 30, 2026 09:41
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…tyle

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
gen-buildsys.sh already passes CLR_CMAKE_TARGET_ARCH=wasm64 for browser builds.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use a sequential layout with a nested explicit union and pointer-sized fields
instead of architecture-specific field offsets, so one System.Runtime.InteropServices.JavaScript
assembly matches both the wasm (32-byte) and wasm64 (56-byte) layouts, and drop
the TARGET_WASM64 define.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Labels

arch-wasm WebAssembly architecture area-CodeGen-Interpreter-coreclr os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants