Skip to content

[clr-interp] Stackoverflow on x64 #121631

Closed

Description

@rolfbjarne

Description

This happens in our test suite:

Stack overflow.
Repeated 7349 times:
--------------------------------
   at System.Runtime.InteropServices.DynamicInterfaceCastableHelpers.GetInterfaceImplementation(System.Runtime.InteropServices.IDynamicInterfaceCastable, System.RuntimeType)
--------------------------------
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Collections.Generic.IEnumerable`1<System.ValueTuple`3<System.Runtime.Versioning.OSPlatformAttribute,Xamarin.Utils.ApplePlatform,System.Version>>, Xamarin.Tests.PlatformInfo, Xamarin.Utils.ApplePlatform)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Collections.Generic.IEnumerable`1<System.Runtime.Versioning.OSPlatformAttribute>, Xamarin.Tests.PlatformInfo)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Reflection.ICustomAttributeProvider, Xamarin.Tests.PlatformInfo)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailableOnHostPlatform(System.Reflection.ICustomAttributeProvider)
   at Introspection.ApiBaseTest.SkipDueToAttribute(System.Reflection.MemberInfo)
   at Introspection.ApiCMAttachmentTest.Skip(System.Type)
[...]

Reproduction Steps

Needs Xcode 26.1.1 installed in /Applications/Xcode_26.1.1.app.

$ git clone --recursive https://github.com/dotnet/macios
$ cd macios
$ git checkout dev/rolf/net11.0-coreclr
$ git reset --hard 0129a5d735b6ff4947c354e7ffa6233c6fa4a2c9
$ ./configure --disable-all-platforms --enable-maccatalyst
$ make all -j8
$ make install -j8
$ make build run-bare TEST_VARIATION=coreclr RID=maccatalyst-x64 -C tests/introspection/dotnet/MacCatalyst

Expected behavior

Successful test execution.

Actual behavior

Stack overflow.
Details
$ make build run-bare TEST_VARIATION=coreclr RID=maccatalyst-x64
Found ccache on the system, enabling it
Detected the macios-adr repository, automatically enabled the Xamarin build
2025-11-14 16:16:43.642 introspection[86919:4310425] Microsoft.MacCatalyst: Invalid IDE Port: -1
2025-11-14 16:16:47.496 introspection[86919:4309880] Queuing test loading on background thread
2025-11-14 16:16:47.503 introspection[86919:4310554] Loading tests on background thread
2025-11-14 16:16:47.580 introspection[86919:4310554] Loaded tests on background thread, queuing UI update on main thead
2025-11-14 16:16:47.907 introspection[86919:4309880] Updating UI on main thead
2025-11-14 16:16:48.089 introspection[86919:4309880] AutoRun ()
2025-11-14 16:16:48.089 introspection[86919:4309880] AutoRun (): queuing test run on main thread
2025-11-14 16:16:48.095 introspection[86919:4309880] AutoRun (): running tests on main thread
2025-11-14 16:16:48.129 introspection[86919:4309880] [Runner executing:	Run Everything]
2025-11-14 16:16:48.129 introspection[86919:4309880] [MonoTouch Version:	26.0.11017]
2025-11-14 16:16:48.130 introspection[86919:4309880] [Assembly:	Microsoft.MacCatalyst.dll (64 bits)]
2025-11-14 16:16:48.130 introspection[86919:4309880] [GC:	sgen]
2025-11-14 16:16:48.130 introspection[86919:4309880] [iPad:	iPadOS v18.7]
2025-11-14 16:16:48.130 introspection[86919:4309880] [Device Name:	iPad]
2025-11-14 16:16:48.131 introspection[86919:4309880] [Device UDID:	unknown]
2025-11-14 16:16:48.158 introspection[86919:4309880] [Device Locale:	en_US@rg=eszzzz]
2025-11-14 16:16:48.160 introspection[86919:4309880] [Device Date/Time:	11/14/2025 4:16:48 PM]
2025-11-14 16:16:48.161 introspection[86919:4309880] [Bundle:	com.xamarin.introspection]
2025-11-14 16:16:48.171 introspection[86919:4310580] introspection
2025-11-14 16:16:48.175 introspection[86919:4310580] Introspection
2025-11-14 16:16:48.175 introspection[86919:4310580] Introspection.ApiCMAttachmentTest
2025-11-14 16:16:48.298 introspection[86919:4310580] 	[PASS] CheckAttachments
Stack overflow.
Repeated 59038 times:
--------------------------------
   at System.Runtime.InteropServices.DynamicInterfaceCastableHelpers.GetInterfaceImplementation(System.Runtime.InteropServices.IDynamicInterfaceCastable, System.RuntimeType)
--------------------------------
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Collections.Generic.IEnumerable`1<System.ValueTuple`3<System.Runtime.Versioning.OSPlatformAttribute,Xamarin.Utils.ApplePlatform,System.Version>>, Xamarin.Tests.PlatformInfo, Xamarin.Utils.ApplePlatform)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Collections.Generic.IEnumerable`1<System.Runtime.Versioning.OSPlatformAttribute>, Xamarin.Tests.PlatformInfo)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailable(System.Reflection.ICustomAttributeProvider, Xamarin.Tests.PlatformInfo)
   at Xamarin.Tests.AvailabilityExtensions.IsAvailableOnHostPlatform(System.Reflection.ICustomAttributeProvider)
   at Introspection.ApiBaseTest.SkipDueToAttribute(System.Reflection.MemberInfo)
   at Introspection.ApiCMAttachmentTest.Skip(System.Type)
   at Introspection.ApiCMAttachmentTest.CheckFailAttachments()
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, Void**, System.Signature, Boolean)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(System.Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(System.Object, System.Reflection.BindingFlags)
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
   at NUnit.Framework.Internal.Reflect.InvokeMethod(System.Reflection.MethodInfo, System.Object, System.Object[])
   at NUnit.Framework.Internal.MethodWrapper.Invoke(System.Object, System.Object[])
   at NUnit.Framework.Internal.Commands.TestMethodCommand.InvokeTestMethod(NUnit.Framework.Internal.TestExecutionContext)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(NUnit.Framework.Internal.TestExecutionContext)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(NUnit.Framework.Internal.TestExecutionContext)
   at NUnit.Framework.Internal.Execution.SimpleWorkItem.PerformWork()
   at NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread()
   at NUnit.Framework.Internal.Execution.WorkItem.Execute()
   at NUnit.Framework.Internal.Execution.MainThreadWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem)
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren()
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork()
   at NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread()
   at NUnit.Framework.Internal.Execution.WorkItem.Execute()
   at NUnit.Framework.Internal.Execution.MainThreadWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem)
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren()
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork()
   at NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread()
   at NUnit.Framework.Internal.Execution.WorkItem.Execute()
   at NUnit.Framework.Internal.Execution.MainThreadWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem)
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren()
   at NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork()
   at NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread()
   at NUnit.Framework.Internal.Execution.WorkItem.Execute()
   at NUnit.Framework.Internal.Execution.MainThreadWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem)
   at NUnit.Framework.Internal.Execution.MainThreadWorkItemDispatcher.Start(NUnit.Framework.Internal.Execution.WorkItem)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.StartRun(NUnit.Framework.Interfaces.ITestListener)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner+<>c__DisplayClass38_0.<RunAsync>b__0()
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.WrapInNUnitCallContext(System.Action)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.RunAsync(NUnit.Framework.Interfaces.ITestListener, NUnit.Framework.Interfaces.ITestFilter)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.Run(NUnit.Framework.Interfaces.ITestListener, NUnit.Framework.Interfaces.ITestFilter)
   at MonoTouch.NUnit.UI.BaseTouchRunner.Run(NUnit.Framework.Internal.Test)
   at MonoTouch.NUnit.UI.BaseTouchRunner.Run()
   at MonoTouch.NUnit.UI.BaseTouchRunner.<AutoRun>b__49_0()
   at MonoTouch.NUnit.UI.TouchRunner+<>c__DisplayClass19_0.<ExecuteOnMainThread>b__0()
   at Foundation.NSAsyncActionDispatcher.Apply()
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, Void**, System.Signature, Boolean)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(System.Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(System.Object, System.Reflection.BindingFlags)
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at ObjCRuntime.Runtime.InvokeMethod(System.Reflection.MethodBase, System.Object, IntPtr)
   at ObjCRuntime.Runtime.InvokeMethod(MonoObject*, MonoObject*, IntPtr)
   at ObjCRuntime.Runtime.bridge_runtime_invoke_method(MonoObject*, MonoObject*, IntPtr, IntPtr*)
   at UIKit.UIApplication.UIApplicationMain(Int32, System.String[], IntPtr, IntPtr)
   at UIKit.UIApplication.Main(System.String[], System.Type, System.Type)
   at MainClass.Main(System.String[])
make: *** [run-bare] Abort trap: 6

Regression?

No

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Nov 14, 2025
  2. added
    needs-area-label
    on Nov 14, 2025
  3. added and removed
    needs-area-label
    on Nov 14, 2025
  4. dotnet-policy-service commented on Nov 14, 2025

    @dotnet-policy-service
    Contributor

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

  5. rolfbjarne commented on Nov 14, 2025

    @rolfbjarne
    MemberAuthor

    I'm not sure if this is the same bug or not, but our other test suite also crashes, with something that looks like stack overflows: https://gist.github.com/rolfbjarne/fc397ffd355ecfc7f6c89fa48a4e9924

    Repro is the same, except the last line, which is:

    $ make build run-bare TEST_VARIATION=coreclr RID=maccatalyst-x64 -C tests/monotouch-test/dotnet/MacCatalyst
    Output
    Details
    
    2025-11-15 00:12:44.664 monotouchtest[35211:5314588] Microsoft.MacCatalyst: Invalid IDE Port: -1
    2025-11-15 00:12:51.846 monotouchtest[35211:5313856] ObjCRuntime.RuntimeException: Detected a protocol (MonoTouchFixtures.JavascriptCore.IMyJavaExporter) inheriting from the JSExport protocol while using the dynamic registrar. It is not possible to export protocols to JavaScriptCore dynamically; the static registrar must be used (add '--registrar:static' to the additional mtouch arguments in the project's iOS Build options to select the static registrar).
    2025-11-15 00:13:29.110 monotouchtest[35211:5313856] Queuing test loading on background thread
    2025-11-15 00:13:29.115 monotouchtest[35211:5315974] Loading tests on background thread
    2025-11-15 00:13:33.182 monotouchtest[35211:5315974] Loaded tests on background thread, queuing UI update on main thead
    2025-11-15 00:13:33.183 monotouchtest[35211:5313856] Updating UI on main thead
    2025-11-15 00:13:34.070 monotouchtest[35211:5313856] AutoRun ()
    2025-11-15 00:13:34.070 monotouchtest[35211:5313856] AutoRun (): queuing test run on main thread
    2025-11-15 00:13:34.076 monotouchtest[35211:5313856] AutoRun (): running tests on main thread
    2025-11-15 00:13:34.077 monotouchtest[35211:5313856] [Runner executing:	Run Everything]
    2025-11-15 00:13:34.077 monotouchtest[35211:5313856] [MonoTouch Version:	26.0.11017]
    2025-11-15 00:13:34.078 monotouchtest[35211:5313856] [Assembly:	Microsoft.MacCatalyst.dll (64 bits)]
    2025-11-15 00:13:34.078 monotouchtest[35211:5313856] [GC:	sgen]
    2025-11-15 00:13:34.078 monotouchtest[35211:5313856] [iPad:	iPadOS v18.7]
    2025-11-15 00:13:34.078 monotouchtest[35211:5313856] [Device Name:	iPad]
    2025-11-15 00:13:34.078 monotouchtest[35211:5313856] [Device UDID:	unknown]
    2025-11-15 00:13:34.094 monotouchtest[35211:5313856] [Device Locale:	en_US@rg=eszzzz]
    2025-11-15 00:13:34.096 monotouchtest[35211:5313856] [Device Date/Time:	11/15/2025 12:13:34 AM]
    2025-11-15 00:13:34.096 monotouchtest[35211:5313856] [Bundle:	com.xamarin.monotouch-test]
    2025-11-15 00:13:59.719 monotouchtest[35211:5317127] monotouchtest
    2025-11-15 00:13:59.722 monotouchtest[35211:5317127] LoaderTest
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] LoaderTest : 0.2857 ms
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] MonoTests
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] MonoTests.System
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] MonoTests.System.Net
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] MonoTests.System.Net.Http
    2025-11-15 00:13:59.723 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest
    2025-11-15 00:13:59.725 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.AcceptSslCertificatesServicePointManager
    2025-11-15 00:14:04.211 monotouchtest[35211:5317127] 	[PASS] AcceptSslCertificatesServicePointManager(System.Net.Http.HttpClientHandler)
    2025-11-15 00:14:06.950 monotouchtest[35211:5317127] 	[PASS] AcceptSslCertificatesServicePointManager(System.Net.Http.NSUrlSessionHandler)
    2025-11-15 00:14:06.953 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.AcceptSslCertificatesServicePointManager : 7228.0127 ms
    2025-11-15 00:14:06.954 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.AcceptSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler
    2025-11-15 00:14:06.958 monotouchtest[35211:5317127] 	[IGNORED] AcceptSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler("https://self-signed.badssl.com/") : OneTimeSetUp: https://github.com/dotnet/macios/issues/21912
    2025-11-15 00:14:06.958 monotouchtest[35211:5317127] 	[IGNORED] AcceptSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler("https://wrong.host.badssl.com/") : OneTimeSetUp: https://github.com/dotnet/macios/issues/21912
    2025-11-15 00:14:06.958 monotouchtest[35211:5317127] 	[SKIPREASON] https://github.com/dotnet/macios/issues/21912
    2025-11-15 00:14:06.959 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.AcceptSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler : 4.6304 ms
    2025-11-15 00:14:06.960 monotouchtest[35211:5317127] 	[PASS] AssertDefaultValuesNSUrlSessionHandler
    2025-11-15 00:14:06.960 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.DnsFailure
    2025-11-15 00:14:07.170 monotouchtest[35211:5317127] 	[PASS] DnsFailure(System.Net.Http.HttpClientHandler)
    2025-11-15 00:14:07.288 monotouchtest[35211:5317127] 	[PASS] DnsFailure(System.Net.Http.CFNetworkHandler)
    2025-11-15 00:14:07.395 monotouchtest[35211:5317127] 	[PASS] DnsFailure(System.Net.Http.SocketsHttpHandler)
    2025-11-15 00:14:07.500 monotouchtest[35211:5317127] 	[PASS] DnsFailure(System.Net.Http.NSUrlSessionHandler)
    2025-11-15 00:14:07.500 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.DnsFailure : 540.0092 ms
    2025-11-15 00:14:07.501 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue16339
    2025-11-15 00:14:08.249 monotouchtest[35211:5317127] 	[PASS] GHIssue16339()
    2025-11-15 00:14:08.250 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue16339 : 748.8319 ms
    2025-11-15 00:14:08.250 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue8342
    2025-11-15 00:14:09.168 monotouchtest[35211:5317127] 	[PASS] GHIssue8342(OK,"mandel","12345678","mandel","12345678")
    2025-11-15 00:14:10.287 monotouchtest[35211:5317127] 	[PASS] GHIssue8342(Unauthorized,"mandel","12345678","mandel","87654321")
    2025-11-15 00:14:12.929 monotouchtest[35211:5317127] 	[PASS] GHIssue8342(Unauthorized,"mandel","12345678","","")
    2025-11-15 00:14:12.930 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue8342 : 4680.0683 ms
    2025-11-15 00:14:12.931 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue8344
    2025-11-15 00:14:18.619 monotouchtest[35211:5317127] 	[PASS] GHIssue8344()
    2025-11-15 00:14:18.620 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.GHIssue8344 : 5689.525 ms
    2025-11-15 00:14:18.621 monotouchtest[35211:5317127] MonoTests.System.Net.Http.MessageHandlerTest.RedirectionWithAuthorizationHeaders
    make: *** [run-bare] Segmentation fault: 11
    
  6. added this to the 11.0.0 milestone on Nov 17, 2025
  7. removed
    untriaged
    on Nov 17, 2025
  8. BrzVlad commented on Nov 17, 2025

    @BrzVlad
    Member
  9. self-assigned this
    on Nov 18, 2025
  10. kotlarmilos commented on Nov 19, 2025

    @kotlarmilos
    Member

    This issue looks like an infinite recursion in interface resolution when casting an object that implements IDynamicInterfaceCastable to IDisposable. It begins in GetInterfaceImplementation, which triggers interface lookup, re-enters the interpreter, and attempts to resolve the same interface method again.

    frame #0: 0x000000010a2296a5 libcoreclr.dylib`InterpExecMethod(InterpreterFrame*, InterpMethodContextFrame*, InterpThreadContext*, ExceptionClauseArgs*) + 773
    frame #1: 0x000000010a190655 libcoreclr.dylib`ExecuteInterpretedMethod + 341
    frame #2: 0x000000010a35b87f libcoreclr.dylib`InterpreterStubRetI8 + 15
    frame #3: 0x000000010a35b82d libcoreclr.dylib`InterpreterStub + 253
    frame #4: 0x000000010a35cc7c libcoreclr.dylib`CallDescrWorkerInternal + 124
    frame #5: 0x000000010a1dca5a libcoreclr.dylib`DispatchCallSimple(unsigned long*, unsigned int, unsigned long, unsigned int) + 186
    frame #6: 0x000000010a207148 libcoreclr.dylib`DynamicInterfaceCastable::GetInterfaceImplementation(Object**, TypeHandle const&) + 136
    frame #7: 0x000000010a16ed49 libcoreclr.dylib`MethodTable::GetMethodDescForInterfaceMethodAndServer(TypeHandle, MethodDesc*, Object**) + 233
    frame #8: 0x000000010a2296a5 libcoreclr.dylib`InterpExecMethod(InterpreterFrame*, InterpMethodContextFrame*, InterpThreadContext*, ExceptionClauseArgs*) + 773
    

    The first argument to GetInterfaceImplementation (rdi) was the object at 0x000000018a50d5e0, with its MethodTable at 0x000000018a50cf70. This is the class implementing IDynamicInterfaceCastable. The second argument (rsi) was a TypeHandle with value 0x000000010ac579b8, which is the MethodTable for IDisposable. The MethodDesc being resolved uses slot 0x0001, which matches Dispose().

    The MethodDesc captured from the interpreter frame encodes the same IDisposable MethodTable in its header and shows slot 0x0001. This shows that the interpreter is trying to resolve IDisposable.Dispose() on the same object. When interpreter enters the managed GetInterfaceImplementation, that method causes another lookup for the same interface and method on the same instance, which re-enters the interpreter at the same point.

  11. kotlarmilos commented on Nov 20, 2025

    @kotlarmilos
    Member

    I’m hitting the following assert in the debug configuration. I suspect it’s the same root cause as in the release configuration since it is failing around the same test. I think it is coming from open virtual delegates where it takes wrong stack slot and ends up passing a wrong MethodTable into GetMethodDescOfVirtualizedCode.

    ASSERT FAILED
       Expression: SanityCheck()
       Location:   line 8792 in /Users/miloskotlar/dotnet/runtime-copy/src/coreclr/vm/methodtable.cpp
       Function:   Validate
       Process:    77231
    
    (lldb) bt
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
      * frame #0: 0x000000010c2339e1 libcoreclr.dylib`DBG_DebugBreak + 1
       frame #1: 0x000000010c1c39df libcoreclr.dylib`DebugBreak + 271
       frame #2: 0x000000010bd1f54c libcoreclr.dylib`MethodTable::Validate() + 124
       frame #3: 0x000000010bd288fd libcoreclr.dylib`Object::ValidateInner(int, int, int) + 189
       frame #4: 0x000000010bd27bb9 libcoreclr.dylib`Object::Validate(int, int, int) + 201
       frame #5: 0x000000010bd27993 libcoreclr.dylib`OBJECTREF::operator->() + 51
       frame #6: 0x000000010bceee05 libcoreclr.dylib`MethodDesc::GetMethodDescOfVirtualizedCode(OBJECTREF*, TypeHandle) + 37
       frame #7: 0x000000010bee4fad libcoreclr.dylib`InterpExecMethod(InterpreterFrame*, InterpMethodContextFrame*, InterpThreadContext*, ExceptionClauseArgs*)::$_1::operator()() const + 77
    

    If I skip this assert, it later fails with:

    ASSERT FAILED
       Expression: !CREATE_CHECK_STRING(pMT && pMT->Validate())
       Location:   line 548 in /Users/miloskotlar/dotnet/runtime-copy/src/coreclr/vm/object.cpp
       Function:   ValidateInner
       Process:    77231
    
  12. kotlarmilos commented on Nov 21, 2025

    @kotlarmilos
    Member

    The interpreter hits a MethodTable::SanityCheck assert in debug because the MethodTable for the this argument in a virtual call is corrupted when MethodDescOfVirtualizedCode executes. The failure occurs at the point where the method table is fetched:

    MethodDesc* MethodDesc::GetMethodDescOfVirtualizedCode(OBJECTREF *orThis, TypeHandle staticTH)
    {
        ...
        // Method table of target (might be instantiated)
        MethodTable *pObjMT = (*orThis)->GetMethodTable(); <- assert here
        ...
    
        if (pStaticMD->IsInterface())
        {
            RETURN(MethodTable::GetMethodDescForInterfaceMethodAndServer(staticTH, pStaticMD, orThis));
        }
    
        RETURN(pObjMT->GetMethodDescForSlot(pStaticMD->GetSlot()));
    }
    

    In release, the same issue appears later inside GetMethodDescForInterfaceMethodAndServer, which is expected since both paths depend on the same invalid this pointer.

    The corrupted object has an invalid component size, indicating that the pointer being treated as an object is not a valid MethodTable:

    DEBUG: MethodTable SanityCheck FAILED - ComponentSize=2032, IsArray=0
    DEBUG: MethodTable details - HasComponentSize=-2147483648, RawComponentSize=2032
    ASSERT FAILED (componentSize <= 2) || isArray
    

    The last logged virtual call shows that the this argument is in the arg slot at offset 240:

    INTOP_CALLVIRT at bytecode offset 212 (callArgsOffset=240, methodSlot=4)
    

    Tracing that slot leads to Xamarin.Tests.AvailabilityExtensions:IsAvailable(): https://gist.github.com/kotlarmilos/63857d07d9390ead5732e7a7921f7dc5

    The same slot is reused several times for different locals and virtual call arguments. I expanded initlocals to zero reused slots and added GCPROTECT around GetMethodDescOfVirtualizedCode, but the error still exists. This indicates that the pointer is already invalid before callvirt runs and is not caused by GC movement.

    At this point my reasoning is that the interpreter writes a non-object value into the arg slot, either by emitting incorrect object reference for a virtual call or by pushing a value-type or stale value that is interpreted as an object pointer in the virtcall path.

  13. kotlarmilos commented on Nov 24, 2025

    @kotlarmilos
    Member

    I managed to run the code on macOS x64 under rosetta. The issue appears when two consecutive INTOP_CALLVIRT execute with the same callArgsOffset (112) and returnOffset (64). In the first virtcall the this argument points to a valid System.Linq.Enumerable+ArraySelectIterator'2[[System.ValueTuple'3 instance. After the first call, INTOP_RET_VT performs a memmove that overwrites the memory slot that previously held the valid this pointer:

    * thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
      * frame #0: 0x00007ff818cff1c5 libsystem_platform.dylib`_platform_memmove$VARIANT$Rosetta + 485
        frame #1: 0x0000000109ded9fe libcoreclr.dylib`ExecuteInterpretedMethod(pTransitionBlock=0x00000003041748a8, byteCodeAddr=4609160560, retBuff=0x0000000189830978) at prestub.cpp:2052:5
        frame #2: 0x000000010a24ca24 libcoreclr.dylib`InterpreterStubRetBuff at asmhelpers.S:585
        frame #3: 0x000000010a24c90d libcoreclr.dylib`InterpreterStub at asmhelpers.S:484
        frame #4: 0x000000010a24da4c libcoreclr.dylib`CallJittedMethodRetBuff at asmhelpers.S:1745
        frame #5: 0x0000000109f8e81d libcoreclr.dylib`InvokeCalliStub(ftn=4295595640, cookie=0x0000000113080168, pArgs=0x00007fc270018070, pRet=0x00007fc270018040) at interpexec.cpp:324:5
        frame #6: 0x0000000109f96f0b libcoreclr.dylib`InterpExecMethod(pInterpreterFrame=0x00000003041769b8, pFrame=0x0000000304176988, pThreadContext=0x00007fc26c1072c0, pExceptionClauseArgs=0x0000000000000000) at interpexec.cpp:2513:25
        frame #7: 0x0000000109ded9fe libcoreclr.dylib`ExecuteInterpretedMethod(pTransitionBlock=0x0000000304176ae8, byteCodeAddr=4608906528, retBuff=0x0000000000000000) at prestub.cpp:2052:5
    

    Then the second CALLVIRT takes an invalid pointer as its this argument. This reproduces only when the iterator returns a value-type tuple on x64.

  14. locked and limited conversation to collaborators on Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions