Skip to content

Android AOT crashes at runtime #55567

Closed

Description

@jonathanpeppers

Description

Using my changes here: dotnet/android#5539

Along with a custom MonoAOTCompiler.dll: dotnet/android#5539 (comment)

I'm able to produce an Android .apk file with AOT support.

However, I hit a crash at runtime, which seems the same on an x86 emulator or arm64 device:

#00 0x001da8b8 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_aot_method_hash
/__w/1/s\src/mono/mono/mini/aot-compiler.c:10610:112
#01 0x001fa794 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
find_aot_method
/__w/1/s\src/mono/mono/mini/aot-runtime.c:4414:17
#02 0x001fb527 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_aot_get_method
/__w/1/s\src/mono/mono/mini/aot-runtime.c:4715:19
#03 0x0016d159 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_jit_compile_method_with_opt
/__w/1/s\src/mono/mono/mini/mini-runtime.c:2558:10
#04 0x0016cf7b /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_jit_compile_method
/__w/1/s\src/mono/mono/mini/mini-runtime.c:2672:9
#05 0x000922e1 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_compile_method_checked
/__w/1/s\src/mono/mono/metadata/object.c:757:8
#06 0x0006df93 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_ftnptr_to_delegate_impl
/__w/1/s\src/mono/mono/metadata/marshal.c:511:27
#07 0x0005f922 /data/app/~~e3TF6FHv0tIRDsWfRxthKg==/com.microsoft.net6.helloandroid-X5qQ8XVyBbnX10icmRYrnw==/lib/x86/libmonosgen-2.0.so (BuildId: db9e68bea0d5ea221ca34add47841cf6d134b55c)
mono_ftnptr_to_delegate
/__w/1/s\src/mono/mono/mini/../metadata/icall-def.h:137:1
#08 0x00002e3b <anonymous:dbc48000>

Configuration

This is .NET 6.0.100-preview.7.21327.2:

https://github.com/xamarin/xamarin-android/blob/064301bfd9a412895bf526455549a3d4170b8621/eng/Version.Details.xml#L3-L14

Regression?

No, AOT on Android is new, and we're trying to get it working.

Other information

Here is the full adb logcat output: aot.txt

This was using adb shell setprop debug.mono.log debug,timing,aot,assembly.

/cc @steveisok @akoeplinger

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jul 13, 2021
  2. steveisok commented on Jul 13, 2021

    @steveisok
    Member

    @vargaz Can you take a look at this one?

  3. lambdageek commented on Jul 13, 2021

    @lambdageek
    Member

    I think wrapper_info is NULL. mono_ftnptr_to_delegate_impl calls mono_marshal_get_native_func_wrapper which sets wrapper info to NULL, then it calls mono_compile_method_checked which goes through the stack in the issue and ends up in mono_aot_method_hash which says:

    	if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE && mono_marshal_get_wrapper_info (method)->subtype == WRAPPER_SUBTYPE_ICALL_WRAPPER)
    

    and that deref of subtype is a null pointer.

    I think we should be using mono_marshal_get_native_func_wrapper_aot in mono_ftnptr_to_delegate_impl. But I'm not sure why we're not. /cc @vargaz

  4. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 13, 2021
  5. added this to the 6.0.0 milestone on Jul 13, 2021
  6. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 13, 2021
  7. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 14, 2021
  8. jonathanpeppers commented on Jul 14, 2021

    @jonathanpeppers
    MemberAuthor

    @vargaz thanks AOT apps are launching now.

    I found I can use this in a project to test newer Mono runtime packs:

      <Target Name="UpdateMonoRuntimePacks" BeforeTargets="ProcessFrameworkReferences">
        <ItemGroup>
          <KnownRuntimePack 
              Update="Microsoft.NETCore.App"
              Condition=" '%(KnownRuntimePack.TargetFramework)' == 'net6.0' "
              LatestRuntimeFrameworkVersion="6.0.0-preview.7.21364.3"
          />
        </ItemGroup>
      </Target>
  9. ghost locked as resolved and limited conversation to collaborators on Aug 13, 2021
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