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.Android] fix crash on startup with EnableLLVM #7188

Merged
merged 1 commit into from
Aug 3, 2022

Conversation

jonathanpeppers
Copy link
Member

dotnet new android apps would crash on startup when built with
-c Release -p:EnableLLVM=true:

07-20 08:55:44.642  2983  2983 F monodroid-assembly: Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.
...
07-20 08:55:44.834  3004  3004 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
07-20 08:55:44.834  3004  3004 F DEBUG   : Abort message: 'Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.'

java_interop_jvm_list should never be called on Android, it is the
result of new AndroidRuntime() having not been called yet?

The problem being that the static Android.App.Application.cctor was
somehow running before JNIEnv.Initialize() was complete? And this
only happens with LLVM?

Reviewing the code:

[UnmanagedCallersOnly]
internal static unsafe void Initialize (JnienvInitializeArgs* args)
{
    //...
    SynchronizationContext.SetSynchronizationContext (Android.App.Application.SynchronizationContext);
}

We do indeed access Android.App.Application...

To fix this, we can move this to a new method decorated with
MethodImplOptions.NoInlining. Apps built with LLVM now launch for
me.

We can also enable the LLVM Mono.Android-Tests again.

@jonathanpeppers
Copy link
Member Author

A dotnet new android app was working, but the Mono.Android-Tests crash with:

07-20 22:20:20.502  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Runtime.dll.so" has no DT_SONAME (will use libaot-System.Runtime.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
--------- beginning of crash
07-20 22:20:20.807  4955  4955 F libc    : Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7ffc0d1b0ff8 in tid 4955 (droid.NET_Tests), pid 4955 (droid.NET_Tests)
07-20 22:20:20.861  4976  4976 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
07-20 22:20:20.862  1656  1656 I /system/bin/tombstoned: received crash request for pid 4955
07-20 22:20:20.862  4976  4976 I crash_dump64: performing dump of process 4955 (target tid = 4955)
07-20 22:20:20.866  4976  4976 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-20 22:20:20.866  4976  4976 F DEBUG   : Build fingerprint: 'Android/sdk_phone_x86_64/generic_x86_64:10/QPP6.190730.005.B1/5775370:userdebug/test-keys'
07-20 22:20:20.866  4976  4976 F DEBUG   : Revision: '0'
07-20 22:20:20.866  4976  4976 F DEBUG   : ABI: 'x86_64'
07-20 22:20:20.867  4976  4976 F DEBUG   : Timestamp: 2022-07-20 22:20:20+0000
07-20 22:20:20.867  4976  4976 F DEBUG   : pid: 4955, tid: 4955, name: droid.NET_Tests  >>> Mono.Android.NET_Tests <<<
07-20 22:20:20.867  4976  4976 F DEBUG   : uid: 10108
07-20 22:20:20.867  4976  4976 F DEBUG   : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7ffc0d1b0ff8
07-20 22:20:20.867  4976  4976 F DEBUG   :     rax 0000000000000000  rbx 00007640d6493700  rcx 00007ffc0d1b1038  rdx 00007ffc0d1b1040
07-20 22:20:20.867  4976  4976 F DEBUG   :     r8  00007ffc0d1b10b0  r9  0000763ffb9e5520  r10 0000763ff89262e0  r11 0000763ffba3a640
07-20 22:20:20.867  4976  4976 F DEBUG   :     r12 00007640d64f5d80  r13 0000763ff9c046b0  r14 0000763ffb9e5520  r15 0000000000000000
07-20 22:20:20.867  4976  4976 F DEBUG   :     rdi 00007640d64810d0  rsi 00007ffc0d1b1068
07-20 22:20:20.867  4976  4976 F DEBUG   :     rbp 00007ffc0d1b10b0  rsp 00007ffc0d1b1000  rip 0000763ffb9c7d99
07-20 22:20:21.022  4976  4976 F DEBUG   : 
07-20 22:20:21.022  4976  4976 F DEBUG   : backtrace:
07-20 22:20:21.022  4976  4976 F DEBUG   :       #00 pc 0000000000133d99  /data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
07-20 22:20:21.022  4976  4976 F DEBUG   :       #01 pc 0000000000133d72  /data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
07-20 22:20:21.022  4976  4976 F DEBUG   :       #02 pc 00000000001513cb  /data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
07-20 22:20:21.022  4976  4976 F DEBUG   :       #03 pc 0000000000108733  /data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
07-20 22:20:21.022  4976  4976 F DEBUG   :       #04 pc 0000000000019ec5  <anonymous:62d25000>

