Skip to content

Add Wasm EH R2R infrastructure - #129197

Merged
davidwrighton merged 9 commits into
dotnet:mainfrom
davidwrighton:wasm_eh_infra
Jun 13, 2026
Merged

Add Wasm EH R2R infrastructure#129197
davidwrighton merged 9 commits into
dotnet:mainfrom
davidwrighton:wasm_eh_infra

Conversation

@davidwrighton

@davidwrightondavidwrighton commented Jun 9, 2026

Copy link
Copy Markdown
Member

Note

This PR description was generated by GitHub Copilot.

Summary

  • Add runtime and JIT support needed for Wasm EH flow in ReadyToRun scenarios
  • Export/import the RtlRestoreContext exception tag for Wasm modules
  • Add a Wasm relocation type for referencing the RtlRestoreContext tag

Testing

  • Verified that finally clauses work
  • Verified that the body of catch clauses works
  • Resume after catch is not yet functional and requires additional JIT changes

Notes:
The exception thrown for catch downstream carries with it the "IP" and SP of the context we want to resume to. The JIT team can decide if this is actually useful. Be aware that the "IP" in this case is simply the return value from the catch clause.

- Make STACKWALK_CONTROLPC_ADJUST_OFFSET 2 so that it doesn't break the IsVirtualIP check
- Avoid using STACKWALK_CONTROLPC_ADJUST_OFFSET in most cases with virtual ips
- Implement EECodeManager::CallFunclet for WASM
- Add GetWasmFunctionTableIndexFromVirtualIP for use by CallFunclet
- Add exception tag type for RtlRestoreContext to be used during EH flow

CopilotAI 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 adds WebAssembly ReadyToRun (R2R) exception-handling plumbing across the runtime, toolchain, and hosts by introducing a CoreCLR-specific Wasm exception tag for RtlRestoreContext, wiring it through Webcil import/export, and extending relocation/JIT-interface support so R2R code can reference that tag.

Changes:

  • Export/import a new Wasm exception tag (__coreclr_wasm_rtlrestorecontext_tag) and plumb it through the JS hosts and build/link flags.
  • Implement Wasm RtlRestoreContext using a tag throw with (ip, sp) payload, and add Wasm-specific funclet invocation helpers + stackwalk adjustments for virtual IPs.
  • Add a new Wasm relocation kind to reference the restore-context exception tag in object writing / relocation resolution, and update the JIT-EE interface version.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
FileDescription
src/native/corehost/browserhost/CMakeLists.txtExports the restore-context tag from the CoreCLR browserhost Wasm module.
src/mono/browser/build/BrowserWasmApp.CoreCLR.targetsEnsures the restore-context tag is exported during app relink.
src/coreclr/vm/wasm/helpers.cppDefines/throws the new tag for RtlRestoreContext; adds Wasm funclet call helpers via call_indirect.
src/coreclr/vm/wasm/cgencpu.hAdjusts Wasm stackwalk ControlPC adjust offset.
src/coreclr/vm/exceptionhandling.cppSkips ControlPC adjustment for Wasm virtual IP frames during EH stack walks.
src/coreclr/vm/eetwain.cppEnables invoking Wasm EH funclets via function table indices and Wasm frame pointer recovery.
src/coreclr/vm/codeman.hDeclares a new ExecutionManager mapping from virtual IP to function table index.
src/coreclr/vm/codeman.cppImplements virtualIP→functionIndex mapping; decodes Wasm virtual IP encoding for EH clauses.
src/coreclr/tools/Common/JitInterface/CorInfoTypes.csAdds a new CorInfoReloc value for the Wasm restore-context exception tag.
src/coreclr/tools/Common/JitInterface/CorInfoImpl.csMaps the new CorInfoReloc to the internal RelocType.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.csImports the restore-context tag into Webcil modules; resolves the new relocation kind.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.csAdds tag-import encoding support (WasmTagImportType).
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.csAllows emitting placeholder bytes for the new relocation kind.
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.csDefines/handles the new relocation type for padded ULEB32 write/read/size.
src/coreclr/inc/jiteeversionguid.hUpdates JIT-EE interface version GUID due to interface surface changes.
src/coreclr/inc/corinfo.hAdds the new relocation kind to the native JIT-EE contract.
src/coreclr/hosts/corerun/wasm/libCorerun.jsPasses the exported tag as a Webcil import; validates it exists post-link.
src/coreclr/hosts/corerun/CMakeLists.txtExports the restore-context tag from the corerun Wasm build.
eng/native.wasm.targetsAdds the tag to the exported-symbol preservation list for Wasm builds.

Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/vm/codeman.h Outdated
Comment threadsrc/coreclr/vm/exceptionhandling.cpp
Comment threadsrc/coreclr/vm/codeman.cpp
Use the Wasm R2R stack-walk terminator in funclet helpers, clarify the virtual IP parameter name, and skip stack-trace IP adjustment for Wasm virtual IPs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@AndyAyersMSAndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I probably shouldn't be the only approver for this, but these changes work well for me in my initial testing.

I have not tried out using the exception tag yet in codegen. Soon.

CopilotAI review requested due to automatic review settings June 10, 2026 23:46

CopilotAI 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

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

Comment threadsrc/coreclr/inc/jiteeversionguid.h Outdated
Comment threadsrc/coreclr/vm/eventtrace.cpp
Comment threadsrc/coreclr/vm/eetwain.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 11, 2026 00:08

CopilotAI 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

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

Comment threadsrc/coreclr/vm/eventtrace.cpp
Comment threadsrc/coreclr/vm/codeman.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp Outdated
Comment threadsrc/coreclr/vm/wasm/helpers.cpp Outdated
Comment threadsrc/coreclr/vm/wasm/helpers.cpp

@adamperlinadamperlin 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.

Overall lgtm, but I just had some suggestions about comments

@davidwrighton

Copy link
Copy Markdown
MemberAuthor

/ba-g only interesting test failures are #129242

CopilotAI review requested due to automatic review settings June 13, 2026 12:39

CopilotAI 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

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

Comment threadsrc/coreclr/vm/eventtrace.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp
@davidwrighton

Copy link
Copy Markdown
MemberAuthor

/ba-g known infra problems

@davidwrighton
davidwrighton merged commit f363796 into dotnet:mainJun 13, 2026
174 of 183 checks passed
@pavelsavarapavelsavara added the arch-wasm WebAssembly architecture label Jun 16, 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.

@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 17, 2026
@AndyAyersMSAndyAyersMS mentioned this pull request Jun 19, 2026
12 tasks
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
> [!NOTE]
> This PR description was generated by GitHub Copilot.
## Summary
- Add runtime and JIT support needed for Wasm EH flow in ReadyToRun
scenarios
- Export/import the `RtlRestoreContext` exception tag for Wasm modules
- Add a Wasm relocation type for referencing the `RtlRestoreContext` tag
## Testing
- Verified that finally clauses work
- Verified that the body of catch clauses works
- Resume after catch is not yet functional and requires additional JIT
changes
Notes:
The exception thrown for catch downstream carries with it the "IP" and
SP of the context we want to resume to. The JIT team can decide if this
is actually useful. Be aware that the "IP" in this case is simply the
return value from the catch clause.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 18, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@davidwrighton@AndyAyersMS@adamperlin@pavelsavara