Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Enable NativeToManaged wrappers to get compiled with LLVM #96910

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6332,6 +6332,8 @@ method_is_externally_callable (MonoAotCompile *acfg, MonoMethod *method)
//return TRUE;
return FALSE;
} else {
if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED && g_hash_table_lookup (llvm_acfg->export_names, method))
return TRUE;
if (!acfg->aot_opts.direct_extern_calls)
return FALSE;
if (!acfg->llvm)
Expand Down Expand Up @@ -10610,6 +10612,15 @@ append_mangled_method (GString *s, MonoMethod *method)
char*
mono_aot_get_mangled_method_name (MonoMethod *method)
{
if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
char *export_name = (char *)g_hash_table_lookup (llvm_acfg->export_names, method);
if (export_name) {
if (strncmp (export_name, llvm_acfg->user_symbol_prefix, strlen (llvm_acfg->user_symbol_prefix)) == 0)
return g_strdup (export_name + strlen (llvm_acfg->user_symbol_prefix));
else
return export_name;
}
}
// FIXME: use static cache (mempool?)
// We call this a *lot*

Expand Down
39 changes: 23 additions & 16 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,13 +2284,12 @@ static LLVMValueRef
get_callee (EmitContext *ctx, LLVMTypeRef llvm_sig, MonoJumpInfoType type, gconstpointer data)
{
LLVMValueRef callee;
char *callee_name;
char *callee_name = NULL;
MonoJumpInfo *ji = NULL;

if (ctx->llvm_only)
return get_callee_llvmonly (ctx, llvm_sig, type, data);

callee_name = NULL;
/* Cross-assembly direct calls */
if (type == MONO_PATCH_INFO_METHOD) {
MonoMethod *cmethod = (MonoMethod*)data;
Expand All @@ -2313,24 +2312,31 @@ get_callee (EmitContext *ctx, LLVMTypeRef llvm_sig, MonoJumpInfoType type, gcons
mono_aot_get_got_offset (ji);

callee_name = mono_aot_get_mangled_method_name (cmethod);
}
}
} else if (type == MONO_PATCH_INFO_JIT_ICALL_ID) {
callee_name = mono_aot_get_direct_call_symbol (type, data);
}

callee = (LLVMValueRef)g_hash_table_lookup (ctx->module->direct_callables, callee_name);
if (!callee) {
callee = LLVMAddFunction (ctx->lmodule, callee_name, llvm_sig);
if (callee_name) {
/* Directly callable */
callee = (LLVMValueRef)g_hash_table_lookup (ctx->module->direct_callables, callee_name);
if (!callee) {
callee = LLVMAddFunction (ctx->lmodule, callee_name, llvm_sig);

LLVMSetLinkage (callee, LLVMExternalLinkage);
LLVMSetVisibility (callee, LLVMHiddenVisibility);

g_hash_table_insert (ctx->module->direct_callables, callee_name, callee);
} else {
/* LLVMTypeRef's are uniqued */
if (LLVMGetElementType (LLVMTypeOf (callee)) != llvm_sig)
callee = LLVMConstBitCast (callee, pointer_type (llvm_sig));
g_hash_table_insert (ctx->module->direct_callables, (char*)callee_name, callee);
} else {
#ifndef USE_OPAQUE_POINTERS
/* LLVMTypeRef's are uniqued */
if (LLVMGetElementType (LLVMTypeOf (callee)) != llvm_sig)
return LLVMConstBitCast (callee, pointer_type (llvm_sig));
#endif

g_free (callee_name);
}
return callee;
}
g_free (callee_name);
}
return callee;
}

callee_name = mono_aot_get_plt_symbol (type, data);
Expand Down Expand Up @@ -12780,7 +12786,8 @@ emit_method_inner (EmitContext *ctx)
return;
}

if (sig->pinvoke && cfg->method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE && !cfg->llvm_only) {
if (sig->pinvoke && cfg->method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE &&
cfg->method->wrapper_type != MONO_WRAPPER_NATIVE_TO_MANAGED && !cfg->llvm_only) {
set_failure (ctx, "pinvoke signature");
return;
}
Expand Down
Loading