@jonpryor
Copy link
Member

Looking at the logcat output, and the output is "interesting". PID 4955 is the relevant process; only PID 4955 output:

07-20 22:20:20.020  4955  4955 W main    : type=1400 audit(0.0:433): avc: granted { read } for name="u:object_r:net_dns_prop:s0" dev="tmpfs" ino=6642 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:net_dns_prop:s0 tclass=file app=Mono.Android.NET_Tests
07-20 22:20:20.046  1537  1537 D Zygote  : Forked child process 4955
07-20 22:20:20.051  4955  4955 W droid.NET_Test: Unexpected CPU variant for X86 using defaults: x86_64
07-20 22:20:20.057  1799  2773 I ActivityManager: Start proc 4955:Mono.Android.NET_Tests/u0a108 for added application Mono.Android.NET_Tests
07-20 22:20:20.075  4955  4955 I droid.NET_Test: The ClassLoaderContext is a special shared library.
07-20 22:20:20.079  4955  4955 W droid.NET_Test: JIT profile information will not be recorded: profile file does not exits.
07-20 22:20:20.079  4955  4955 W droid.NET_Test: JIT profile information will not be recorded: profile file does not exits.
07-20 22:20:20.087  4955  4955 I DOTNET  : JNI_OnLoad: JNI_OnLoad in pal_jni.c
07-20 22:20:20.162  4955  4955 I monodroid-timing: [0/4] XATiming: init time; elapsed: 0:73::379000
07-20 22:20:20.163  4955  4955 W monodroid: Creating public update directory: `/data/user/0/Mono.Android.NET_Tests/files/.__override__`
07-20 22:20:20.164  4955  4955 I monodroid-timing: [0/7] Runtime.init: Mono runtime init; elapsed: 0:0::180000
07-20 22:20:20.164  4955  4955 I monodroid-timing: [0/9] Register runtimeconfig binary blob; elapsed: 0:0::42000
07-20 22:20:20.169  4955  4955 I monodroid-timing: [0/0] LZ4 decompression time for <assembly_store>; elapsed: 0:1::128000
07-20 22:20:20.170  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Private.CoreLib.dll.so" has no DT_SONAME (will use libaot-System.Private.CoreLib.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.264  4955  4955 I monodroid-timing: [0/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::268000
07-20 22:20:20.265  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-Mono.Android.NET-Tests.dll.so" has no DT_SONAME (will use libaot-Mono.Android.NET-Tests.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.265  4955  4955 I monodroid-timing: [0/1] Assembly load (ALC): Mono.Android.NET-Tests.dll; elapsed: 0:1::343000
07-20 22:20:20.265  4955  4955 I monodroid-timing: [0/2] Finished preloading, number of loaded assemblies: 1; elapsed: 0:1::486000
07-20 22:20:20.265  4955  4955 W monodroid-gc: GREF GC Threshold: 46080
07-20 22:20:20.265  4955  4955 I monodroid-timing: [0/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::268000
07-20 22:20:20.266  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-Mono.Android.dll.so" has no DT_SONAME (will use libaot-Mono.Android.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.266  4955  4955 I monodroid-timing: [0/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::114000
07-20 22:20:20.267  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-Java.Interop.dll.so" has no DT_SONAME (will use libaot-Java.Interop.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.415  4955  4955 I monodroid-timing: [0/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::403000
07-20 22:20:20.415  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Net.Http.dll.so" has no DT_SONAME (will use libaot-System.Net.Http.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.492  4955  4955 I monodroid-timing: [0/8] Runtime.init: end native-to-managed transition; elapsed: 0:220::4000
07-20 22:20:20.493  4955  4955 I monodroid-timing: [0/11] Runtime.init: end, total time; elapsed: 0:330::171000
07-20 22:20:20.501  4955  4955 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::54000
07-20 22:20:20.501  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-TestRunner.Core.NET.dll.so" has no DT_SONAME (will use libaot-TestRunner.Core.NET.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.501  4955  4955 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::52000
07-20 22:20:20.502  4955  4955 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-U-WZ4hrGmp_9zjUMvMLinQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Runtime.dll.so" has no DT_SONAME (will use libaot-System.Runtime.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
07-20 22:20:20.807  4955  4955 F libc    : Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7ffc0d1b0ff8 in tid 4955 (droid.NET_Tests), pid 4955 (droid.NET_Tests)
07-20 22:20:20.862  1656  1656 I /system/bin/tombstoned: received crash request for pid 4955
07-20 22:20:20.862  4976  4976 I crash_dump64: performing dump of process 4955 (target tid = 4955)
07-20 22:20:20.867  4976  4976 F DEBUG   : pid: 4955, tid: 4955, name: droid.NET_Tests  >>> Mono.Android.NET_Tests <<<
07-20 22:20:21.255  1537  1537 I Zygote  : Process 4955 exited due to signal 11 (Segmentation fault)
07-20 22:20:21.255  1799  1875 I ActivityManager: Process Mono.Android.NET_Tests (pid 4955) has died: fore FGS 
07-20 22:20:21.256  1799  1826 I libprocessgroup: Successfully killed process cgroup uid 10108 pid 4955 in 0ms

What looks particularly "interesting" is:

Unexpected CPU variant for X86 using defaults: x86_64

I don't know where this message is coming from; I don't see it in xamarin-android or in dotnet/runtime.

@jonpryor
Copy link
Member

@jonathanpeppers: are you able to repro this crash locally? It would be good to get a crash with an un-strip'd libmonosgen-2.0.so, so that we know where the crash is coming from. It does seem "odd" that the same offset is present for all stack frames, though; perhaps the backtrace stack is corrupt?

@jonathanpeppers
Copy link
Member Author

Android must print this on the x86_64 emulator, seems like all processes?

image

The symbolicated crash I'm getting is:

********** Crash dump: **********
Build fingerprint: 'google/sdk_gphone_x86_64_arm64/generic_x86_64_arm64:11/RSR1.210722.013/7800151:userdebug/dev-keys'
#00 0x0000000000133db1 /data/app/~~Tv_klgaiXLjyreZr_N4TOw==/Mono.Android.NET_Tests-M4-L5DzcyDE_T9ZZN17tfA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
                                                                                                                                                        mono_conc_g_hash_table_lookup_extended
                                                                                                                                                        /__w/1/s\src/mono/mono/metadata/mono-conc-hash.c:232:19
#01 0x0000000000133d72 /data/app/~~Tv_klgaiXLjyreZr_N4TOw==/Mono.Android.NET_Tests-M4-L5DzcyDE_T9ZZN17tfA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
                                                                                                                                                        mono_conc_g_hash_table_lookup
                                                                                                                                                        /__w/1/s\src/mono/mono/metadata/mono-conc-hash.c:220:6
#02 0x00000000001513cb /data/app/~~Tv_klgaiXLjyreZr_N4TOw==/Mono.Android.NET_Tests-M4-L5DzcyDE_T9ZZN17tfA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
                                                                                                                                                        check_object_handle
                                                                                                                                                        /__w/1/s\src/mono/mono/mini/../../mono/metadata/reflection-cache.h:104:15
                                                                                                                                                        check_or_construct_handle
                                                                                                                                                        /__w/1/s\src/mono/mono/mini/../../mono/metadata/reflection-cache.h:116:25
#03 0x0000000000108733 /data/app/~~Tv_klgaiXLjyreZr_N4TOw==/Mono.Android.NET_Tests-M4-L5DzcyDE_T9ZZN17tfA==/split_config.x86_64.apk!libmonosgen-2.0.so (offset 0x646000) (BuildId: ca213f04656ee08ed2774ca712125f022263bf61)
                                                                                                                                                        ves_icall_RuntimeTypeHandle_GetAssembly
                                                                                                                                                        /__w/1/s\src/mono/mono/metadata/icall.c:2834:13
                                                                                                                                                        ves_icall_RuntimeTypeHandle_GetAssembly_raw
                                                                                                                                                        /__w/1/s\src/mono/mono/mini/../metadata/icall-def.h:502:1
#04 0x0000000000009eb5 <anonymous:40c7b000>
Crash dump is completed

`dotnet new android` apps would crash on startup when built with
`-c Release -p:EnableLLVM=true`:

    07-20 08:55:44.642  2983  2983 F monodroid-assembly: Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.
    ...
    07-20 08:55:44.834  3004  3004 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
    07-20 08:55:44.834  3004  3004 F DEBUG   : Abort message: 'Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.'

`java_interop_jvm_list` should *never* be called on Android, it is the
result of `new AndroidRuntime()` having not been called yet?

The problem being that the static `Android.App.Application.cctor` was
somehow running *before* `JNIEnv.Initialize()` was complete? And this
only happens with LLVM?

Reviewing the code:

    [UnmanagedCallersOnly]
    internal static unsafe void Initialize (JnienvInitializeArgs* args)
    {
        //...
        SynchronizationContext.SetSynchronizationContext (Android.App.Application.SynchronizationContext);
    }

We do indeed access `Android.App.Application`...

To fix this, we can move this to a new method decorated with
`MethodImplOptions.NoInlining`. Apps built with LLVM now launch for
me.

We can also enable the LLVM `Mono.Android-Tests` again.
Comment on lines -694 to 697
# TODO: disable LLVM test, see: https://github.com/dotnet/runtime/issues/68914
# TODO: disable LLVM test, see:
# https://github.com/dotnet/runtime/issues/68914
# https://github.com/dotnet/runtime/issues/73304
condition: false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept these disabled because of: dotnet/runtime#73304

I think we should merge this with the tests disabled, because it does get things further.

<ExcludeCategories Condition=" '$(RunAOTCompilation)' == 'true' ">$(ExcludeCategories):InetAccess</ExcludeCategories>
<ExcludeCategories Condition=" '$(EnableLLVM)' == 'true' ">$(ExcludeCategories):InetAccess</ExcludeCategories>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 0084162, this Condition wasn't actually doing anything. We weren't passing in RunAOTCompilation=true because that is the default value for Release builds.

InetAccess seems to crash the tests when EnableLLVM=true, however... So let's keep the condition for that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also open an issue for the InetAccess test crashes with LLVM enabled?

@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 3, 2022 15:33
@jonathanpeppers
Copy link
Member Author

The designer tests should be getting fixed by: #7227

And going to ignore these, unrelated:

image

Going to merge, with a decent commit message shortly.

@jonathanpeppers jonathanpeppers merged commit b6c22f3 into dotnet:main Aug 3, 2022
@jonathanpeppers jonathanpeppers deleted the EnableLLVM branch August 3, 2022 18:56
condition: false
configuration: $(XA.Build.Configuration)
testName: Mono.Android.NET_Tests-AotLlvm
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)AotLlvm.xml
extraBuildArgs: -p:TestsFlavor=AotLlvm -p:EnableLlvm=true
extraBuildArgs: -p:TestsFlavor=AotLlvm -p:EnableLLVM=true -p:AndroidEnableProfiledAot=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to disable profiled AOT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was: dotnet/runtime#73003

