Skip to content

Relink browser Wasm ReadyToRun apps - #134291

Closed
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing-guarded-pinvoke-follow-up
Closed

lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing-guarded-pinvoke-follow-up

Conversation

@lewing

@lewing lewing commented Sep 20, 2026

Copy link
Copy Markdown
Member

Summary

Browser CoreCLR ReadyToRun publishing now implies WasmBuildNative=true, ensuring Crossgen2 and the generated P/Invoke call-helper table process the same managed closure.

The failure occurred when per-app ReadyToRun compilation classified framework modules such as System.Native as direct while WasmBuildNative=false reused the prebuilt framework-only helper table. Test-only entry points such as SystemNative_GetEUid were then absent from that table and failed during ReadyToRun fixup before the guarded call was reached.

This change:

  • preserves the direct-P/Invoke compiler policy introduced by Classify Wasm P/Invokes before R2R codegen #133773, including direct PINVOKE_TARGET codegen;
  • makes browser ReadyToRun nested publishes require native relinking, while leaving WASI unchanged;
  • preserves explicitly requested VFS payloads in trimmed CoreCLR browser tests without restoring the broad untrimmed dependency set;
  • adds a trimmed guarded SystemNative_GetEUid regression;
  • updates ReadyToRun WBT coverage and validates custom native modules through the generated --directpinvoke:native-lib response-file entry.

Validation

  • Browser clr+libs+host+packs build passed.
  • Full trimmed System.Runtime.Extensions.Tests: 8,308 passed, 70 skipped, 0 failed.
  • ReadyToRun WBT class: 5/5 passed before the final main rebase; the post-rebase product/library validation passed, while a local WBT rerun was blocked by unrelated missing/rolled-back workload-test packs.
  • Custom native P/Invoke execution passed and R2RDump confirmed PINVOKE_TARGET remains for print_line and SystemNative_GetEUid.
  • Generated call-helper tables contain DllImportEntry(print_line) and DllImportEntry(SystemNative_GetEUid).

Sequencing

#133656 currently carries a narrow #if NET workaround in AdminHelpers. Whichever PR merges second should remove that workaround so the root fix is the only retained behavior change.

Resolves #133614

Note

This pull request description and change were prepared with GitHub Copilot assistance.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing
lewing force-pushed the lewing-guarded-pinvoke-follow-up branch from 5dd203d to 77ee8ca Compare September 20, 2026 00:41

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.

Copilot review overview

🟡 Changes recommended

Improve the ReadyToRun-specific relinking error message before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Relinks browser CoreCLR Wasm ReadyToRun apps so compilation and native P/Invoke helper generation use the same managed closure.

Changes:

  • Requires native relinking for browser ReadyToRun publishes.
  • Preserves explicit VFS payloads in trimmed CoreCLR tests.
  • Adds guarded P/Invoke and native-module regression coverage.

Review note: the ReadyToRun relinking failure can produce an unhelpful error message when WasmBuildNative=false is explicit (moderate, 3 votes).

File Description
src/​mono/​wasm/​Wasm.Build.Tests/​ReadyToRunTests.cs Adds ReadyToRun relinking regression coverage.
src/​mono/​wasm/​Wasm.Build.Tests/​NativeLibraryTests.cs Validates generated direct-P/Invoke arguments.
src/​mono/​wasm/​testassets/​EntryPoints/​PInvoke/​GuardedFrameworkEntryPoint.cs Adds the guarded framework P/Invoke regression entry point.
src/​mono/​browser/​build/​BrowserWasmApp.CoreCLR.targets Enables relinking for browser ReadyToRun publishes.
eng/​testing/​tests.browser.targets Preserves explicit VFS files in trimmed tests.

Comment thread src/mono/browser/build/BrowserWasmApp.CoreCLR.targets
Copilot AI review requested due to automatic review settings September 20, 2026 00:43

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.

Copilot review overview

🟡 Changes recommended

Three moderate review findings remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)

Comment thread src/mono/browser/build/BrowserWasmApp.CoreCLR.targets
Require browser CoreCLR ReadyToRun publishes to relink the native runtime so Crossgen2 and the PInvoke call-helper generator process the same managed closure. Preserve explicit test payload files under trimming, add guarded PInvoke coverage, and update ReadyToRun build tests for the implied relink.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 20, 2026 01:45
@lewing
lewing force-pushed the lewing-guarded-pinvoke-follow-up branch from 77ee8ca to b637222 Compare September 20, 2026 01:45

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.

Copilot review overview

🔵 Needs a closer look

The nested ReadyToRun opt-out path can emit a duplicate generic diagnostic and needs conditional handling.

Review effort: Lite
Findings: None

Resolved since last review (2)

@lewing
lewing requested a review from pavelsavara September 20, 2026 02:02
@lewing lewing added the arch-wasm WebAssembly architecture label Sep 20, 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.

value differs from what was baked into the runtime pack forces a relink, and an
explicit WasmBuildNative=false in that situation is an error rather than a silent
mismatch between the app's configuration and the prebuilt dotnet.native.wasm. -->
value differs from what was baked into the runtime pack forces a relink. ReadyToRun

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.

What is the cost of auto-enabling relink for ReadyToRun?

It doesn’t seem right to me to auto-enable relinking for ReadyToRun solely to accommodate tests that represent invalid user code.

@lewing lewing closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[browser][CoreCLR][R2R] Filesystem timestamp tests load kernel32.dll through guarded IsInAppContainer

3 participants