From 2fe9b3bfe6e5936abb1ef69b7d3ca25a72a52942 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 17 Apr 2024 19:24:57 +0300 Subject: [PATCH] [mono][interp] Resolve virtual method on delegates created by compiled code (#101168) Creating a delegate would normally end up calling into the runtime via ves_icall_mono_delegate_ctor. However, jit/aot backand have a fastpath where the delegate is not fully initialized (relying on the delegate trampoline to resolve the actual method to be called when the delegate is first called). Interp delegate initialization therefore doesn't take place. If this is the case and the delegate method is virtual, we would need to resolve it based on the target object. --- src/mono/mono/mini/interp/interp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index a4e435ceeb7..7de2bf84d84 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -4098,6 +4098,8 @@ main_loop: // Not created from interpreted code g_assert (del->method); del_imethod = mono_interp_get_imethod (del->method); + if (del->target && m_method_is_virtual (del->method)) + del_imethod = get_virtual_method (del_imethod, del->target->vtable); del->interp_method = del_imethod; del->interp_invoke_impl = del_imethod; } else {