Skip to content

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Oct 23, 2025

  • enable -sWASM_BIGINT=1
  • enable -mbulk-memory
  • detect max memory size
  • don't touch cgroup files on wasm
  • don't call memcpy on zero size buffers

Fixes #119639
Fixes #119997
Related #120298 (comment)

@pavelsavara pavelsavara added this to the 11.0.0 milestone Oct 23, 2025
@pavelsavara pavelsavara self-assigned this Oct 23, 2025
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm labels Oct 23, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

- detect max memory size
- use bulk memory
- fix zero size calls to memcpy
@radekdoulik
Copy link
Member

There is also an option to fix the underlying bug in our emscripten fork for our current version. That would take some effort, depends on how much we need this now. @pavelsavara does enabling bigint improve the linking times on your system?

@pavelsavara
Copy link
Member Author

pavelsavara commented Oct 24, 2025

There is also an option to fix the underlying bug in our emscripten fork for our current version.

The fix is in emscripten-core/emscripten#22873, we could do partial backport into our fork.

But I much prefer full upgrade.
See #119409 and #120222

does enabling bigint improve the linking times on your system?

Yes it does make a large difference.

it can be turned off separately, but only by fiddling with minimum browser options, which has more far-reaching effects (e. g. it implies JS transpilation).

Yes

https://github.com/emscripten-core/emscripten/blob/cf90417346b78455089e64eb909d71d091ecc055/tools/link.py#L1383-L1384

-sMIN_CHROME_VERSION=74 does the trick in our version of emscripten.

We would loose NON_TRAPPING_FPTOINT and PROMISE_ANY why is that a big deal @SingleAccretion ?

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Oct 24, 2025

We would loose NON_TRAPPING_FPTOINT and PROMISE_ANY why is that a big deal

It is not a big deal. What I was worried about is this https://github.com/emscripten-core/emscripten/blob/8ac7ef7de5b9dc555d83db0f17bbc22346914dba/tools/link.py#L1284-L1299. Looks like it can be turned off via -sPOLYFILL=0. So that (-sWASM_BIGINT=1 -sPOLYFILL=0 -sMIN_CHROME_VERSION=74) seems like a good way forward.

@pavelsavara pavelsavara marked this pull request as ready for review October 24, 2025 15:27
@Copilot Copilot AI review requested due to automatic review settings October 24, 2025 15:27
@pavelsavara pavelsavara requested a review from kg as a code owner October 24, 2025 15:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables WebAssembly BigInt support and bulk memory operations for the CoreCLR browser runtime. The changes improve WASM compatibility and prevent runtime errors when working with zero-size memory operations.

Key changes:

  • Enable -sWASM_BIGINT=1 and -mbulk-memory compiler flags across browser-related build configurations
  • Add guards to prevent memcpy calls with zero-size buffers, which can cause issues in WASM
  • Skip cgroup file system operations on WASM platform and implement WASM-specific memory size detection

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tests/CMakeLists.txt Adds -mbulk-memory flag to test build configuration
src/native/corehost/browserhost/CMakeLists.txt Enables bulk memory and BigInt flags for browser host
src/coreclr/vm/methodtablebuilder.cpp Guards ZeroMemory call when field count is zero
src/coreclr/pal/src/misc/cgroup.cpp Prevents cgroup operations on WASM and guards cgroup path finding
src/coreclr/pal/CMakeLists.txt Adds -mbulk-memory flag to PAL build
src/coreclr/interpreter/compiler.cpp Guards multiple memcpy calls against zero-size operations
src/coreclr/hosts/corerun/CMakeLists.txt Enables bulk memory and BigInt flags for corerun host
src/coreclr/gc/unix/gcenv.unix.cpp Implements WASM-specific memory size detection using emscripten_get_heap_max()
src/coreclr/gc/unix/cgroup.cpp Prevents cgroup operations on WASM and guards cgroup path finding

@kg
Copy link
Member

kg commented Oct 24, 2025

Note that recent emscripten has bulk memory as default AFAIK, so if we ever update emscripten this will happen anyway. I think it's still worthwhile to explicitly turn bulk memory on now though even if it will become the default later.

@radekdoulik
Copy link
Member

Note that recent emscripten has bulk memory as default AFAIK, so if we ever update emscripten this will happen anyway. I think it's still worthwhile to explicitly turn bulk memory on now though even if it will become the default later.

Yes, and with it we also closer to current mono, which has bulk memory enabled too.

@radekdoulik
Copy link
Member

There is also an option to fix the underlying bug in our emscripten fork for our current version.

The fix is in emscripten-core/emscripten#22873, we could do partial backport into our fork.

But I much prefer full upgrade. See #119409 and #120222

Sure, we want to do that anyway.

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

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm][coreCLR] fix ASAN/ASSERTIONS issues [wasm coreclr] fix bigint

6 participants