Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net8.0-ios] App crashes on ios device when calling static abstract generic interface method #90732

Closed
vyacheslav-volkov opened this issue Aug 17, 2023 · 10 comments
Assignees
Milestone

Comments

@vyacheslav-volkov
Copy link

vyacheslav-volkov commented Aug 17, 2023

Description

App crashes on ios device with <UseInterpreter>false</UseInterpreter> flag when calling static abstract generic interface method.

Reproduction Steps

  1. Create a new net8.0-ios project
  2. Add code:
public interface ITypeChecker
{
    static abstract bool Test<T>();
}

public interface IHandler
{
    bool Test<T>();
}

public class TypeChecker : ITypeChecker
{
    public static bool Test<T>() => true;
}

public class Handler<TChecker> : IHandler where TChecker : ITypeChecker
{
    public bool Test<T>() => TChecker.Test<T>();
}

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
    public override UIWindow? Window { get; set; }

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        var handler = GetHandler();
        handler.Test<int>();
        return true;
    }

    public IHandler GetHandler() => new Handler<TypeChecker>();
}

Expected behavior

No crashes

Actual behavior

Native crash:

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Native stacktrace:
=================================================================
	0x102c967a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c81990 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c64364 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1f05fd2f4 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x102c6ace0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102717d80 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102640240 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x1028cfeac - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c14874 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c17594 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd5488 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd51cc - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1a8a8f2d0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8ea28 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8da5c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8d6bc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a87f6884 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIScenePerformActionsWithLifecycleActionMask
	0x1a8b0c858 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89cea70 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce8a0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce470 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a904d430 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a90e10ac - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
	0x1a888cdc8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8cc0fe0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89533c8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a895325c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89527cc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8952570 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1bb2ae3e4 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e88ec - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2b1e38 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e8590 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1ad56f780 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1ad5472d0 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1bb2bb34c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2baf88 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2bd53c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1a688d154 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6898dc8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6824044 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a68391b8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a683dda0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
	0x1ddb3b998 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
	0x1a8ad2fd8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8ad2c50 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
	0x102a28bf8 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_UIApplicationMain
	0x10275de30 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102a0bb14 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c13a84 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c199a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c6c808 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102a33a24 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_log
	0x102cd4834 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1c3f93344 - /usr/lib/dyld : <redacted>

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x102c6ace0):0x102c6acd0  e8 42 40 79 28 0d 10 37 e0 03 17 aa 4a 7b fd 97  .B@y(..7....J{..
0x102c6ace0  68 02 40 f9 88 14 00 b4 19 00 1b 12 08 01 40 f9  h.@...........@.
0x102c6acf0  17 01 40 f9 00 0b 40 f9 60 0c 00 b4 08 3c 40 39  ..@...@.`....<@9
0x102c6ad00  a8 0c 00 37 e0 03 17 aa d4 81 fd 97 e8 6e 40 f9  ...7.........n@.

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at System.Object:__icall_wrapper_(null) <0x00007>
	  at TestCrash.Handler`1:Test <0x0007f>
	  at TestCrash.AppDelegate:FinishedLaunching <0x00047>
	  at System.Object:runtime_invoke_dynamic <0x00127>
	  at <unknown> <0xffffffff>
	  at UIKit.UIApplication:xamarin_UIApplicationMain <0x00007>
	  at UIKit.UIApplication:UIApplicationMain <0x000cf>
	  at UIKit.UIApplication:Main <0x00107>
	  at Program:<Main>$ <0x0003f>
	  at System.Object:runtime_invoke_dynamic <0x00127>
=================================================================

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

An error has occurred in the native fault reporting. Some diagnostic information will be unavailable.

=================================================================
	Native stacktrace:
=================================================================
	0x102c967a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c81990 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c64364 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1f05fd2f4 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x102c6ace0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102717d80 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102640240 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x1028cfeac - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c14874 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c17594 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd5488 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd51cc - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1a8a8f2d0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8ea28 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8da5c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8d6bc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a87f6884 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIScenePerformActionsWithLifecycleActionMask
	0x1a8b0c858 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89cea70 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce8a0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce470 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a904d430 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a90e10ac - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
	0x1a888cdc8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8cc0fe0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89533c8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a895325c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89527cc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8952570 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1bb2ae3e4 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e88ec - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2b1e38 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e8590 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1ad56f780 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1ad5472d0 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1bb2bb34c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2baf88 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2bd53c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1a688d154 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6898dc8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6824044 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a68391b8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a683dda0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
	0x1ddb3b998 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
	0x1a8ad2fd8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8ad2c50 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
	0x102a28bf8 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_UIApplicationMain
	0x10275de30 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102a0bb14 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c13a84 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c199a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c6c808 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102a33a24 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_log
	0x102cd4834 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1c3f93344 - /usr/lib/dyld : <redacted>

Exiting early due to double fault.

Regression?

No response

Known Workarounds

No response

Configuration

NET 8.0 Preview 7

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 17, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 17, 2023
@kotlarmilos kotlarmilos added area-Codegen-AOT-mono and removed untriaged New issue has not been triaged by the area owner needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 17, 2023
@kotlarmilos
Copy link
Member

I managed to reproduce the issue locally using Mono AOT LLVM configuration.

Test case:

using System;

namespace HelloWorld
{
    public interface ITypeChecker
    {
        static abstract bool Test<T>();
    }

    public interface IHandler
    {
        bool Test<T>();
    }

    public class TypeChecker : ITypeChecker
    {
        public static bool Test<T>() => true;
    }

    public class Handler<TChecker> : IHandler where TChecker : ITypeChecker
    {
        public bool Test<T>() => TChecker.Test<T>();
    }

    internal class Program
    {

        private static void Main(string[] args)
        {
            var handler = GetHandler();
            bool test = handler.Test<int>();
            Console.WriteLine(test);
        }

        public static IHandler GetHandler() => new Handler<TypeChecker>();
    }
}

Stack trace:

* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = signal SIGSEGV
  * frame #0: 0x000000010038f8c0 mono-sgen`constrained_gsharedvt_call_setup(mp=0x0000000000000000, cmethod=0x00000001034094c0, klass=0x000000010600f968, this_arg=0x000000016fdfe390, error=0x000000016fdfe3b0) at jit-icalls.c:1367:14
    frame #1: 0x000000010038f604 mono-sgen`mono_gsharedvt_constrained_call(mp=0x0000000000000000, cmethod=0x00000001034094c0, klass=0x000000010600f968, info=0x0000000103409540, deref_args=0x0000000000000000, args=0x0000000000000000) at jit-icalls.c:1464:7
    frame #2: 0x0000000104a681c0 System.Private.CoreLib.dll.dylib`wrapper_managed_to_native_object___icall_wrapper_mono_gsharedvt_constrained_call_intptr_intptr_intptr_intptr_intptr_intptr + 160
    frame #3: 0x00000001008d37c0 HelloWorld.dll.dylib`HelloWorld_Handler_1_TChecker_GSHAREDVT_Test_T_GSHAREDVT(this=0x0000000102001fa8) at Program.cs:25
    frame #4: 0x00000001008d367c HelloWorld.dll.dylib`HelloWorld_Program_Main_string__(param0=<unavailable>) at Program.cs:34
    frame #5: 0x0000000104a623e8 System.Private.CoreLib.dll.dylib`wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 296
    frame #6: 0x00000001002f77a4 mono-sgen`mono_jit_runtime_invoke(method=0x0000000100f0aca0, obj=0x0000000000000000, params=0x000000016fdfe960, exc=0x000000016fdfe7e0, error=0x000000016fdfea38) at mini-runtime.c:3636:3
    frame #7: 0x0000000100250310 mono-sgen`do_runtime_invoke(method=0x0000000100f0aca0, obj=0x0000000000000000, params=0x000000016fdfe960, exc=0x0000000000000000, error=0x000000016fdfea38) at object.c:2542:11
    frame #8: 0x000000010024a0b8 mono-sgen`mono_runtime_invoke_checked(method=0x0000000100f0aca0, obj=0x0000000000000000, params=0x000000016fdfe960, error=0x000000016fdfea38) at object.c:2758:9
    frame #9: 0x0000000100255a0c mono-sgen`do_exec_main_checked(method=0x0000000100f0aca0, args=0x0000000102001f18, error=0x000000016fdfea38) at object.c:4644:3
    frame #10: 0x0000000100253fa0 mono-sgen`mono_runtime_exec_main_checked(method=0x0000000100f0aca0, args=0x0000000102001f18, error=0x000000016fdfea38) at object.c:4741:9
    frame #11: 0x0000000100253ff4 mono-sgen`mono_runtime_run_main_checked(method=0x0000000100f0aca0, argc=1, argv=0x0000000100a06660, error=0x000000016fdfea38) at object.c:4305:9
    frame #12: 0x00000001003af3d4 mono-sgen`mono_jit_exec_internal(domain=0x0000000100a08040, assembly=0x0000000100f0b4d0, argc=1, argv=0x0000000100a06660) at driver.c:1369:13
    frame #13: 0x00000001003af1e8 mono-sgen`mono_jit_exec(domain=0x0000000100a08040, assembly=0x0000000100f0b4d0, argc=1, argv=0x0000000100a06660) at driver.c:1314:7
    frame #14: 0x00000001003b3e98 mono-sgen`main_thread_handler(user_data=0x000000016fdfee30) at driver.c:1444:2
    frame #15: 0x00000001003b2570 mono-sgen`mono_main(argc=3, argv=0x0000000100a06650) at driver.c:2668:3
    frame #16: 0x00000001000be528 mono-sgen`mono_main_with_options(argc=3, argv=0x0000000100a06650) at main.c:36:9
    frame #17: 0x00000001000be4e8 mono-sgen`main(argc=2, argv=0x000000016fdff158) at main.c:88:9
    frame #18: 0x000000018d69bf28 dyld`start + 2236

@kotlarmilos
Copy link
Member

@vargaz If cmethod is a static virtual method, the receiver's type is null. In such case, if klass is used instead of the receiver's type, the test case works. I am not sure if the constrained_gsharedvt_call_setup should be called for static virtual methods, or if the handling for such methods is missing.

/cc: @lambdageek

@kotlarmilos kotlarmilos self-assigned this Aug 18, 2023
@kotlarmilos kotlarmilos added the os-ios Apple iOS label Aug 18, 2023
@ghost
Copy link

ghost commented Aug 18, 2023

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

App crashes on ios device with <UseInterpreter>false</UseInterpreter> flag when calling static abstract generic interface method.

Reproduction Steps

  1. Create a new net8.0-ios project
  2. Add code:
public interface ITypeChecker
{
    static abstract bool Test<T>();
}

public interface IHandler
{
    bool Test<T>();
}

public class TypeChecker : ITypeChecker
{
    public static bool Test<T>() => true;
}

public class Handler<TChecker> : IHandler where TChecker : ITypeChecker
{
    public bool Test<T>() => TChecker.Test<T>();
}

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
    public override UIWindow? Window { get; set; }

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        var handler = GetHandler();
        handler.Test<int>();
        return true;
    }

    public IHandler GetHandler() => new Handler<TypeChecker>();
}

