Skip to content

Commit

Permalink
[mono][mini] Prefer llvmaot compiled method instead of inlining it wi…
Browse files Browse the repository at this point in the history
…th JIT

The motivation for this is to fix crashes due to different HW intrinsics support between llvm and JIT. For example, a llvmaot compiled method might check if we have a set of HW intrinsics available and proceed with a code path that will end up calling a method that assumes intrinsics support that is not present in the aot image (because the gsharedvt version is not emitted for example). In this scenario, the called method will end up being compiled with JIT where we would crash due to missing HW intrinsics support.
  • Loading branch information
BrzVlad committed Sep 11, 2024
1 parent 6219d18 commit 8d5107c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -6547,6 +6547,12 @@ mono_aot_get_method_flags (guint8 *code)
return (MonoAotMethodFlags)flags;
}

MonoAotFileFlags
mono_aot_get_module_flags (gpointer aot_module)
{
return ((MonoAotModule*)aot_module)->info.flags;
}

#else
/* AOT disabled */

Expand Down Expand Up @@ -6747,4 +6753,10 @@ mono_aot_get_method_flags (guint8 *code)
return MONO_AOT_METHOD_FLAG_NONE;
}

MonoAotFileFlags
mono_aot_get_module_flags (gpointer aot_module)
{
return 0;
}

#endif
1 change: 1 addition & 0 deletions src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ guint32 mono_aot_find_method_index (MonoMethod *method);
gboolean mono_aot_init_llvm_method (gpointer aot_module, gpointer method_info, MonoClass *init_class, MonoError *error);
GHashTable *mono_aot_get_weak_field_indexes (MonoImage *image);
MonoAotMethodFlags mono_aot_get_method_flags (guint8 *code);
MonoAotFileFlags mono_aot_get_module_flags (gpointer aot_module);

#ifdef MONO_ARCH_CODE_EXEC_ONLY
typedef guint32 (*MonoAotResolvePltInfoOffset)(gpointer amodule, guint32 plt_entry_index);
Expand Down
10 changes: 10 additions & 0 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4179,6 +4179,16 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method)
if (method_does_not_return (method))
return FALSE;

MonoAotModule *amodule = m_class_get_image (method->klass)->aot_module;
if (amodule && (amodule != AOT_MODULE_NOT_FOUND) && (mono_aot_get_module_flags (amodule) & MONO_AOT_FILE_FLAG_WITH_LLVM)) {
ERROR_DECL (error);
mono_class_init_internal (method->klass);
gpointer addr = mono_aot_get_method (method, error);
// If method is present in aot image compiled with llvm, we don't inline it
if (addr && is_ok (error))
return FALSE;
}

return TRUE;
}

Expand Down

0 comments on commit 8d5107c

Please sign in to comment.