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

[mono] Crash when calling an interface method on a struct through a generic default interface method #58394

Closed
lambdageek opened this issue Aug 30, 2021 · 3 comments · Fixed by #58521, mono/mono#21208 or Unity-Technologies/mono#1551
Assignees
Milestone

Comments

@lambdageek
Copy link
Member

lambdageek commented Aug 30, 2021

Reported by @Jorenkv at mono/mono#21206 but also happens in .NET 6

using System;

class Program {
    static void Main() {
        (new Foo() as IFoo).NoCrash(); // Prints "Hello!" as expected
        (new Foo() as IFoo).Crash<int>(); // Crashes
    }
}

interface IFoo {
    void Crash<T>() {
        Bla();
    }

    void NoCrash() {
        Bla();
    }

    void Bla();
}

struct Foo: IFoo {
    public void Bla() {
        Console.WriteLine("Hello!");
    }
}

Expected result: prints Hello! twice

Actual result:

Hello!

=================================================================
	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:
=================================================================
	0x1040c0184 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_dump_native_crash_info
	0x1040627ae - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_handle_native_crash
	0x103fbd30b - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_sigsegv_signal_handler_debug
	0x7fff20486d7d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
	0x7fff2026af0a - /usr/lib/system/libsystem_malloc.dylib : tiny_malloc_from_free_list
	0x103fc0579 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_jit_runtime_invoke
	0x103edea48 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_runtime_invoke_checked
	0x103ee688c - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : do_exec_main_checked
	0x10401d132 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_jit_exec
	0x10402076a - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_main
	0x10409b5d3 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : monovm_execute_assembly
	0x103e144e1 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostpolicy.dylib : _Z19run_app_for_contextRK20hostpolicy_context_tiPPKc
	0x103e15401 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostpolicy.dylib : corehost_main
	0x103da1bce - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/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
	0x103da0a4b - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostfxr.dylib : _ZN10fx_muxer_t7executeENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiPPKcRK19host_startup_info_tPciPi
	0x103d9d4d8 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostfxr.dylib : hostfxr_main_startupinfo
	0x103d54795 - /Users/alklig/work/dotnet-runtime/runtime/src/mono/sample/HelloWorld/../../../../artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/HelloWorld : _Z9exe_startiPPKc
	0x103d549af - /Users/alklig/work/dotnet-runtime/runtime/src/mono/sample/HelloWorld/../../../../artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/HelloWorld : main
	0x7fff2045cf3d - /usr/lib/system/libdyld.dylib : start

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

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x107c4704b):0x107c4703b  49 8b ff 49 8b 07 49 ba e0 89 80 8a e7 7f 00 00  I..I..I.........
0x107c4704b  ff 50 88 4c 8b 3c 24 48 83 c4 08 c3 00 00 00 00  .P.L.<$H........
0x107c4705b  00 00 00 00 00 48 83 c7 10 48 b8 10 70 c4 07 01  .....H...H..p...
0x107c4706b  00 00 00 ff e0 00 00 00 00 00 00 00 00 00 00 00  ................

=================================================================
	Managed Stacktrace:
=================================================================
	  at IFoo:Crash <0x0003b>
	  at Program:RunTwo <0x00064>
	  at Program:Main <0x00042>
	  at System.Object:runtime_invoke_void <0x000a5>
=================================================================
make: *** [run] Abort trap: 6

Does not happen if Foo is a class not a struct

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Aug 30, 2021
@lambdageek lambdageek self-assigned this Aug 30, 2021
@ghost
Copy link

ghost commented Aug 30, 2021

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

Issue Details

Reported by @Jorenkv at mono/mono#21206 but also happens in .NET 6

using System;

class Program {
    static void Main() {
        (new Foo() as IFoo).NoCrash(); // Prints "Hello!" as expected
        (new Foo() as IFoo).Crash<int>(); // Crashes
    }
}

interface IFoo {
    void Crash<T>() {
        Bla();
    }

    void NoCrash() {
        Bla();
    }

    void Bla();
}

struct Foo: IFoo {
    public void Bla() {
        Console.WriteLine("Hello!");
    }
}

Expected result: prints Hello! twice

Actual result:

Hello!

=================================================================
	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:
