Skip to content

Commit 498731b

Browse files
committed
[llvmonly] Throw an ExecutionEngine exception with a helpful message when we try to execute a method which failed AOT compilation.
<!-- Thank you for your Pull Request! If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed. Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number -->
1 parent 26eb70b commit 498731b

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

src/mono/mono/metadata/jit-icall-reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ MONO_JIT_ICALL (mini_llvmonly_resolve_generic_virtual_iface_call) \
139139
MONO_JIT_ICALL (mini_llvmonly_resolve_iface_call_gsharedvt) \
140140
MONO_JIT_ICALL (mini_llvmonly_resolve_vcall_gsharedvt) \
141141
MONO_JIT_ICALL (mini_llvmonly_throw_nullref_exception) \
142-
MONO_JIT_ICALL (mini_llvmonly_throw_missing_method_exception) \
142+
MONO_JIT_ICALL (mini_llvmonly_throw_aot_failed_exception) \
143143
MONO_JIT_ICALL (mono_amd64_resume_unwind) \
144144
MONO_JIT_ICALL (mono_amd64_start_gsharedvt_call) \
145145
MONO_JIT_ICALL (mono_amd64_throw_corlib_exception) \

src/mono/mono/mini/llvmonly-runtime.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,14 +809,11 @@ mini_llvmonly_throw_nullref_exception (void)
809809
mono_llvm_throw_corlib_exception (ex_token_index);
810810
}
811811

812-
static GENERATE_GET_CLASS_WITH_CACHE (missing_method, "System", "MissingMethodException")
813-
814812
void
815-
mini_llvmonly_throw_missing_method_exception (void)
813+
mini_llvmonly_throw_aot_failed_exception (const char *name)
816814
{
817-
MonoClass *klass = mono_class_get_missing_method_class ();
818-
819-
guint32 ex_token_index = m_class_get_type_token (klass) - MONO_TOKEN_TYPE_DEF;
820-
821-
mono_llvm_throw_corlib_exception (ex_token_index);
815+
char *msg = g_strdup_printf ("AOT Compilation failed for method '%s'.", name);
816+
MonoException *ex = mono_get_exception_execution_engine (msg);
817+
g_free (msg);
818+
mono_llvm_throw_exception ((MonoObject*)ex);
822819
}

src/mono/mono/mini/llvmonly-runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ G_EXTERN_C void mini_llvm_init_method (MonoAotFileInfo *info, gpointer
3333

3434
G_EXTERN_C void mini_llvmonly_throw_nullref_exception (void);
3535

36-
G_EXTERN_C void mini_llvmonly_throw_missing_method_exception (void);
36+
G_EXTERN_C void mini_llvmonly_throw_aot_failed_exception (const char *name);
3737

3838
#endif

src/mono/mono/mini/mini-llvm.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9542,10 +9542,22 @@ emit_method_inner (EmitContext *ctx)
95429542
ctx->builder = create_builder (ctx);
95439543
LLVMPositionBuilderAtEnd (ctx->builder, ctx->inited_bb);
95449544

9545+
char *name = mono_method_get_full_name (cfg->method);
9546+
int len = strlen (name);
9547+
9548+
LLVMTypeRef type = LLVMArrayType (LLVMInt8Type (), len + 1);
9549+
LLVMValueRef name_var = LLVMAddGlobal (ctx->lmodule, type, "missing_method_name");
9550+
LLVMSetVisibility (name_var, LLVMHiddenVisibility);
9551+
LLVMSetLinkage (name_var, LLVMInternalLinkage);
9552+
LLVMSetInitializer (name_var, mono_llvm_create_constant_data_array ((guint8*)name, len + 1));
9553+
mono_llvm_set_is_constant (name_var);
9554+
g_free (name);
9555+
95459556
if (!sig)
9546-
sig = LLVMFunctionType0 (LLVMVoidType (), FALSE);
9547-
LLVMValueRef callee = get_callee (ctx, sig, MONO_PATCH_INFO_JIT_ICALL_ADDR, GUINT_TO_POINTER (MONO_JIT_ICALL_mini_llvmonly_throw_missing_method_exception));
9548-
LLVMBuildCall (ctx->builder, callee, NULL, 0, "");
9557+
sig = LLVMFunctionType1 (LLVMVoidType (), ctx->module->ptr_type, FALSE);
9558+
LLVMValueRef callee = get_callee (ctx, sig, MONO_PATCH_INFO_JIT_ICALL_ADDR, GUINT_TO_POINTER (MONO_JIT_ICALL_mini_llvmonly_throw_aot_failed_exception));
9559+
LLVMValueRef args [] = { convert (ctx, name_var, ctx->module->ptr_type) };
9560+
LLVMBuildCall (ctx->builder, callee, args, 1, "");
95499561
LLVMBuildUnreachable (ctx->builder);
95509562
}
95519563

src/mono/mono/mini/mini-runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4672,7 +4672,7 @@ register_icalls (void)
46724672
register_icall (mini_llvmonly_init_delegate, mono_icall_sig_void_object, TRUE);
46734673
register_icall (mini_llvmonly_init_delegate_virtual, mono_icall_sig_void_object_object_ptr, TRUE);
46744674
register_icall (mini_llvmonly_throw_nullref_exception, mono_icall_sig_void, TRUE);
4675-
register_icall (mini_llvmonly_throw_missing_method_exception, mono_icall_sig_void, TRUE);
4675+
register_icall (mini_llvmonly_throw_aot_failed_exception, mono_icall_sig_void_ptr, TRUE);
46764676

46774677
register_icall (mono_get_assembly_object, mono_icall_sig_object_ptr, TRUE);
46784678
register_icall (mono_get_method_object, mono_icall_sig_object_ptr, TRUE);

0 commit comments

Comments
 (0)