Skip to content

[Mono] Calling a virtual static method on an interface in Debug mode causes a crash #90139

Closed

Description

@simonrozsival

A Mono program crashes when a static virtual method is called on an interface but only in the Debug configuration.
The same program works correctly with CoreCLR or with Mono in the Release configuration. I observed this while working on xamarin-macios (see dotnet/macios#18519 (comment)).

Reproduction steps

To reproduce the issue, put the following code to the HelloWorld sample code in src/mono/sample/HelloWorld/Program.cs:

using System;

Console.WriteLine(CallMyMethod<MyClass>());
Console.WriteLine(CallMyMethod<IMyInterface>());

string CallMyMethod<T>() where T : IMyInterface
    => T.MyMethod();

interface IMyInterface {
    static virtual string MyMethod() => nameof(IMyInterface);
}

class MyClass : IMyInterface {
    public static string MyMethod() => nameof(MyClass);
}

Run the program via make -C src/mono/sample/HelloWorld run.

Instead of printing both lines, program crashes:

MyClass
* Assertion at /.../dotnet/runtime/src/mono/mono/mini/mini-generic-sharing.c:2289, condition `m_class_get_vtable (info->klass)' not met


=================================================================
        Native Crash Reporting
=================================================================
Got a SIGABRT 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:
=================================================================
        0x103c1e854 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : dump_native_stacktrace
        0x103c1e7ac - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_dump_native_crash_info
        0x103b73f70 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_handle_native_crash
        0x103c1dedc - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : sigabrt_signal_handler
        0x18627aa24 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x18624bc28 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
        0x186159ae8 - /usr/lib/system/libsystem_c.dylib : abort
        0x103d296b8 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : monoeg_assert_abort
        0x103d44148 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_log_write_logfile
        0x103d407f0 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : structured_log_adapter
        0x103d29dbc - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : monoeg_g_logstr
        0x103d299f8 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : monoeg_g_logv_nofree
        0x103d29ae8 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : monoeg_assertion_message
        0x103d29b64 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_assertion_message_unreachable
        0x103b8426c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : instantiate_info
        0x103b83b3c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mini_instantiate_gshared_info
        0x103af93e4 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mini_init_method_rgctx
        0x1038ef748 - Unknown
        0x102f8f880 - Unknown
        0x102f8fc78 - Unknown
        0x103a607d4 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_jit_runtime_invoke
        0x103e23dc4 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : do_runtime_invoke
        0x103e1db6c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_runtime_invoke_checked
        0x103e29464 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : do_exec_main_checked
        0x103e27a54 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_runtime_exec_main_checked
        0x103e27aa8 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_runtime_run_main_checked
        0x103b18128 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_jit_exec_internal
        0x103b17f3c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_jit_exec
        0x103b1cb18 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : main_thread_handler
        0x103b1b1d0 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : mono_main
        0x103be51d0 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : monovm_execute_assembly
        0x103a4878c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libcoreclr.dylib : coreclr_execute_assembly
        0x1032815cc - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostpolicy.dylib : _ZN9coreclr_t16execute_assemblyEiPPKcS1_Pj
        0x1032c79d4 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostpolicy.dylib : _Z19run_app_for_contextRK20hostpolicy_context_tiPPKc
        0x1032c7c58 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostpolicy.dylib : _Z7run_appiPPKc
        0x1032c87ec - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostpolicy.dylib : corehost_main
        0x102feb0fc - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostfxr.dylib : _ZL11execute_appRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEP15corehost_init_tiPPKc
        0x102fe3110 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostfxr.dylib : _ZN12_GLOBAL__N_123read_config_and_executeERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERK19host_startup_info_tS8_RKNS0_13unordered_mapI13known_optionsNS0_6vectorIS6_NS4_IS6_EEEE18known_options_hashNS0_8equal_toISD_EENS4_INS0_4pairIKS
        0x102fe0240 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostfxr.dylib : _ZN10fx_muxer_t24handle_exec_host_commandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERK19host_startup_info_tS8_RKNS0_13unordered_mapI13known_optionsNS0_6vectorIS6_NS4_IS6_EEEE18known_options_hashNS0_8equal_toISD_EENS4_INS0_4pairIKSD
        0x102fdf714 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostfxr.dylib : _ZN10fx_muxer_t7executeENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiPPKcRK19host_startup_info_tPciPi
        0x102fd7250 - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/libhostfxr.dylib : hostfxr_main_startupinfo
        0x102de881c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/HelloWorld : _Z9exe_startiPPKc
        0x102de8c0c - /.../dotnet/runtime/artifacts/bin/HelloWorld/arm64/Debug/osx-arm64/publish/HelloWorld : main
        0x185ef3f28 - /usr/lib/dyld : start

=================================================================
        External Debugger Dump:
=================================================================

=================================================================
        Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x186214764):0x186214754  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x186214764  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......
0x186214774  65 e0 ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  e........{...._.
0x186214784  c0 03 5f d6 70 0a 80 d2 01 10 00 d4 03 01 00 54  .._.p..........T

=================================================================
        Managed Stacktrace:
=================================================================
=================================================================
make: *** [run] Abort trap: 6

Activity

  1. ghost added
    untriaged
    on Aug 8, 2023
  2. self-assigned this
    on Aug 8, 2023
  3. added this to the 8.0.0 milestone on Aug 8, 2023
  4. ghost removed
    untriaged
    on Aug 8, 2023
  5. BrzVlad commented on Aug 14, 2023

    @BrzVlad
    Member

    Not blocking release. Will investigate and backport if necessary

  6. modified the milestones: 8.0.0, 9.0.0 on Aug 14, 2023
  7. ghost added
    in-pr
    on Sep 6, 2023
  8. ghost removed
    in-pr
    on Sep 7, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Oct 7, 2023
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