Using Profiled AOT and LLVM at the same time can hit:

[ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Arg_PlatformNotSupported
at System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte_Intrinsified(Byte* , UIntPtr )
at System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte(Byte* , Int32 , Int32& , Int32& )
at System.Text.UTF8Encoding.GetCharCount(Byte* , Int32 )
at System.String.CreateStringFromEncoding(Byte* , Int32 , Encoding )
at System.Text.Encoding.GetString(Byte* , Int32 )
at System.String.CreateStringForSByteConstructor(Byte* , Int32 )
at System.String.Ctor(SByte* value)
at Java.Interop.TypeManager.GetClassName(IntPtr )
at Android.Runtime.JNIEnv.RegisterJniNatives(IntPtr , Int32 , IntPtr , IntPtr , Int32 )

<ExcludeCategories Condition=" '$(RunAOTCompilation)' == 'true' ">$(ExcludeCategories):InetAccess</ExcludeCategories>
<ExcludeCategories Condition=" '$(EnableLLVM)' == 'true' ">$(ExcludeCategories):InetAccess</ExcludeCategories>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also open an issue for the InetAccess test crashes with LLVM enabled?

@jonathanpeppers
Copy link
Member Author

The InetAccess issue, let me investigate that one further, I don't have much information on it:

    08-02 21:26:57.581  5154  5173 I NUnit   : System.NetTests.ProxyTest : 646.269 ms
    08-02 21:26:57.593  5154  5173 I droid.NET_Test: Explicit concurrent copying GC freed 20(95KB) AllocSpace objects, 0(0B) LOS objects, 59% free, 1054KB/2590KB, paused 1.469ms total 7.180ms
    08-02 21:26:57.594  5154  5173 I NUnit   : SslTest
    08-02 21:26:57.594  5154  5173 I NUnit   : HttpsShouldWork 
    08-02 21:26:57.858  5154  5181 D NetworkSecurityConfig: No Network Security Config specified, using platform default
    08-02 21:26:58.585  5154  5164 I droid.NET_Test: Background young concurrent copying GC freed 39658(2920KB) AllocSpace objects, 0(0B) LOS objects, 22% free, 1999KB/2590KB, paused 69.607ms total 194.902ms
    08-02 21:26:58.922  5154  5164 I droid.NET_Test: Background concurrent copying GC freed 12412(836KB) AllocSpace objects, 0(0B) LOS objects, 46% free, 6987KB/12MB, paused 2.127ms total 327.448ms
    08-02 21:26:58.953  5154  5181 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::75000
    08-02 21:26:58.954  5154  5181 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-QcXozuJGB3EpfK6bvDvvMQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Formats.Asn1.dll.so" has no DT_SONAME (will use libaot-System.Formats.Asn1.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
    08-02 21:26:59.037  5154  5181 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::129000
    08-02 21:26:59.038  5154  5181 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-QcXozuJGB3EpfK6bvDvvMQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Runtime.Numerics.dll.so" has no DT_SONAME (will use libaot-System.Runtime.Numerics.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
    08-02 21:26:56.680  5154  5154 W Instrumentation: type=1400 audit(0.0:432): avc: denied { search } for name="run" dev="vdc" ino=32774 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:varrun_file:s0 tclass=dir permissive=0 app=Mono.Android.NET_Tests
    08-02 21:26:56.770  5154  5154 W Instrumentation: type=1400 audit(0.0:433): avc: denied { ioctl } for path="socket:[49468]" dev="sockfs" ino=49468 ioctlcmd=0x8946 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=udp_socket permissive=0 app=Mono.Android.NET_Tests
    08-02 21:26:56.780  5154  5154 W Instrumentation: type=1400 audit(0.0:434): avc: denied { ioctl } for path="socket:[49468]" dev="sockfs" ino=49468 ioctlcmd=0x8946 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=udp_socket permissive=0 app=Mono.Android.NET_Tests
    08-02 21:27:00.029  1540  1540 I Zygote  : Process 5154 exited due to signal 11 (Segmentation fault)

I think it just says (Segmentation fault) and that's it?

run-Mono.Android.NET_Tests-AotLlvm.binlog.zip

grendello added a commit to grendello/xamarin-android that referenced this pull request Aug 3, 2022
* main:
  [Mono.Android] fix crash on startup with EnableLLVM (dotnet#7188)
  [ci] Add Android Designer test template (dotnet#7227)
grendello added a commit to grendello/xamarin-android that referenced this pull request Aug 3, 2022
* mm-codegen:
  [Mono.Android] fix crash on startup with EnableLLVM (dotnet#7188)
  [ci] Add Android Designer test template (dotnet#7227)
jonathanpeppers added a commit that referenced this pull request Aug 5, 2022
`dotnet new android` apps would crash on startup when built with
`-c Release -p:EnableLLVM=true`:

    07-20 08:55:44.642  2983  2983 F monodroid-assembly: Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.
    ...
    07-20 08:55:44.834  3004  3004 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
    07-20 08:55:44.834  3004  3004 F DEBUG   : Abort message: 'Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.'

`java_interop_jvm_list` should *never* be called on Android, it is the
result of `new AndroidRuntime()` having not been called yet?

The problem being that the static `Android.App.Application.cctor` was
somehow running *before* `JNIEnv.Initialize()` was complete? And this
only happens with LLVM?

Reviewing the code:

    [UnmanagedCallersOnly]
    internal static unsafe void Initialize (JnienvInitializeArgs* args)
    {
        //...
        SynchronizationContext.SetSynchronizationContext (Android.App.Application.SynchronizationContext);
    }

We do indeed access `Android.App.Application`...

To fix this, we can move this to a new method decorated with
`MethodImplOptions.NoInlining`. Apps built with LLVM now launch for
me.

However, we can't really enable the LLVM `Mono.Android-Tests` quite
yet. Read on!

~~ Known Issues ~~

* dotnet/runtime#73003

Using Profiled AOT and LLVM at the same time can hit:

    [ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Arg_PlatformNotSupported
    at System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte_Intrinsified(Byte* , UIntPtr )
    at System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte(Byte* , Int32 , Int32& , Int32& )
    at System.Text.UTF8Encoding.GetCharCount(Byte* , Int32 )
    at System.String.CreateStringFromEncoding(Byte* , Int32 , Encoding )
    at System.Text.Encoding.GetString(Byte* , Int32 )
    at System.String.CreateStringForSByteConstructor(Byte* , Int32 )
    at System.String.Ctor(SByte* value)
    at Java.Interop.TypeManager.GetClassName(IntPtr )
    at Android.Runtime.JNIEnv.RegisterJniNatives(IntPtr , Int32 , IntPtr , IntPtr , Int32 )

For now we can set `AndroidEnableProfiledAot=false` for the LLVM tests.

* dotnet/runtime#73304

Some Java.Interop unit tests fail with:

    System.InvalidOperationException : InvalidOperation_EnumEnded
    at System.ArrayEnumerator.get_Current()
    at Cadenza.Collections.Tests.CollectionContract`1[[System.Int16, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].DisposeCollection(IEnumerable c)
    at Cadenza.Collections.Tests.CollectionContract`1[[System.Int16, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CopyTo()
    at System.Reflection.MethodInvoker.InterpretedInvoke(Object , Span`1 , BindingFlags )

* https://github.com/xamarin/java.interop/blob/a3de91efdaec04b3927b755a07018e8d26cfdc71/tests/Java.Interop-Tests/Cadenza.Collections/CollectionContract.cs#L205-L221
* https://github.com/xamarin/java.interop/blob/a3de91efdaec04b3927b755a07018e8d26cfdc71/tests/Java.Interop-Tests/Cadenza.Collections/CollectionContract.cs#L85-L86

The `InetAccess` category causes the `Mono.Android-Tests` suite to crash with:

    08-02 21:26:57.581  5154  5173 I NUnit   : System.NetTests.ProxyTest : 646.269 ms
    08-02 21:26:57.593  5154  5173 I droid.NET_Test: Explicit concurrent copying GC freed 20(95KB) AllocSpace objects, 0(0B) LOS objects, 59% free, 1054KB/2590KB, paused 1.469ms total 7.180ms
    08-02 21:26:57.594  5154  5173 I NUnit   : SslTest
    08-02 21:26:57.594  5154  5173 I NUnit   : HttpsShouldWork 
    08-02 21:26:57.858  5154  5181 D NetworkSecurityConfig: No Network Security Config specified, using platform default
    08-02 21:26:58.585  5154  5164 I droid.NET_Test: Background young concurrent copying GC freed 39658(2920KB) AllocSpace objects, 0(0B) LOS objects, 22% free, 1999KB/2590KB, paused 69.607ms total 194.902ms
    08-02 21:26:58.922  5154  5164 I droid.NET_Test: Background concurrent copying GC freed 12412(836KB) AllocSpace objects, 0(0B) LOS objects, 46% free, 6987KB/12MB, paused 2.127ms total 327.448ms
    08-02 21:26:58.953  5154  5181 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::75000
    08-02 21:26:58.954  5154  5181 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-QcXozuJGB3EpfK6bvDvvMQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Formats.Asn1.dll.so" has no DT_SONAME (will use libaot-System.Formats.Asn1.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
    08-02 21:26:59.037  5154  5181 I monodroid-timing: [1/0] LZ4 decompression time for <assembly_store>; elapsed: 0:0::129000
    08-02 21:26:59.038  5154  5181 W linker  : Warning: "/data/app/Mono.Android.NET_Tests-QcXozuJGB3EpfK6bvDvvMQ==/split_config.x86_64.apk!/lib/x86_64/libaot-System.Runtime.Numerics.dll.so" has no DT_SONAME (will use libaot-System.Runtime.Numerics.dll.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 21)
    08-02 21:26:56.680  5154  5154 W Instrumentation: type=1400 audit(0.0:432): avc: denied { search } for name="run" dev="vdc" ino=32774 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:varrun_file:s0 tclass=dir permissive=0 app=Mono.Android.NET_Tests
    08-02 21:26:56.770  5154  5154 W Instrumentation: type=1400 audit(0.0:433): avc: denied { ioctl } for path="socket:[49468]" dev="sockfs" ino=49468 ioctlcmd=0x8946 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=udp_socket permissive=0 app=Mono.Android.NET_Tests
    08-02 21:26:56.780  5154  5154 W Instrumentation: type=1400 audit(0.0:434): avc: denied { ioctl } for path="socket:[49468]" dev="sockfs" ino=49468 ioctlcmd=0x8946 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=udp_socket permissive=0 app=Mono.Android.NET_Tests
    08-02 21:27:00.029  1540  1540 I Zygote  : Process 5154 exited due to signal 11 (Segmentation fault)

Not really any useful info here...

Disabled this category for now. We can file an issue for this one,
assuming it is different than the other issues.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants