Skip to content

Commit

Permalink
[mono][interp] Attempt to interpret m2n wrapper if it is not found in…
Browse files Browse the repository at this point in the history
… aot image (dotnet#100025)

* [mono][interp] Remove old hack

interp_create_method_pointer should only ever return a function pointer callable from compiled code.

* [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.
  • Loading branch information
BrzVlad committed Mar 21, 2024
1 parent 09608df commit e4abc2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e4abc2d

Please sign in to comment.