Skip to content

[browser] upgrade wasm exceptions#129396

Draft
pavelsavara wants to merge 60 commits into
dotnet:mainfrom
pavelsavara:emsdk-upgrade-wasm_exceptions
Draft

[browser] upgrade wasm exceptions#129396
pavelsavara wants to merge 60 commits into
dotnet:mainfrom
pavelsavara:emsdk-upgrade-wasm_exceptions

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

On top of #129299

akoeplinger and others added 30 commits June 11, 2026 18:44
(cherry picked from commit ea0ec7c)
When passing a negative C int to LLVMConstInt, the value is implicitly
converted to unsigned long long via sign-extension. In LLVM 23,
LLVMConstInt now retains those upper bits when SignExtend is FALSE,
which broke constant folding of subsequent ZExt instructions (e.g.
'zext i32 -1 to i64' produced i64 -1 instead of i64 4294967295).

This manifested as wrong results for decimal arithmetic in mono+LLVM
AOT, e.g. the inlined Decimal..ctor(uint) with a constant argument
sign-extending to _lo64. Many CoreLib tests (System.Tests.DecimalTests,
System.Text.Tests.RuneTests, Vector128.NarrowWithSaturation*) were
failing as a result.

Mask the value to the destination width before passing to LLVMConstInt.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Updated comments to clarify that OSX HFS driver format does not support millisecond granularity.
LLVMConstInt(IntTy, N, FALSE) requires N to fit in IntTy's unsigned width
(i.e. no bits set beyond IntTy's bit count). Passing -1 (= 0xFF..FF as
unsigned long long) to a sub-64-bit type violates this. Under LLVM 23
the resulting constant is wrong, which in emit_div_check caused the
rhs == -1 comparison to constant-fold to false and the OverflowException
check for INT_MIN / -1 and INT_MIN % -1 to be eliminated by the
optimizer.

Use LLVMConstAllOnes() which is the LLVM C API's idiomatic way to
build an all-ones constant of any integer width, sidestepping the issue.

Also fix the same pattern in emit_entry_bb where il_state->il_offset
is initialized to -1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
for wasm-opt: --enable-reference-types --enable-multivalue
for runtime default build: new instructions -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0
for no-EH runtime:-fexceptions JS exceptions
- change jiterp to use new wasm exception instructions
pavelsavara and others added 19 commits June 14, 2026 15:24
(cherry picked from commit 7f3a839)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Emscripten before 3.1.74 didn't support distinct atime/mtime, so the
Browser path set both to the same value. The repo now uses Emscripten
5.0.6, so the workaround is no longer needed and was causing
SetLastAccessTime to clobber LastWriteTime (and vice versa).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 14, 2026
@pavelsavara pavelsavara self-assigned this Jun 14, 2026
Copilot AI review requested due to automatic review settings June 14, 2026 17:44
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm labels Jun 14, 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the Browser/WASM stack to use the final WebAssembly exception handling (exnref/try_table) path across build tooling, runtime feature detection, and the jiterpreter, aligned with the newer Emscripten toolchain and LLVM updates.

Changes:

  • Switch Browser/WASM runtime feature detection and jiterpreter codegen from legacy EH to final EH (exceptionsFinal, try_table), and update JS engines/scripts to pass --experimental-wasm-exnref.
  • Update wasm toolchain/build flags (Emscripten 5.0.6, wasm-opt feature flags, legacy exceptions disabled) and adjust build/test infrastructure accordingly.
  • Update Mono LLVM integration for newer LLVM (23.x) and refresh related version pins.

Reviewed changes

