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

Android AOT crashes at runtime #55567

Closed
jonathanpeppers opened this issue Jul 13, 2021 · 4 comments · Fixed by #55602
Closed

Android AOT crashes at runtime #55567

jonathanpeppers opened this issue Jul 13, 2021 · 4 comments · Fixed by #55602
Assignees
Milestone

Comments

@jonathanpeppers
Copy link
Member

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

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Infrastructure-mono untriaged New issue has not been triaged by the area owner labels Jul 13, 2021
@ghost
Copy link

ghost commented Jul 13, 2021

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

Issue Details

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

Author: jonathanpeppers
Assignees: -
Labels:

area-Infrastructure-mono, untriaged

Milestone: -

@steveisok
Copy link
Member

@vargaz Can you take a look at this one?

@lambdageek
Copy link
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

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Jul 13, 2021
@marek-safar marek-safar added this to the 6.0.0 milestone Jul 13, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 13, 2021
vargaz added a commit to vargaz/runtime that referenced this issue Jul 14, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 14, 2021
@jonathanpeppers
Copy link
Member Author

@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>

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

Successfully merging a pull request may close this issue.

5 participants