From a8f7d5c2eff08f8f4a2bf1851b7565d498d0ac83 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 20 Mar 2024 18:00:16 +0200 Subject: [PATCH 1/2] [mono][interp] Remove old hack interp_create_method_pointer should only ever return a function pointer callable from compiled code. --- src/mono/mono/mini/interp/interp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 30bc914204edae..ee9566afc23397 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -3478,9 +3478,6 @@ interp_create_method_pointer (MonoMethod *method, gboolean compile, MonoError *e return (gpointer)no_llvmonly_interp_method_pointer; } - if (method->wrapper_type && method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) - return imethod; - #ifndef MONO_ARCH_HAVE_FTNPTR_ARG_TRAMPOLINE /* * Interp in wrappers get the argument in the rgctx register. If From 69b4db1301f1fe0f5d2e0b2d559cf804877d9f97 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 20 Mar 2024 18:15:21 +0200 Subject: [PATCH 2/2] [mono][interp] Attempt to interpret m2n wrapper if it is not found in aot image On ios with interpreter enabled it can happen to mark an assembly as aot and have the rest interpreted, including SPC.dll. If the aot code attempts to do an icall, for example Math.Ceiling defined in SPC.dll, it will fail to find the m2n wrapper, since SPC.dll is not aot-ed. We fix this by obtaining an interp entry thunk, in order to execute the wrapper in interp, if we can't find the aot version of wrapper. --- src/mono/mono/mini/mini-runtime.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 8274949414c275..90fe8ddc799ebf 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2564,7 +2564,18 @@ compile_special (MonoMethod *method, MonoError *error) } else { MonoMethod *nm = mono_marshal_get_native_wrapper (method, TRUE, mono_aot_only); compiled_method = mono_jit_compile_method_jit_only (nm, error); - return_val_if_nok (error, NULL); + if (!compiled_method && mono_aot_only && mono_use_interpreter) { + // We failed to find wrapper in aot images, try interpreting it instead + mono_error_cleanup (error); + error_init_reuse (error); + nm = mono_marshal_get_native_wrapper (method, TRUE, FALSE); + compiled_method = mono_jit_compile_method (nm, error); + return_val_if_nok (error, NULL); + code = mono_get_addr_from_ftnptr (compiled_method); + return code; + } else { + return_val_if_nok (error, NULL); + } } code = mono_get_addr_from_ftnptr (compiled_method);