Skip to content

Fix generic lookups and thunks#129825

Open
davidwrighton wants to merge 7 commits into
dotnet:mainfrom
davidwrighton:FixGenericLookupsAndThunks
Open

Fix generic lookups and thunks#129825
davidwrighton wants to merge 7 commits into
dotnet:mainfrom
davidwrighton:FixGenericLookupsAndThunks

Conversation

@davidwrighton

@davidwrighton davidwrighton commented Jun 24, 2026

Copy link
Copy Markdown
Member

Add support for generic lookups to Wasm R2R code by following the DynamicHelper pattern we use on other platforms. This looks like a quite suitable implementation for Wasm, so I expect that this will remain for the long term.

Add support for WebAssembly .S files, as it was difficult to implement the helpers in inline assembly due to clang limitations.
Tweak Crossgen2 into generating uses of the DynamicHelper logic.

Also add support for precomputed thunks for various runtime helpers which were missing them, and add an assert that will fire even in interpreted runs for missing cases.

Fixes (most) of #129622
Fixes #129821

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
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 extends the WebAssembly ReadyToRun (R2R) pipeline to support generic dictionary lookups and related delay-load helper paths using the “DynamicHelper” pattern already used on other architectures, including adding dedicated Wasm .S helpers and updating Crossgen2’s Wasm thunk/signature plumbing accordingly.

Changes:

  • Add new Wasm dynamic helper stubs (in .S) for generic dictionary lookup variants and supporting VM glue to allocate the corresponding portable-entrypoint stub data.
  • Update Wasm delay-load/import thunk generation to support generic lookups via portable entrypoints (signature updates + always generating a thunk).
  • Add missing Wasm portable-entrypoint interpreter-call thunks for additional signatures (e.g., double arg + i32/i64 return, and S8 payload).

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/vm/wasm/helpers.cpp Adds additional portable-entrypoint interpreter-call thunks and updates the portable-entrypoint thunk table; removes Wasm placeholder DelayLoad_Helper stubs.
src/coreclr/vm/wasm/dynamichelpers.S New Wasm assembly implementations of generic dictionary lookup dynamic helpers (incl. size-check / null-test variants and small constant-offset fast paths).
src/coreclr/vm/wasm/dynamichelpers.cpp Implements Wasm DelayLoad_Helper entry and creates portable-entrypoint data for generic dictionary lookup helpers on Wasm.
src/coreclr/vm/wasm/asmconstants.h Introduces Wasm-specific asm constants/offsets needed by dynamichelpers.S (with debug/fre handling and static-assert hooks).
src/coreclr/vm/readytoruninfo.h Adds GenericDictionaryDynamicHelperStubData_PortableEntryPoint layout used by Wasm helper stubs.
src/coreclr/vm/prestub.cpp Allows resolving import sections by RVA when sectionIndex == (DWORD)-1 (used by Wasm delay-load helper), and excludes non-Wasm fixup kinds under TARGET_WASM.
src/coreclr/vm/jitinterface.cpp Adds a debug assert ensuring portable-entrypoint targets have actual code under R2R (helps catch missing cases).
src/coreclr/vm/CMakeLists.txt Wires new Wasm .S and .cpp sources (and asmconstants header) into the VM build.
src/coreclr/vm/cgensys.h Adjusts DelayLoad_Helper declaration for Wasm to match the new calling convention/signature.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/.../WasmImportThunkPortableEntrypoint.cs Updates generic-lookup thunk signature shape/string to include the portable-entrypoint parameter.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/.../DelayLoadHelperImport.cs Always generates a Wasm import-thunk portable entrypoint (including for generic lookups).
eng/native/configurecompiler.cmake Enables ASM for Browser/WASI toolchains so preprocessed Wasm .S files can be assembled by clang-based toolchains.

Comment thread src/coreclr/vm/wasm/helpers.cpp
Comment thread src/coreclr/vm/wasm/helpers.cpp
Comment thread src/coreclr/vm/wasm/dynamichelpers.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 22:53

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

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

Comment thread src/coreclr/vm/wasm/helpers.cpp Outdated
Comment thread src/coreclr/vm/cgensys.h
Comment thread src/coreclr/vm/wasm/dynamichelpers.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 23:01

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Comment thread src/coreclr/vm/wasm/helpers.cpp Outdated
Comment on lines +44 to +48
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericClassDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pClassWithSlotAndModule
Comment on lines +90 to +94
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericMethodDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pMethodWithSlotAndModule
Comment on lines +128 to +132
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericClassDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pClassWithSlotAndModule
Comment on lines +243 to +247
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericMethodDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pMethodWithSlotAndModule
Comment on lines +340 to +344
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pClassWithSlotAndModule
Comment on lines +361 to +365
local.get 1 // Load the GenericContext
local.get 2 // Load the GenericDictionaryDynamicHelperStubData parameter
i32.load OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
i32.const 0
i32.load g_pMethodWithSlotAndModule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm][coreCLR] R2R generic dictionary lookup traps with ull function (zero import cell for GenericLookupSignature)

2 participants