Expected behavior

No crashes

Actual behavior

Native crash:

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Native stacktrace:
=================================================================
	0x102c967a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c81990 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c64364 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1f05fd2f4 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x102c6ace0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102717d80 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102640240 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x1028cfeac - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c14874 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c17594 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd5488 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd51cc - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1a8a8f2d0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8ea28 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8da5c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8d6bc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a87f6884 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIScenePerformActionsWithLifecycleActionMask
	0x1a8b0c858 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89cea70 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce8a0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce470 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a904d430 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a90e10ac - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
	0x1a888cdc8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8cc0fe0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89533c8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a895325c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89527cc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8952570 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1bb2ae3e4 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e88ec - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2b1e38 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e8590 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1ad56f780 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1ad5472d0 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1bb2bb34c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2baf88 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2bd53c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1a688d154 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6898dc8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6824044 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a68391b8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a683dda0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
	0x1ddb3b998 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
	0x1a8ad2fd8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8ad2c50 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
	0x102a28bf8 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_UIApplicationMain
	0x10275de30 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102a0bb14 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c13a84 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c199a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c6c808 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102a33a24 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_log
	0x102cd4834 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1c3f93344 - /usr/lib/dyld : <redacted>

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x102c6ace0):0x102c6acd0  e8 42 40 79 28 0d 10 37 e0 03 17 aa 4a 7b fd 97  .B@y(..7....J{..
0x102c6ace0  68 02 40 f9 88 14 00 b4 19 00 1b 12 08 01 40 f9  h.@...........@.
0x102c6acf0  17 01 40 f9 00 0b 40 f9 60 0c 00 b4 08 3c 40 39  ..@...@.`....<@9
0x102c6ad00  a8 0c 00 37 e0 03 17 aa d4 81 fd 97 e8 6e 40 f9  ...7.........n@.

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at System.Object:__icall_wrapper_(null) <0x00007>
	  at TestCrash.Handler`1:Test <0x0007f>
	  at TestCrash.AppDelegate:FinishedLaunching <0x00047>
	  at System.Object:runtime_invoke_dynamic <0x00127>
	  at <unknown> <0xffffffff>
	  at UIKit.UIApplication:xamarin_UIApplicationMain <0x00007>
	  at UIKit.UIApplication:UIApplicationMain <0x000cf>
	  at UIKit.UIApplication:Main <0x00107>
	  at Program:<Main>$ <0x0003f>
	  at System.Object:runtime_invoke_dynamic <0x00127>
=================================================================

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

An error has occurred in the native fault reporting. Some diagnostic information will be unavailable.

=================================================================
	Native stacktrace:
=================================================================
	0x102c967a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c81990 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c64364 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1f05fd2f4 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x102c6ace0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102717d80 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102640240 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x1028cfeac - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c14874 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c17594 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd5488 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102cd51cc - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1a8a8f2d0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8ea28 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8da5c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8a8d6bc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a87f6884 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIScenePerformActionsWithLifecycleActionMask
	0x1a8b0c858 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89cea70 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce8a0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce470 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89ce350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a904d430 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a90e10ac - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
	0x1a888cdc8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8cc0fe0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89533c8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a895325c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a89527cc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8952570 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1bb2ae3e4 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e88ec - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2b1e38 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2e8590 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1ad56f780 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1ad5472d0 - /usr/lib/system/libdispatch.dylib : <redacted>
	0x1bb2bb34c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2baf88 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1bb2bd53c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : <redacted>
	0x1a688d154 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6898dc8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a6824044 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a68391b8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
	0x1a683dda0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
	0x1ddb3b998 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
	0x1a8ad2fd8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
	0x1a8ad2c50 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
	0x102a28bf8 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_UIApplicationMain
	0x10275de30 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102a0bb14 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : 
	0x102c675a0 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c13a84 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c199a4 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102c6c808 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x102a33a24 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : xamarin_log
	0x102cd4834 - /private/var/containers/Bundle/Application/17646053-8E61-4B41-BA88-71BCCBDB1947/TestCrash.app/TestCrash : SystemNative_GetDefaultTimeZone
	0x1c3f93344 - /usr/lib/dyld : <redacted>

Exiting early due to double fault.

Regression?

No response

Known Workarounds

No response

Configuration

NET 8.0 Preview 7

Other information

No response

Author: vyacheslav-volkov
Assignees: kotlarmilos
Labels:

area-Codegen-AOT-mono, os-ios

Milestone: -

@SamMonoRT
Copy link
Member

/cc @BrzVlad

@SamMonoRT SamMonoRT added this to the 8.0.0 milestone Aug 18, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 21, 2023
@kotlarmilos
Copy link
Member

kotlarmilos commented Aug 21, 2023

After further investigation, it seems that the constrained_gsharedvt_call_setup shouldn't be called if cmethod is a static virtual method. In the AOT compiler, static virtual methods are handled normally.

Assumption is that during the runtime, the call cannot be made through constrained_gsharedvt_call_setup, and the type should be retrieved from vtable of a class.

@vargaz @lambdageek Please let me know if I am on the right track :)

I've opened a draft PR to test the CI.

UPDATE: The mono_gsharedvt_constrained_call JIT icall should handle static virtual methods by using null for the this argument.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 23, 2023
@kotlarmilos
Copy link
Member

kotlarmilos commented Aug 24, 2023

The fix has been merged. We should verify if it resolves the customer issue. Additionally, a runtime test should be added if this scenario is not already covered by full AOT llvm job on the CI.

@SamMonoRT
Copy link
Member

This is fixed via #90875 and also in release\8.0 via #91059 - Closing the issue as Fixed.

@vyacheslav-volkov
Copy link
Author

Hi everyone!
Was this fix included in RC1 for iOS because I'm still getting this error on RC1?

@kotlarmilos
Copy link
Member

The issue has been merged into main after the RC1 snap and backported to .NET 8 branch (not RC1). At some point, it will flow into RC2 and GA.

@SamMonoRT Please fill in with details if I missed something.

@kotlarmilos
Copy link
Member

You can either wait for RC2 or switch to Preview 7. I will check if we can backport it to the RC1 as well.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants