dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.36k stars 4.75k forks source link

[mono] Runtime tests failing with 'Attempting to JIT compile method' for Mono FullAOT mode #70492

Open ivanpovazan opened 2 years ago

ivanpovazan commented 2 years ago

Summary

Runtime tests:

are failing in FullAOT mode on Mono with nearly the same Attempting to JIT compile method xxx while running in aot-only mode.

StdCallMemberFunctionTest

Output

Full output for /JIT/Directed/callconv/StdCallMemberFunction/StdCallMemberFunctionTest/*:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) StdCallMemberFunctionNative/SizeF modopt(System.Runtime.CompilerServices.CallConvMemberFunction) modopt(System.Runtime.CompilerServices.CallConvStdcall) StdCallMemberFunctionTest:wrapper_native_indirect_0x600003ce7140 (intptr&,StdCallMemberFunctionNative/C*,int)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

   at StdCallMemberFunctionTest.Test8ByteHFA(C* instance) in /Users/ivan/repos/runtime-mono-AOT/src/tests/JIT/Directed/callconv/StdCallMemberFunction/StdCallMemberFunctionTest.cs:line 96
   at StdCallMemberFunctionTest.Main(String[] args)
Expected: 100
Actual: 101
END EXECUTION - FAILED

Repro

1) Enable building the test with Mono AOT

diff --git a/src/tests/JIT/Directed/callconv/Directory.Build.props b/src/tests/JIT/Directed/callconv/Directory.Build.props
index 49b99b7a101..9ed3161df40 100644
--- a/src/tests/JIT/Directed/callconv/Directory.Build.props
+++ b/src/tests/JIT/Directed/callconv/Directory.Build.props
@@ -2,6 +2,6 @@
   <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

   <PropertyGroup>
-    <MonoAotIncompatible>true</MonoAotIncompatible>
+    <MonoAotIncompatible>false</MonoAotIncompatible>
   </PropertyGroup>
 </Project>

2) Build Mono

./build.sh mono+libs+clr.hosts -c debug /p:MonoEnableLlvm=true /p:MonoLLVMUseCxx11Abi=true

3) Build the test

./src/tests/build.sh mono debug /p:LibrariesConfiguration=Debug -test:JIT/Directed/callconv/StdCallMemberFunction/StdCallMemberFunctionTest.csproj

4) AOT compile the test

./src/tests/build.sh mono_fullaot debug /p:LibrariesConfiguration=Debug -test:JIT/Directed/callconv/StdCallMemberFunction/StdCallMemberFunctionTest.csproj

5) Run the test (note: adjust the paths)

MONO_ENV_OPTIONS=--full-aot bash /Users/ivan/repos/runtime-mono-AOT/artifacts/tests/coreclr/OSX.arm64.Debug/JIT/Directed/callconv/StdCallMemberFunction/StdCallMemberFunctionTest/StdCallMemberFunctionTest.sh  -coreroot=/Users/ivan/repos/runtime-mono-AOT/artifacts/tests/coreclr/OSX.arm64.Debug/Tests/Core_Root

Additional notes

Tests exclusion details should be updated to reference this tracking issue: Done.

Possibly related to: https://github.com/dotnet/runtime/issues/50440

cc: @lambdageek @lateralusX

ivanpovazan commented 2 years ago

@lambdageek should we try to fix this for .NET7?

SamMonoRT commented 1 year ago

Assigning to @LeVladIonescu related to current work

matouskozak commented 11 months ago

Current situation. Mono is reporting the following warnings for StdCallMemberFunctionTest and CdeclMemberFunctionTest tests:

Multiple calling conventions are not supported for UnmanagedCallersOnlyAttribute parameter CallConvs, specified for method GetWidthAsLong. Only the first calling convention will be taken into account
Multiple calling conventions are not supported for UnmanagedCallersOnlyAttribute parameter CallConvs, specified for method GetE. Only the first calling convention will be taken into account
Multiple calling conventions are not supported for UnmanagedCallersOnlyAttribute parameter CallConvs, specified for method GetHeightAsInt. Only the first calling convention will be taken into account
Multiple calling conventions are not supported for UnmanagedCallersOnlyAttribute parameter CallConvs, specified for method GetWidth. Only the first calling convention will be taken into account
Multiple calling conventions are not supported for UnmanagedCallersOnlyAttribute parameter CallConvs, specified for method GetSize. Only the first calling convention will be taken into account

This could be related to missing support for CallConvMemberFunction https://github.com/dotnet/runtime/issues/50440 as is listed in the PR description.

The ThisCallTest is still failing with:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) ThisCallNative/SizeF ThisCallTest/<>c:<get_ManagedVtable>b__20_0 (ThisCallNative/C*,int)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

   at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(Delegate d)
   at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate[GetSizeFn](GetSizeFn d)
   at ThisCallTest.get_ManagedVtable()
   at ThisCallTest.Test8ByteHFAReverse()
   at ThisCallTest.TestEntryPoint()
Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 100
Actual:   101
   at Xunit.Assert.Equal[Int32](Int32 expected, Int32 actual, IEqualityComparer`1 comparer)
   at Xunit.Assert.Equal[Int32](Int32 expected, Int32 actual)
   at __GeneratedMainWrapper.Main()
Expected: 100
Actual: 101
END EXECUTION - FAILED

and PlatformDefaultMemberFunctionTest is passing correctly.

ivanpovazan commented 11 months ago

@matouskozak I suggest we enable the tests that are now passing.

matouskozak commented 9 months ago

Enabled tests (https://github.com/dotnet/runtime/pull/96243):

Test to fix:

ivanpovazan commented 9 months ago

@matouskozak are you currently actively working on the fix for ThisCallTest? If not, I would suggest updating the issue description with the current state and add a disabled test label.