runtime: .NET 7 exception on Android with EnableLLVM=true
Description
Run with LLVM on an arm64 device, and you can run into:
07-22 09:59:55.062 4374 4374 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Arg_PlatformNotSupported
07-22 09:59:55.062 4374 4374 F mono-rt : at System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte_Intrinsified(Byte* , UIntPtr )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte(Byte* , Int32 , Int32& , Int32& )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.Text.UTF8Encoding.GetCharCount(Byte* , Int32 )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.String.CreateStringFromEncoding(Byte* , Int32 , Encoding )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.Text.Encoding.GetString(Byte* , Int32 )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.String.CreateStringForSByteConstructor(Byte* , Int32 )
07-22 09:59:55.062 4374 4374 F mono-rt : at System.String.Ctor(SByte* value)
07-22 09:59:55.062 4374 4374 F mono-rt : at Java.Interop.TypeManager.GetClassName(IntPtr )
07-22 09:59:55.062 4374 4374 F mono-rt : at Android.Runtime.JNIEnv.RegisterJniNatives(IntPtr , Int32 , IntPtr , IntPtr , Int32 )
Somewhere here:
So I think AdvSimd.Arm64.IsSupported is true, but because GetIndexOfFirstNonAsciiByte_Intrinsified() is not in the AOT profile (it’s running under JIT), we get the above exception. It’s possible that the above code should also work under JIT.
/cc @fanyang-mono
Reproduction Steps
dotnet new androiddotnet build -t:Run -c Release -p:EnableLLVM=trueto run on an arm64 device (in my case a Pixel 5)
Expected behavior
You can use Profiled AOT + LLVM together on Android.
Actual behavior
We get an exception when trying to use Profiled AOT + LLVM together on Android.
Regression?
I don’t hit this same exception in .NET 6, but maybe it’s just luck?
Known Workarounds
You can turn off profiled AOT, such as -p:AndroidEnableProfiledAot=false or don’t use LLVM.
Configuration
.NET 7.0.100-rc.1.22374.1
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (14 by maintainers)
Commits related to this issue
- [Mono.Android] fix crash on startup with EnableLLVM (#7188) `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 ... — committed to xamarin/xamarin-android by jonathanpeppers 2 years ago
- [Mono.Android] fix crash on startup with EnableLLVM (#7188) `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 ... — committed to xamarin/xamarin-android by jonathanpeppers 2 years ago
My suggestion was to make sure we always LLVM AOT the implementation, regardless of whether it is used by the profile, so that no fallback to the JIT occurs.