Skip to content

[Wasm] Workaround for release corerun.wasm not having exported stack pointer#128207

Closed
kg wants to merge 1 commit into
dotnet:mainfrom
kg:wasm-corerun-release-workaround
Closed

[Wasm] Workaround for release corerun.wasm not having exported stack pointer#128207
kg wants to merge 1 commit into
dotnet:mainfrom
kg:wasm-corerun-release-workaround

Conversation

@kg

@kg kg commented May 14, 2026

Copy link
Copy Markdown
Contributor

emscripten's wasm-opt appears to have a bug that strips the stack pointer export from our runtime module, which prevents loading R2R'd wasm code in release builds. Passing -g to enable DWARF information for the runtime appears to work around this by forcing 'limited post-link optimizations'. I tried a bunch of other stuff and this was the only thing that worked.

Note that I can't reproduce this wasm-opt bug using latest emscripten on linux, so it's possible @pavelsavara 's emscripten bump will fix it for us.

See also #128167 which handles this failure better.

EDIT: Repro steps using https://github.com/kg/wasm-ryujit-runner :

dotnet run wasm-ryujit-runner.cs -- --auto-build --config Debug --checkout Z:\runtime --assembly Z:\wasm-test\bin\Debug\net10.0\wasm-test.dll --corerun
works
dotnet run wasm-ryujit-runner.cs -- --auto-build --config Release --checkout Z:\runtime --assembly Z:\wasm-test\bin\Debug\net10.0\wasm-test.dll --corerun
broken due to missing __stack_pointer

cc @adamperlin @AndyAyersMS @davidwrighton

Copilot AI review requested due to automatic review settings May 14, 2026 16:25
@kg kg added the arch-wasm WebAssembly architecture label May 14, 2026

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 CoreCLR corerun WASM (browser) link flags to work around a tooling issue where the final corerun.wasm ends up missing the __stack_pointer export, which is needed for loading additional WASM modules (e.g., R2R’d modules) against the runtime module.

Changes:

  • Add an Emscripten -g link flag to alter/limit post-link optimization behavior (wasm-opt) as a workaround to preserve __stack_pointer export.
  • Document the rationale inline in the CMake configuration.

Comment on lines +95 to +98
# -g forces 'limited post-link optimizations'. I tried a dozen other workarounds and this is the only thing that worked.
# This bug may be fixed in latest emscripten.
target_link_options(corerun PRIVATE
-g)
Comment on lines +94 to +96
# HACK: Workaround for bug in wasm-opt that strips __stack_pointer
# -g forces 'limited post-link optimizations'. I tried a dozen other workarounds and this is the only thing that worked.
# This bug may be fixed in latest emscripten.
@adamperlin

Copy link
Copy Markdown
Contributor

This seems reasonable as a workaround. Do we have a tracking issue to see if this can be removed once we've bumped emscripten? Also I'm curious if -g1 or -g2 have any similar effect?

@pavelsavara pavelsavara self-assigned this May 20, 2026
@kg

kg commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

This seems reasonable as a workaround. Do we have a tracking issue to see if this can be removed once we've bumped emscripten? Also I'm curious if -g1 or -g2 have any similar effect?

There is not a separate tracking issue yet. If we merge this or another workaround I'll make sure we have a tracking issue.

I haven't tested g1 or g2 yet to see if they also fix it at a lesser file size cost.

@pavelsavara

Copy link
Copy Markdown
Member

I will have look at this next week.

@pavelsavara

Copy link
Copy Markdown
Member

@kg This is my attempt at solving the issue, please tests it with R2R

#128567

@github-actions github-actions Bot locked and limited conversation to collaborators Jun 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-Host

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants