Skip to content

[browser] preparation for emscripten bump to v5#127323

Open
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:emscripten_prep
Open

[browser] preparation for emscripten bump to v5#127323
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:emscripten_prep

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

@pavelsavara pavelsavara commented Apr 23, 2026

TODO: run extra platforms

Contributes to #113786
Replaces #119409

This PR makes preparatory changes across native build infrastructure and C source files to enable a future Emscripten SDK upgrade (from the current 3.1.56). The changes fix compatibility issues with newer Emscripten/LLVM/wasm-opt toolchain versions.

Changes

Linker flag syntax fix (-Wl,--error-limit=0)

Newer versions of wasm-ld require the double-dash form --error-limit=0 instead of the deprecated single-dash -error-limit=0. Updated in:

  • eng/native/configureplatform.cmake
  • src/coreclr/hosts/corerun/CMakeLists.txt
  • src/mono/browser/build/BrowserWasmApp.CoreCLR.targets
  • src/native/corehost/browserhost/CMakeLists.txt

Add --enable-nontrapping-float-to-int to wasm-opt

Newer Emscripten emits i32.trunc_sat_f64_s and similar nontrapping float-to-int instructions. Without this flag, wasm-opt rejects the binary. Added in:

  • src/mono/browser/browser.proj (threaded builds)
  • src/mono/browser/runtime/CMakeLists.txt (release post-build step)
  • src/mono/wasi/wasi.proj (threaded WASI builds)
  • src/mono/wasm/build/WasmApp.Common.targets (user app publish)

Remove TEXTDECODER=0 workaround

The Emscripten threading + TextDecoder issue (emscripten#18034) has been fixed upstream. Removed the -s TEXTDECODER=0 workaround from src/mono/browser/browser.proj.

Export HEAP views from Emscripten runtime

Added HEAP8, HEAP16, HEAPU8, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64, HEAP64, HEAPU64 to EmccExportedRuntimeMethod in src/mono/browser/browser.proj. Newer Emscripten no longer exports these by default.

Use generic LLVM sub_sat intrinsics for WASM

Replaced WASM-specific wasm_sub_sat_signed/wasm_sub_sat_unsigned intrinsics with the generic LLVM ssub_sat/usub_sat intrinsics (already used for x86 SSE). This aligns with newer LLVM which may not expose the WASM-specific variants.

  • src/mono/mono/mini/llvm-intrinsics.h — moved sub_sat entries into the shared x86+WASM block and removed WASM-specific ones
  • src/mono/mono/mini/simd-intrinsics.c — updated switch cases to use the shared intrinsic IDs

Fix Windows emsdk environment setup

In eng/native/gen-buildsys.cmd:

  • Changed emsdk_envemsdk_env.cmd for explicit script extension
  • Fixed quoting: set EMSDK_QUIET=1set "EMSDK_QUIET=1" to avoid trailing spaces in the variable

Suppress new Clang warnings

  • Added -Wno-c++-keyword compiler flag for browser/WASI targets in src/native/libs/CMakeLists.txt (suppresses warnings about C identifiers that are C++ keywords)
  • Added #pragma clang diagnostic ignored "-Wjump-misses-init" in:
    • src/native/libs/System.Globalization.Native/pal_icushim_static.c
    • src/native/libs/System.Native/pal_networking.c
    • src/native/libs/System.Native/pal_threading.c

ICU shim C code fixes

In src/native/libs/System.Globalization.Native/pal_icushim_static.c:

  • Changed UErrorCode status = 0UErrorCode status = U_ZERO_ERROR (proper enum initializer)
  • Added explicit (char *) cast on malloc return (C++ compatibility)
  • Moved file_buf_size declaration to top of function to avoid "jump misses init" with goto error patterns

@pavelsavara pavelsavara added this to the 11.0.0 milestone Apr 23, 2026
@pavelsavara pavelsavara self-assigned this Apr 23, 2026
Copilot AI review requested due to automatic review settings April 23, 2026 14:53
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Apr 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.

Copy link
Copy Markdown
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

Prepares the Browser/WASI toolchain and runtime code for an upcoming Emscripten v5 bump by adjusting Clang warning handling, wasm-opt feature flags, and some WASM SIMD intrinsic plumbing.

Changes:

  • Add Clang diagnostic suppression for -Wjump-misses-init in several native PAL sources used by Browser/WASI builds.
  • Enable --enable-nontrapping-float-to-int in wasm-opt invocations and propagated wasm-opt configuration flags.
  • Update Mono WASM SIMD saturating-subtract lowering to use existing SSE-style intrinsic IDs, and adjust LLVM intrinsic tables accordingly.

Reviewed changes

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

Show a summary per file
File Description
src/native/libs/System.Native/pal_threading.c Adds Clang diagnostic suppression intended to unblock newer Clang/Emscripten builds.
src/native/libs/System.Native/pal_networking.c Adds Clang diagnostic suppression intended to unblock newer Clang/Emscripten builds.
src/native/libs/System.Globalization.Native/pal_icushim_static.c Adds suppression and cleans up some ICU error-code/buffer-size initialization patterns.
src/native/libs/CMakeLists.txt Suppresses -Wc++-keyword for Clang when targeting Browser/WASI.
src/mono/wasm/build/WasmApp.Common.targets Updates wasm-opt invocation to enable nontrapping float-to-int.
src/mono/wasi/wasi.proj Propagates the nontrapping float-to-int feature into generated wasm-opt configuration flags.
src/mono/mono/mini/simd-intrinsics.c Switches WASM saturating subtract intrinsic selection to SSE-style intrinsic IDs.
src/mono/mono/mini/llvm-intrinsics.h Adjusts intrinsic availability/definitions to match the new SSE-style IDs and removes old WASM-specific sub-sat entries.
src/mono/browser/runtime/CMakeLists.txt Updates the post-build wasm-opt command to enable nontrapping float-to-int.
src/mono/browser/browser.proj Exports HEAP views for Emscripten runtime, updates wasm-opt flags, and removes a threads-only TEXTDECODER workaround.
eng/native/gen-buildsys.cmd Calls emsdk_env.cmd and fixes quoting to match current Emscripten SDK provisioning scripts.

Comment thread src/native/libs/System.Native/pal_threading.c
Comment thread src/native/libs/System.Native/pal_networking.c
Comment thread src/native/libs/System.Globalization.Native/pal_icushim_static.c
Copilot AI review requested due to automatic review settings April 23, 2026 21:44
Copy link
Copy Markdown
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Comment thread src/native/libs/System.Native/pal_threading.c
Comment thread eng/native/gen-buildsys.cmd
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara marked this pull request as ready for review April 24, 2026 06:19
Copy link
Copy Markdown
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

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

Looks good to me and my copilot 👍

@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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