Skip to content

[browser][coreCLR] enable -O3 after emscripten bump#130111

Merged
pavelsavara merged 1 commit into
dotnet:mainfrom
pavelsavara:browser-enable-o3
Jul 2, 2026
Merged

[browser][coreCLR] enable -O3 after emscripten bump#130111
pavelsavara merged 1 commit into
dotnet:mainfrom
pavelsavara:browser-enable-o3

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Fixes #128686.

The emscripten 5.0.6 / LLVM 23 bump (#113786) no longer strips user-requested wasm exports during -O3 metadce, so the workarounds added in #128567 are no longer needed.

Changes

  • eng/native/configureoptimization.cmake — remove the browser-only -O2 link special-case and let browser use -O3 like the other UNIX targets (reverts the [browser][coreCLR] Export __stack_pointer global #128567 hunk; the file is now identical to its pre-[browser][coreCLR] Export __stack_pointer global #128567 state).
  • src/native/corehost/browserhost/CMakeLists.txt, src/coreclr/hosts/corerun/CMakeLists.txt, src/mono/browser/build/BrowserWasmApp.CoreCLR.targets — drop the explicit -Wl,--export=__stack_pointer and -Wl,--export=__coreclr_wasm_rtlrestorecontext_tag. Both symbols are exported via -sEXPORTED_FUNCTIONS (the EmccExportedFunction items in eng/native.wasm.targets) alone.

-lexports.js (MINIFY_WASM_EXPORT_NAMES=0) is kept so the raw export names remain un-minified for the JS-side wasmExports['__stack_pointer'] / tag lookups.

Testing

Built clr+libs+host for -os browser -c Release (CoreCLR), 0 warnings / 0 errors, and inspected the exports with wa-info:

  • -O3 shared framework dotnet.native.wasm:
    • (export "__stack_pointer" (GlobalIdx 0))
    • (export "__coreclr_wasm_rtlrestorecontext_tag" (4 1)) — the wasm tag (kind 4) survives via EXPORTED_FUNCTIONS.
  • -O2 app-relinked console-node sample wasm: both exports present as well.
  • console-node (Release/CoreCLR) runs and returns the expected exit code 3 (args.Length), exercising reverse-pinvoke (__stack_pointer) and the EH path (__coreclr_wasm_rtlrestorecontext_tag).

Note

This PR description was drafted with GitHub Copilot.

…ds (dotnet#128686)

emsdk 5.0.6 (dotnet#113786) no longer strips wasm exports at -O3 metadce. Restore -O3 (revert the -O2 link workaround from dotnet#128567) and drop the explicit -Wl,--export for both __stack_pointer (global) and __coreclr_wasm_rtlrestorecontext_tag (tag). Both are exported via -sEXPORTED_FUNCTIONS (EmccExportedFunction) alone, verified with wa-info on the -O3 shared framework and the -O2 app relink; console-node sample runs (exit 3). Keep -lexports.js to preserve the raw export names.
Copilot AI review requested due to automatic review settings July 2, 2026 08:53
@pavelsavara pavelsavara self-assigned this Jul 2, 2026
@github-actions github-actions Bot added the area-Infrastructure-coreclr Only use for closed issues label Jul 2, 2026
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm and removed area-Infrastructure-coreclr Only use for closed issues labels Jul 2, 2026
@pavelsavara pavelsavara added this to the 11.0.0 milestone Jul 2, 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 WASM/Browser CoreCLR build configuration to remove now-unneeded export-preservation workarounds and to restore the standard Release optimization behavior after the Emscripten/LLVM toolchain bump.

Changes:

  • Removes the Browser-specific -O2 Release link optimization override so Browser builds follow the normal UNIX -O3 Release configuration.
  • Drops explicit -Wl,--export=__stack_pointer and -Wl,--export=__coreclr_wasm_rtlrestorecontext_tag link flags from Browser host / corerun / CoreCLR BrowserWasmApp, relying on the centralized -sEXPORTED_FUNCTIONS list instead.
  • Keeps -lexports.js to prevent export-name minification (so JS-side lookups by raw export name continue to work).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
eng/native/configureoptimization.cmake Removes the Browser-only Release link -O2 special-case so Release Browser builds align with other UNIX targets.
src/native/corehost/browserhost/CMakeLists.txt Removes explicit wasm --export flags for __stack_pointer and the EH tag, relying on -sEXPORTED_FUNCTIONS.
src/coreclr/hosts/corerun/CMakeLists.txt Same export-flag removal for the corerun WASM link step.
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets Removes explicit wasm --export flags from the managed build pipeline’s emcc link args (still emits -lexports.js).

@pavelsavara pavelsavara enabled auto-merge (squash) July 2, 2026 11:22
@pavelsavara pavelsavara merged commit 8557105 into dotnet:main Jul 2, 2026
197 of 200 checks passed
@pavelsavara pavelsavara deleted the browser-enable-o3 branch July 2, 2026 12:56
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview7 Jul 3, 2026
lewing added a commit that referenced this pull request Jul 11, 2026
…tive (#130543)

## Summary

Fixes the browser-wasm **CoreCLR** library test leg
(`WasmTestOnChrome-CLR` → `System.Globalization.Extensions.Tests`),
failing on `main` since 2026-07-09 with:

```
System.DllNotFoundException : Unable to load shared library 'libSystem.Globalization.Native' ...
dynamic linking not enabled
   at Interop.Globalization.ToUnicode(...)
   at System.Globalization.IdnMapping.IcuTryGetUnicodeCore(...)
```

Tracked by #130479 (`blocking-clean-ci`).

## Root cause

#130140 added `GlobalizationNative_InitOrdinalLowerCasingPage` to the
generated `callhelpers-pinvoke.cpp` P/Invoke tables (browser + wasi) —
correctly inserting the sorted entry and its `extern "C"` declaration —
but did **not** update the hard-coded `EntryCount` in `s_PInvokeTables`
(left at `33`, now `34` entries).

`minipal_resolve_dllimport` (`src/native/minipal/entrypoints.h`)
linearly scans `entries[0 .. count-1]`. With `count = 33` over the
34-entry table, the **last** entry — `GlobalizationNative_ToUnicode` —
became unreachable, so its P/Invoke resolved to `NULL` and fell back to
`dlopen` (unsupported for CoreCLR-wasm) → `DllNotFoundException`. This
is why **only** `IdnMapping.GetUnicode`/`ToUnicode` tests failed while
`GetAscii` (`ToAscii`, index 32, still in range) kept passing.

The generator emits this count from the table length, so `34` is exactly
what a regeneration produces; #130140 hand-edited the generated file
without re-running it.

## Fix

Bump the `libSystem.Globalization.Native` `EntryCount` from `33` → `34`
in both:
- `src/coreclr/vm/wasm/browser/callhelpers-pinvoke.cpp`
- `src/coreclr/vm/wasm/wasi/callhelpers-pinvoke.cpp`

All other module counts already match their tables (verified in both
files).

## Regression window (bisected on `main`, definition 129)

| Build | SHA | `LibraryTestsCoreCLR` |
|---|---|---|
| 1500867 (Jul 9 08:00) | `0f907bfa` (no #130140) | ✅ pass |
| 1502091 (Jul 9 20:00) | `6c584914` (has #130140) | ❌ fail — same
signature |

Emscripten 5.0.6/LLVM23 (Jun 25) and -O3 (#130111, Jul 2) were ruled out
— the leg stayed green with both for two weeks.

## Verification

- Native reproduction against the real `minipal/entrypoints.h`:
`ToUnicode` resolves `NULL` at count 33 and `FOUND` at count 34;
`ToAscii` resolves at 33 (matches the observed pass/fail split).
- The browser-wasm CoreCLR `WasmTestOnChrome-CLR` CI leg exercises this
end-to-end.

cc @tarekgh @pavelsavara @lewing

> [!NOTE]
> Root-cause investigation and this fix were produced with GitHub
Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

[browser][coreCLR] enable -O3 after emscripten bump

3 participants