[Wasm] Workaround for release corerun.wasm not having exported stack pointer#128207
[Wasm] Workaround for release corerun.wasm not having exported stack pointer#128207kg wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
-glink flag to alter/limit post-link optimization behavior (wasm-opt) as a workaround to preserve__stack_pointerexport. - Document the rationale inline in the CMake configuration.
| # -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) |
| # 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. |
|
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 |
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. |
|
I will have look at this next week. |
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
-gto 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 --corerunworks
dotnet run wasm-ryujit-runner.cs -- --auto-build --config Release --checkout Z:\runtime --assembly Z:\wasm-test\bin\Debug\net10.0\wasm-test.dll --corerunbroken due to missing
__stack_pointercc @adamperlin @AndyAyersMS @davidwrighton