From 84565aadac6c5ec488db29f676f18a621d60f974 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 2942fb23d3f82f..5328d982af6f03 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -3362,9 +3362,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 1f5bd5c57986d794d6719d424ebbb8adc40e01b9 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 d075623de8cf73..0318c3d1689bcc 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2558,7 +2558,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);