=================================================================
	0x1040c0184 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_dump_native_crash_info
	0x1040627ae - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_handle_native_crash
	0x103fbd30b - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_sigsegv_signal_handler_debug
	0x7fff20486d7d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
	0x7fff2026af0a - /usr/lib/system/libsystem_malloc.dylib : tiny_malloc_from_free_list
	0x103fc0579 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_jit_runtime_invoke
	0x103edea48 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_runtime_invoke_checked
	0x103ee688c - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : do_exec_main_checked
	0x10401d132 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_jit_exec
	0x10402076a - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : mono_main
	0x10409b5d3 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libcoreclr.dylib : monovm_execute_assembly
	0x103e144e1 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostpolicy.dylib : _Z19run_app_for_contextRK20hostpolicy_context_tiPPKc
	0x103e15401 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostpolicy.dylib : corehost_main
	0x103da1bce - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/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
	0x103da0a4b - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostfxr.dylib : _ZN10fx_muxer_t7executeENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiPPKcRK19host_startup_info_tPciPi
	0x103d9d4d8 - /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/libhostfxr.dylib : hostfxr_main_startupinfo
	0x103d54795 - /Users/alklig/work/dotnet-runtime/runtime/src/mono/sample/HelloWorld/../../../../artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/HelloWorld : _Z9exe_startiPPKc
	0x103d549af - /Users/alklig/work/dotnet-runtime/runtime/src/mono/sample/HelloWorld/../../../../artifacts/bin/HelloWorld/x64/Release/osx-x64/publish/HelloWorld : main
	0x7fff2045cf3d - /usr/lib/system/libdyld.dylib : start

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

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x107c4704b):0x107c4703b  49 8b ff 49 8b 07 49 ba e0 89 80 8a e7 7f 00 00  I..I..I.........
0x107c4704b  ff 50 88 4c 8b 3c 24 48 83 c4 08 c3 00 00 00 00  .P.L.<$H........
0x107c4705b  00 00 00 00 00 48 83 c7 10 48 b8 10 70 c4 07 01  .....H...H..p...
0x107c4706b  00 00 00 ff e0 00 00 00 00 00 00 00 00 00 00 00  ................

=================================================================
	Managed Stacktrace:
=================================================================
	  at IFoo:Crash <0x0003b>
	  at Program:RunTwo <0x00064>
	  at Program:Main <0x00042>
	  at System.Object:runtime_invoke_void <0x000a5>
=================================================================
make: *** [run] Abort trap: 6
Author: lambdageek
Assignees: -
Labels:

untriaged, area-VM-meta-mono

Milestone: -

@lambdageek
Copy link
Member Author

It's not a vtable layout issue probably . Both class and struct Foo have:

*** Vtable for class 'Foo' at "FINALLY" (size 7)
  [O][000][INDEX 000] object:GetHashCode () [0x7fc49e84daf8]
  [O][001][INDEX 001] object:Equals (object) [0x7fc49e84dad0]
  [O][002][INDEX 002] object:ToString () [0x7fc49e84daa8]
  [O][003][INDEX 003] object:Finalize () [0x7fc49e84da80]
  [I][004][INDEX 000] IFoo:Crash<T> () [0x7fc488819560]
  [I][005][INDEX 001] IFoo:NoCrash () [0x7fc4888195f0]
  [I][006][INDEX 006] Foo:Bla () [0x7fc488819640]

It's a JIT issue: MONO_ENV_OPTIONS=--interp also works and prints Hello! Hello!

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 1, 2021
lambdageek added a commit to lambdageek/runtime that referenced this issue Sep 1, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet#58394
github-actions bot pushed a commit that referenced this issue Sep 2, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes #58394
monojenkins pushed a commit to monojenkins/mono that referenced this issue Sep 2, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394
github-actions bot pushed a commit to mono/mono that referenced this issue Sep 2, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394
lambdageek added a commit that referenced this issue Sep 3, 2021
* [mini] Don't add unbox tramopline on generic DIM calls

Don't unbox a valuetype `this` if the generic method is a DIM

Fixes #58394

* Add regression test
lambdageek added a commit to mono/mono that referenced this issue Sep 3, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394

Co-authored-by: lambdageek <[email protected]>
lambdageek added a commit to mono/mono that referenced this issue Sep 3, 2021
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394

Fixes #21206

Co-authored-by: lambdageek <[email protected]>
Anipik pushed a commit that referenced this issue Sep 7, 2021
…58585)

* [mini] Don't add unbox tramopline on generic DIM calls

Don't unbox a valuetype `this` if the generic method is a DIM

Fixes #58394

* Add regression test

Co-authored-by: Aleksey Kliger <[email protected]>
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 7, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Oct 7, 2021
bholmes added a commit to Unity-Technologies/mono that referenced this issue Feb 3, 2022
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394

Co-authored-by: lambdageek <[email protected]>
schoudhary-rythmos pushed a commit to Unity-Technologies/mono that referenced this issue Mar 4, 2022
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394

Co-authored-by: lambdageek <[email protected]>
schoudhary-rythmos pushed a commit to Unity-Technologies/mono that referenced this issue Mar 4, 2022
Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet/runtime#58394

Co-authored-by: lambdageek <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.