Copilot reviewed 44 out of 44 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/mono/wasm/build/WasmApp.Common.targets Adds wasm-opt flags required by newer wasm feature set (ref types/multivalue) during post-link optimization.
src/mono/sample/wasm/wasm.mk Adds --experimental-wasm-exnref when running samples under V8/Node.
src/mono/sample/wasm/console-v8/Wasm.Console.V8.Sample.csproj Passes --experimental-wasm-exnref to XHarness V8 engine args for the sample.
src/mono/sample/wasm/console-node/Wasm.Console.Node.Sample.csproj Passes --experimental-wasm-exnref to XHarness NodeJS engine args for the sample.
src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj Adjusts advanced sample build properties to fit the updated toolchain/runtime behavior.
src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/Sdk/WorkloadTesting.Core.targets Alters workload-testing provisioning behavior for dotnet-install script/feed handling.
src/mono/mono/mini/mini-llvm.c Updates Mono LLVM backend for LLVM 23 behavior and API changes; suppresses new deprecation warnings.
src/mono/mono/mini/mini-llvm-cpp.h Updates C++ shim function signatures to be context-aware for newer LLVM APIs.
src/mono/mono/mini/mini-llvm-cpp.cpp Implements context-aware constant creation and updates intrinsic declarations for newer LLVM APIs.
src/mono/mono/mini/CMakeLists.txt Disables legacy wasm exceptions for the wasm EH static library build.
src/mono/mono.proj Updates Windows Python tool path for the newer Emscripten workload version.
src/mono/CMakeLists.txt Bumps expected LLVM API version and adjusts the LLVM library lists accordingly.
src/mono/browser/runtime/types/internal.ts Renames loader/runtime helper fields to reflect final EH (exceptionsFinal, featureWasmFinalEh).
src/mono/browser/runtime/startup.ts Switches runtime EH feature assertion to final EH and adjusts keepalive behavior during startup.
src/mono/browser/runtime/scheduling.ts Tweaks timer scheduling bookkeeping (including keepalive pop on canceled timeouts).
src/mono/browser/runtime/loader/globals.ts Switches wasm-feature-detect import and wiring from exceptions to exceptionsFinal.
src/mono/browser/runtime/loader/exit.ts Skips node stream flushing when not running under Node.
src/mono/browser/runtime/jiterpreter-support.ts Updates import generation and adds helpers to support final EH tag index space and try_table emission.
src/mono/browser/runtime/jiterpreter-opcodes.ts Updates WASM opcode definitions to include final EH opcodes (try_table/throw_ref).
src/mono/browser/runtime/jiterpreter-jit-call.ts Switches jiterpreter EH wrapping from legacy try/catch to final EH try_table structure.
src/mono/browser/runtime/diagnostics/dotnet-gcdump.ts Balances keepalive when canceling a pending safeSetTimeout during gcdump collection.
src/mono/browser/runtime/CMakeLists.txt Uses an EH-library selector variable and updates wasm-opt post-build flags.
src/mono/browser/emscripten-version.txt Updates recorded Emscripten version to 5.0.6.
src/mono/browser/build/BrowserWasmApp.targets Updates exception-handling flags to disable legacy exceptions and updates V8 run script args.
src/mono/browser/browser.proj Passes new Emscripten flags and selects the appropriate EH static library variant via CMake.
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/GetSetTimes.cs Refines temporal-resolution conditions and assertions around sub-second timestamps.
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/GetSetTimes.cs Updates timestamp granularity gating and removes Browser active-issue skips.
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs Makes last-write-time validation apply on Browser as well.
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Base/BaseGetSetTimes.cs Reworks temporal-resolution feature flags (sec/ms/ns) used by file-system timestamp tests.
src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs Changes Browser/WASI timestamp setting behavior to set access/write independently rather than forcing both.
src/coreclr/hosts/corerun/CMakeLists.txt Splits browser vs node wasm link options (WASM_BIGINT, preload, NODERAWFS, exports trimming).
NuGet.config Adds a new package source (general-testing).
global.json Bumps Arcade/Helix/SharedFramework/IL SDK versions.
eng/Versions.props Updates EmsdkVersion to 5.0.6.
eng/Version.Details.xml Updates dependency versions/shas (notably LLVM toolsets and dotnet-dotnet toolset deps).
eng/Version.Details.props Updates toolset and LLVM package version properties to match Version.Details.xml.
eng/testing/WasmRunnerTemplate.sh Adds --experimental-wasm-exnref to default engine args for wasm test runs.
eng/testing/WasmRunnerTemplate.cmd Adds --experimental-wasm-exnref to default engine args for wasm test runs (Windows).
eng/testing/wasm-provisioning.targets Switches Linux Firefox download archive format to .tar.xz.
eng/testing/BrowserVersions.props Updates Firefox/GeckoDriver revisions (moves to ESR and newer driver).
eng/native/tryrun.browser.cmake Updates tryrun cache’s recorded Emscripten version to 5.0.6.
eng/native/configureplatform.cmake Disables legacy wasm exceptions for browser builds and adjusts wasm link options.
eng/native.wasm.targets Expands exported runtime methods list (HEAP* accessors, etc.) for Browser builds.
docs/workflow/building/coreclr/wasm.md Updates debugging/run instructions to include --experimental-wasm-exnref.

Comment on lines 295 to 299
await mono_wasm_after_user_runtime_initialized();
endMeasure(mark, MeasuredBlock.onRuntimeInitialized);
} catch (err) {
Module.runtimeKeepalivePop();
if (keepAlivePushed && !runtimeHelpers.runtimeReady) Module.runtimeKeepalivePop();
mono_log_error("onRuntimeInitializedAsync() failed", err);
Comment on lines +33 to +38
// Mono's LLVM backend uses the global-context LLVM-C type accessors (LLVMInt32Type, etc.)
// pervasively. These are deprecated in newer LLVM versions in favor of the *InContext variants.
// Suppress the deprecation warnings rather than threading an LLVMContextRef through every call site.
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Comment on lines 24 to 26
${MONO_ARTIFACTS_DIR}/libmono-icall-table.a
${MONO_ARTIFACTS_DIR}/libmono-wasm-eh-js.a
${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_EH_LIB}.a
${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants