Skip to content

Enable Emscripten with MEMORY64#5

Open
vulkan101 wants to merge 212 commits intomhfrom
wasm64_addressSpaceLimitationFix
Open

Enable Emscripten with MEMORY64#5
vulkan101 wants to merge 212 commits intomhfrom
wasm64_addressSpaceLimitationFix

Conversation

@vulkan101
Copy link
Owner

@vulkan101 vulkan101 commented Nov 10, 2025

These changes allow us to use the MEMORY64 flag in emscripten in combination with the dotnet runtime, opening up the available address space to web applications.
Changes affect areas including marshalling and interpreted call handling. In particular, icalls need to specify whether pointer parameters are 4 or 8 byte. On x86/64 this is not required because both sizes are written to the same register. All permutations of 4 and 8 byte pointer parameters are now handled by the icall system in a new file interp-icalls.c, split out from interp.c. This is probably not an ideal solution long term, but is functional.

The Jiterpreter is hardcoded out in this branch, and no changes have been made to the jiterpreter code to support wasm64. Stub functions are provided to enable this branch to work. Similarly we use invariant globalization and remove the standard libicu, utilising stub methods instead.

We have a separate demo sample to show the address space limitation being overcome here: https://github.com/[vulkan101/Wasm64Demo](https://github.com/vulkan101/Wasm64Demo. This is a stripped down blazor application which simply allocates memory in chunks until it fails.

  • to test this we manually copy runtime dlls into a portable SDK install

Test projects in the runtime which have been run successfully include:

  • System.Runtime.InteropServices.Tests.csproj
  • System.Memory.Tests.csproj
  • System.Runtime.Tests.csproj
  • System.Runtime.InteropServices.JavaScript.Tests.csproj

To date, we have not run any of the low level wasm tests which require linux compilation.

The use of wasm64 is hardcoded in several places, and other changes include modification to allow the use of a local emscripten install, which must be 4.0.5 at present.

We got around an issue with runtime startup by modifying dotnet.es6.lib.js and using the USE_CLOSURE_COMPILER flag, but as discussed at the time this is not ideal, and PRs such as this dotnet#119409 take a better approach.

This PR targets the point at which the branch was taken from main to show the changes more clearly.

vulkan101 and others added 30 commits April 4, 2025 16:32
Add flags to try to get mono cross to build wasm64 - this time --target=wasm64 is not recognised.
…this (conditional, check which of these wasm64's can be removed)
…iterpreter stub function, set DISABLE_JITERPRETER for browser builds of BuildMonoCross
…o I've got a record of the change, will revert)
…itting so I've got a record of the change, will revert)"

This reverts commit 3583d31.
This reverts commit d032b31.
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