Skip to content

wasm: fix R2R generic dictionary lookup debug assert - #129947

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-r2r-generic-dict-assert
Jun 28, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-r2r-generic-dict-assert

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

On wasm, R2R code lives in the function table and R2R data in linear memory, so the
GenericHandleWorkerCore debug assert's ExecutionManager::FindReadyToRunModule (a
code-range lookup) cannot resolve the dictionary signature's data address and returns the
wrong module, firing IsNativeImageSharedBy spuriously once more than one R2R image is
loaded. The signature is taken from pModule's own R2R image (FindToken returns the
incoming blob), so on wasm the assert instead checks that the signature lies within
pModule's R2R image bounds; other targets are unchanged.

This is a _DEBUG-only assert (FindReadyToRunModule has no other callers), so release
behavior is unaffected. It was the single most common failure when running the Pri-1 R2R
test suite on wasm, accounting for ~half of all observed assert failures and the bulk of the
generics tests.

On wasm, R2R code and data live in separate address spaces, so
FindReadyToRunModule can't resolve the dictionary signature's data address.
Check the signature lies within pModule's R2R image bounds instead.

Co-authored-by: Copilot <[email protected]>
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@davidwrighton PTAL
fyi @dotnet/wasm-contrib

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

Adjusts a _DEBUG-only invariant check in the CoreCLR generics dictionary lookup helper to account for WASM ReadyToRun (R2R) layout differences (code in function table vs data in linear memory), avoiding a module-lookup assert failure when multiple R2R images are loaded.

Changes:

  • Add a TARGET_WASM-specific debug assert path in GenericHandleWorkerCore that validates the signature address against the current module’s R2R image bounds.
  • Keep the existing ExecutionManager::FindReadyToRunModule / IsNativeImageSharedBy debug assert unchanged for non-WASM targets.

Comment thread src/coreclr/vm/jithelpers.cpp Resolved
@AndyAyersMS
AndyAyersMS merged commit 9cb68cd into dotnet:main Jun 28, 2026
113 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 29, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label 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.

eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
On wasm, R2R code lives in the function table and R2R data in linear
memory, so the
`GenericHandleWorkerCore` debug assert's
`ExecutionManager::FindReadyToRunModule` (a
code-range lookup) cannot resolve the dictionary signature's data
address and returns the
wrong module, firing `IsNativeImageSharedBy` spuriously once more than
one R2R image is
loaded. The signature is taken from `pModule`'s own R2R image
(`FindToken` returns the
incoming blob), so on wasm the assert instead checks that the signature
lies within
`pModule`'s R2R image bounds; other targets are unchanged.

This is a `_DEBUG`-only assert (`FindReadyToRunModule` has no other
callers), so release
behavior is unaffected. It was the single most common failure when
running the Pri-1 R2R
test suite on wasm, accounting for ~half of all observed assert failures
and the bulk of the
generics tests.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants