From 59c592cc8d2778bcc6173baa2b25b13190e42990 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 5 Apr 2021 09:43:21 -0400 Subject: [PATCH] [mono] Fix delegate invokes to dynamic methods in mixed mode. (#50547) In mixed mode, when compiling a call to a delegate invoke, add an interp entry wrapper for the signature used by the actual method which is called by the invoke, which might be a dynamic method whose signature is otherwise not present in the program. --- src/mono/mono/mini/calls.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/calls.c b/src/mono/mono/mini/calls.c index 38ec02b..8424a48 100644 --- a/src/mono/mono/mini/calls.c +++ b/src/mono/mono/mini/calls.c @@ -670,10 +670,17 @@ mini_emit_llvmonly_virtual_call (MonoCompile *cfg, MonoMethod *cmethod, MonoMeth int offset; gboolean special_array_interface = m_class_is_array_special_interface (cmethod->klass); - if (cfg->interp && can_enter_interp (cfg, cmethod, TRUE)) + if (cfg->interp && can_enter_interp (cfg, cmethod, TRUE)) { /* Need wrappers for this signature to be able to enter interpreter */ cfg->interp_in_signatures = g_slist_prepend_mempool (cfg->mempool, cfg->interp_in_signatures, fsig); + if (m_class_is_delegate (cmethod->klass) && !strcmp (cmethod->name, "Invoke")) { + /* To support dynamically generated code, add a signature for the actual method called by the delegate as well. */ + MonoMethodSignature *nothis_sig = mono_metadata_signature_dup_add_this (m_class_get_image (cmethod->klass), fsig, mono_get_object_class ()); + cfg->interp_in_signatures = g_slist_prepend_mempool (cfg->mempool, cfg->interp_in_signatures, nothis_sig); + } + } + /* * In llvm-only mode, vtables contain function descriptors instead of * method addresses/trampolines. -- 2.7.4