Skip to content

[browser][wasm] Backport #132306 (GC pin for OP_MOVE destinations in AOT code) to release/10.0 #136489

Open

Description

@doverhill

Please backport #132306 (the fix for #130592) to release/10.0. #132522 took it to 11.0 only, so the bug still ships in the current .NET 10 runtime. #132306 is locked, so I am asking here.

We hit it in production in a Blazor WebAssembly app: after we turned on AOT, RuntimeError: memory access out of bounds crashes became about 30 times more frequent. The mapped frames read an invalid reference inside a loop (Enumerable.ToArray).

The loop from #132306's regression test reproduces it on every run on .NET 10, and does not on .NET 11:

10.0 (SDK 10.0.402, runtime pack 10.0.13) 11.0 (SDK 11.0.100-rc.3.26522.148)
AOT 100/100 rounds lose a live reference 0/100
interpreter 0/100 0/100
AOT + MONO_INTERPRETER_OPTIONS=-precise 100/100
AOT + MONO_GC_PARAMS=nursery-size=64m, minor GCs from allocation instead of GC.Collect 100/100

So on .NET 10 we have no workaround except turning AOT off. Node 25, macOS arm64.

Repro (dotnet publish -c Release, copy main.mjs into bin/Release/net10.0/publish/wwwroot, node main.mjs)

Repro.csproj

<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <InvariantGlobalization>true</InvariantGlobalization>
    <RunAOTCompilation>true</RunAOTCompilation>
  </PropertyGroup>
</Project>

Program.cs

using System.Runtime.CompilerServices;

public static class Program
{
    private sealed class Box
    {
        public int Value;
        public Box Self;
        public Box(int v) { Value = v; Self = this; }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static Box Make(int v) => new Box(v);

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Touch(ref Box b) { if (b is null) throw new InvalidOperationException(); }

    // The loop from GCTests.MovedAliasOfAddressTakenLocalIsRootedAcrossGC in #132306.
    [MethodImpl(MethodImplOptions.NoInlining)]
    private static bool Run()
    {
        Box[] witness = new Box[1];
        Box cur = Make(0);
        Touch(ref cur);
        for (int i = 1; i <= 128; i++)
        {
            Box alias = cur;
            witness[0] = cur;
            cur = Make(i);
            Touch(ref cur);
            GC.Collect();
            GC.KeepAlive(new byte[64]);
            if (!ReferenceEquals(alias, witness[0]) || alias.Value != i - 1 || !ReferenceEquals(alias.Self, alias))
                return false;
            GC.KeepAlive(alias);
        }
        return true;
    }

    public static async Task<int> Main()
    {
        int failures = 0;
        for (int round = 0; round < 100; round++)
        {
            await Task.Yield(); // a shallow stack, so no stale copy pins the object
            if (!Run()) failures++;
        }
        Console.WriteLine($"{failures}/100 rounds lost a live reference");
        return failures == 0 ? 0 : 1;
    }
}

main.mjs

import { dotnet } from './_framework/dotnet.js';
const { runMain, getConfig } = await dotnet.create();
process.exitCode = await runMain(getConfig().mainAssemblyName, []);

Activity

  1. added
    area-CodeGen-coreclr
    on Oct 26, 2026
  2. added
    untriaged
    on Oct 26, 2026
  3. dotnet-policy-service commented on Oct 26, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. JulieLeeMSFT commented on Oct 27, 2026

    @JulieLeeMSFT
    Member

    @doverhill, .NET 11 will GA next month. Is it possible to upgrade to .NET 11?

  5. doverhill commented on Oct 28, 2026

    @doverhill
    Author

    @JulieLeeMSFT we have applied some mitigations to try to work around the issue in the hottest code paths while we are waiting for .NET 11. So I guess there are no plans for a .NET 10 backport?

  6. JulieLeeMSFT commented on Oct 28, 2026

    @JulieLeeMSFT
    Member

    We need a business justification to get .NET 10 servicing approval. Please let me know why you need .NET 10 or if you can wait for .NET 11.

  7. added
    arch-wasm
    on Nov 6, 2026
  8. added this to the 12.0.0 milestone on Nov 6, 2026
  9. dotnet-policy-service commented on Nov 6, 2026

    @dotnet-policy-service
    Contributor

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

  10. removed
    untriaged
    on Nov 6, 2026
  11. JulieLeeMSFT commented on Nov 6, 2026

    @JulieLeeMSFT
    Member

    @doverhill, pinging on this.

    We need a business justification to get .NET 10 servicing approval. Please let me know why you need .NET 10 or if you can wait for .NET 11.

  12. added
    needs-author-action
    on Nov 6, 2026
  13. dotnet-policy-service commented on Nov 6, 2026

    @dotnet-policy-service
    Contributor

    This issue has been marked needs-author-action and may be missing some important information.

  14. doverhill commented on Nov 7, 2026

    @doverhill
    Author

    We are preparing to move to .Net 11 instead after it has gone GA. Thank you.

  15. added
    needs-further-triage
    and removed
    needs-author-action
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmarea-CodeGen-coreclrneeds-further-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions