Skip to content

[release/11.0] Home DIM instantiating thunks on System.Object - #136148

Merged
agocke merged 1 commit into
release/11.0from
backport/pr-136128-to-release/11.0
Nov 11, 2026
Merged

agocke merged 1 commit into
release/11.0from
backport/pr-136128-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #136128 to release/11.0

/cc @MichalStrehovsky

Customer Impact

  • Customer reported
  • Found internally

#136073 - default interface method instantiating thunks need to be homed on a different type but they're conceptually instance methods on the interface. Inlining into these thunks can produce bad optimizations. In this case, RyuJIT optimized out "impossible" code path that is actually possible.

Regression

  • Yes
  • No

We have always reported these on the "wrong" type, this was triggered by more inlining.

Testing

Added targeted regression test. This requires interaction of at least two optimizations (first we need to inline, and then make a decision about this).

Risk

The risk should be low, the fix was straightforward and didn't require any adjustments with our existing DIM testing.

IMPORTANT: If this backport is for a servicing release, please verify that:

  • For .NET 8 and .NET 9: The PR target branch is release/X.0-staging, not release/X.0.
  • For .NET 10+: The PR target branch is release/X.0 (no -staging suffix).

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Fixes #136073

These need to be homed on something that is not generic so we cannot
place them on the interface itself: it causes issues around whether
these require instantiating argument (they don't) that requires lots of
special casing to back out.

This is probably the cleanest local fix. It doesn't work for the
multi-obj file mode (these now all look like they should be compiled
into CoreLib.obj). We can live with that, considering everything else.
@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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@CaffeinatedCoder

Copy link
Copy Markdown

The trap from #136073 is still in the GA release, so this backport is still needed: the minimal repro from that issue ends with SIGTRAP when published with Native AOT on .NET 11.0.0.

Environment: SDK 11.0.100, Microsoft.DotNet.ILCompiler 11.0.0, net11.0, osx-arm64, dotnet publish -c Release -r osx-arm64 with PublishAot.

Default IFormattable.ToString on the generic interface Result
AggressiveInlining, as in the repro in #136073 prints the first line, then SIGTRAP, exit 133, nothing on stderr
NoInlining prints Object, String, done, exit 0

So the NoInlining workaround still holds on 11.0.0, and it is still needed. Is there a servicing release this is planned for?

Program.cs
using System;
using System.Runtime.CompilerServices;

Console.WriteLine("runtime " + System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
Console.WriteLine(Create<object>().ToString(null, null));
Console.WriteLine(Create<string>().ToString(null, null));
Console.WriteLine("done");

[MethodImpl(MethodImplOptions.NoInlining)]
static IFormattable Create<T>() => new Receiver<T>();

interface ITarget { Type Identity(Type type); }

interface IDefault<T> : IFormattable
{
#if NOINLINE
    [MethodImpl(MethodImplOptions.NoInlining)]
#else
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
    string IFormattable.ToString(string? format, IFormatProvider? provider)
        => ((ITarget)this).Identity(typeof(T)).Name;
}

class Receiver<T> : IDefault<T>, ITarget
{
    public Type Identity(Type type) => type;
}

NOINLINE is defined with -p:NoInline=true through DefineConstants in the project file.

@agocke

agocke commented Nov 11, 2026

Copy link
Copy Markdown
Member

/ba-g failures known

@agocke
agocke merged commit 4265613 into release/11.0 Nov 11, 2026
126 of 131 checks passed
@agocke
agocke deleted the backport/pr-136128-to-release/11.0 branch November 11, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants