Conversation
Direct P/Invokes in WASM ReadyToRun images are now emitted as 'webcil' function imports called directly, instead of going through the build-time generated P/Invoke lookup table. The host resolves these imports against the native runtime's wasmExports, and crossgen2's call-helper generator emits callhelpers-exports.txt so link steps export the needed symbols. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
R2R WASM images now import [WasmImportLinkage] P/Invoke targets as module.entryPoint instead of routing them through the webcil exports or the generated P/Invoke table. The browser and corerun hosts resolve these imports from the runtime module's imports, or install throwing stubs to preserve lazy binding failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
P/Invokes that are direct only because their module is listed in DirectPInvokes go back to the PInvokeTarget fixup resolved through the generated table. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove the lazy-resolution Proxy import objects and throw-on-call stubs. The hosts now pass the runtime module's exports (webcil) and imports (WasmImportLinkage modules) directly, so missing imports fail at instantiation like any WASM import. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The browser and WASI corerun links listed every QCall export inline, which exceeds the Windows command-line limit. Emscripten reads EXPORTED_FUNCTIONS from a file and clang reads the WASI export options from a response file. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Link Node corerun with WASM_BIGINT so QCall exports keep i64 signatures. - Resolve JS-implemented QCalls from the runtime's env imports. - Match FreeGCHandleForTypeHandle's managed return type to its native void. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove QCall export plumbing and QCall/FCall-specific Webcil imports while preserving plain WasmImportLinkage imports and configured direct P/Invoke behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 6 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
jkoritzinsky
requested review from
davidwrighton
and
a balanced review from Copilot
December 3, 2026 01:14
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Distinct signatures sharing a module and entrypoint get identical symbols and collapse into one import, causing WebAssembly type-validation failures for incompatible calls.
1 open issue
What changed in this PR
Adds direct binding of [WasmImportLinkage] P/Invokes to their declared modules in CoreCLR WebAssembly ReadyToRun images.
Changes:
- Emits module-qualified imports and reuses host-provided imports during loading.
- Unifies direct-call lowering and corrects
FreeGCHandle’s return type. - Adds import, fixup, and function-index coverage.
| File | Description |
|---|---|
src/native/libs/Common/JavaScript/host/assets.ts |
Reuses host imports for ReadyToRun loading. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs |
Selects direct imports for attributed P/Invokes. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunSymbolNodeFactory.cs |
Creates module-qualified import symbols. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/WasmR2RAssert.cs |
Accounts for imported functions in assertions. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/Webcil/WasmImportLinkagePInvoke.cs |
Adds representative P/Invoke test declarations. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs |
Tests declared modules, fixups, and indices. |
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs |
Matches native FreeGCHandle’s void return. |
src/coreclr/jit/lowerwasm.cpp |
Allows direct ReadyToRun function symbols. |
src/coreclr/jit/lower.cpp |
Removes the redundant ReadyToRun special case. |
src/coreclr/hosts/corerun/wasm/libCorerun.js |
Supplies Emscripten imports to Webcil images. |
Review effort: Balanced
| private NodeCache<(string ImportModule, string ImportName, MethodSignature Signature), ExternFunctionSymbolNode> _wasmImportLinkagePInvokeTargets = | ||
| new NodeCache<(string ImportModule, string ImportName, MethodSignature Signature), ExternFunctionSymbolNode>(key => | ||
| { | ||
| Utf8String symbolName = new Utf8String($"{key.ImportModule}#{key.ImportName}"); |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
023f5ece48de8f79e38ed34e0563b8e445324e41↓ Browser end-to-end execution was not rerun after the final changes.
There was no mechanism to provide module imports for user-owned
[WasmImportLinkage]P/Invokes, so add that support.WebAssembly ReadyToRun images can more efficiently bind
[WasmImportLinkage]P/Invokes to their declared WebAssembly imports rather than resolving them through the generated P/Invoke table.[WasmImportLinkage]and reuse host-provided imports when instantiating R2R Webcil images.FreeGCHandlewith its nativevoidreturn type.Validation
.\build.cmd clr+libs -os browser -configuration Release /p:NuGetAudit=false- passed..\build.cmd -s clr.r2rtests -os browser -arch wasm -lc Release -c Release -test /p:NuGetAudit=false- passed: 399 passed, 43 skipped, 0 failed.Note
This description was generated with GitHub Copilot.