Skip to content

Commit 59c592c

Browse files
authored
[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.
1 parent 240fcec commit 59c592c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/mono/mono/mini/calls.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,17 @@ mini_emit_llvmonly_virtual_call (MonoCompile *cfg, MonoMethod *cmethod, MonoMeth
670670
int offset;
671671
gboolean special_array_interface = m_class_is_array_special_interface (cmethod->klass);
672672

673-
if (cfg->interp && can_enter_interp (cfg, cmethod, TRUE))
673+
if (cfg->interp && can_enter_interp (cfg, cmethod, TRUE)) {
674674
/* Need wrappers for this signature to be able to enter interpreter */
675675
cfg->interp_in_signatures = g_slist_prepend_mempool (cfg->mempool, cfg->interp_in_signatures, fsig);
676676

677+
if (m_class_is_delegate (cmethod->klass) && !strcmp (cmethod->name, "Invoke")) {
678+
/* To support dynamically generated code, add a signature for the actual method called by the delegate as well. */
679+
MonoMethodSignature *nothis_sig = mono_metadata_signature_dup_add_this (m_class_get_image (cmethod->klass), fsig, mono_get_object_class ());
680+
cfg->interp_in_signatures = g_slist_prepend_mempool (cfg->mempool, cfg->interp_in_signatures, nothis_sig);
681+
}
682+
}
683+
677684
/*
678685
* In llvm-only mode, vtables contain function descriptors instead of
679686
* method addresses/trampolines.

0 commit comments

Comments
 (0)