Skip to content

crossgen2 --partial omits managed JIT helpers from CoreLib R2R image on no-JIT targets #138187

Description

@lewing

Description

Under profile-guided partial compilation (--partial), browser CoreCLR ReadyToRun composites leave out every managed JIT helper that the profile doesn't list. That breaks the rule @jkotas set out in #136050 (comment):

  • R2R code outside CoreLib can be used only when CoreLib is R2R too
  • CoreLib R2R image must contain code for all JIT helpers

Since #134356, browser publishes pass --partial whenever PublishReadyToRunPgoFiles is non-empty, which includes the default StandardOptimizationData.mibc. When the restriction is set, ReadyToRunSingleAssemblyCompilationModuleGroup.ContainsMethodBodyCore rejects every method missing from the profile. On no-JIT targets the only exemption is HardwareIntrinsicHelpers.IsHardwareIntrinsic. As a result, the helpers rooted by ReadyToRunJitHelperRootProvider are dropped.

In a default CI-style publish of System.Runtime.Intrinsics.Tests (browser-wasm CoreCLR, Release, TestWasmReadyToRun=true, aggressive trimming, default MIBC + --partial), crossgen2's --map output shows the composite compiles 1,229 CoreLib methods but none of the 70 managed JIT helpers. Among them:

  • CastHelpers.*
  • SpanHelpers.Memmove / Fill / ClearWithoutReferences
  • the StaticsHelpers statics-base helpers
  • RuntimeTypeHandle.GetRuntimeTypeFromHandle
  • InitHelpers.*
  • Math division and overflow helpers

Memmove and ClearWithoutReferences are even called through DelayLoad_MethodCall imports.

R2R code reaches these through helper cells. The runtime resolves them to the helper's interpreter PortableEntryPoint, which works only if some loaded image happens to supply an R2R-to-interpreter thunk for that signature. When none does, _pActualCode stays null and the call traps.

Reproduction Steps

  1. Build the browser baseline: ./build.sh -arch wasm -os browser -s clr+libs+host+packs -c Release.
  2. Use dotnet-pgo create-mibc-from-method-list to build a profile containing only System.Runtime.Intrinsics.Wasm.Tests.PackedSimdTests.PackedSimdIsSupported.
  3. Publish and run that test with /p:UseMibcProjectReference=false and /p:PublishReadyToRunCrossgen2ExtraArgs=--partial;--mibc:<that file>, using the same browser R2R settings as above.

Expected behavior

CoreLib's R2R image contains code for every managed JIT helper, whatever the profile says, and the test runs.

Actual behavior

The test fails with RuntimeError: null function at the first call_indirect in PackedSimdIsSupported. That call goes through the eager READYTORUN_HELPER_GetRuntimeTypeHandle cell for typeof(PackedSimd). At the trap, the helper's PortableEntryPoint has:

  • _pActualCode = 0
  • _pInterpreterData set
  • kPrefersInterpreterEntryPoint set

The image has no WasmR2RToInterpreterThunk(iTip), and the method stays on the runtime's pending-thunk list. Adding System.RuntimeTypeHandle.GetRuntimeTypeFromHandle to the profile makes the test pass.

The default profile doesn't hit this today, but only because the thunks it needs happen to be generated for other call sites.

Regression?

Yes, starting with #134356 (profile-guided partial ReadyToRun for browser CoreCLR). Before that change browser publishes didn't use --partial, so the profile restriction was never set and the rooted helpers were compiled.

Known Workarounds

Disable PGO (/p:EnableNgenOptimization=false), or list the needed helpers in the profile.

Configuration

browser-wasm, CoreCLR, Release, composite ReadyToRun with --partial. The same filter applies to any no-JIT target using partial compilation.

Other information

Suggested fix: on targets that can't JIT, exempt the managed JIT helper methods (those from ReadyToRunJitHelperRootProvider) from the partial-profile restriction in ContainsMethodBodyCore, the same way hardware intrinsics are exempt today. The fix should also confirm BubbleIncludesCoreModule holds for these composites, since the helper root provider is only added then.

Generating helper-signature R2R-to-interpreter thunks in crossgen2 instead was considered and dropped in #136050 in favor of the rule above.

Related: #138182 / #138183 add a similar partial-profile exemption for the Vector*.IsHardwareAccelerated getters.

Note

This issue was drafted with GitHub Copilot.

Activity

  1. added
    arch-wasm
    area-crossgen2-coreclr
    on Nov 24, 2026
  2. added
    untriaged
    on Nov 24, 2026
  3. dotnet-policy-service commented on Nov 24, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  4. added this to the 12.0.0 milestone on Nov 24, 2026
  5. removed
    untriaged
    on Nov 24, 2026
  6. self-assigned this
    on Nov 24, 2026
  7. added a commit that references this issue on Nov 24, 2026
    161248c
  8. added and removed
    area-crossgen2-coreclr
    on Nov 24, 2026
  9. dotnet-policy-service commented on Nov 24, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/crossgen-contrib
    See info in area-owners.md if you want to be subscribed.

  10. moved this from In Progress to Done in AppModelon Nov 24, 2026
  11. added a commit that references this issue on Nov 24, 2026
    70a7d51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-ReadyToRun

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions