From cc13fe41d6774eaada46e4851b0f20764b6ecab3 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 24 Mar 2025 07:32:00 +0100 Subject: [PATCH] Allow using P/Invoke helpers for IL stubs --- src/coreclr/jit/lower.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 8b1dc5d10b1e06..59235daf465337 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -5943,7 +5943,7 @@ void Lowering::InsertPInvokeMethodProlog() noway_assert(comp->info.compUnmanagedCallCountWithGCTransition); noway_assert(comp->lvaInlinedPInvokeFrameVar != BAD_VAR_NUM); - if (comp->opts.ShouldUsePInvokeHelpers()) + if (!comp->info.compPublishStubParam && comp->opts.ShouldUsePInvokeHelpers()) { return; } @@ -5972,6 +5972,13 @@ void Lowering::InsertPInvokeMethodProlog() DISPTREERANGE(firstBlockRange, store); } + // If we use P/Invoke helper calls then the hidden stub initialization + // is all we need to do. Rest will get initialized by the helper. + if (comp->opts.ShouldUsePInvokeHelpers()) + { + return; + } + // Call runtime helper to fill in our InlinedCallFrame and push it on the Frame list: // TCB = CORINFO_HELP_INIT_PINVOKE_FRAME(&symFrameStart); GenTree* frameAddr = comp->gtNewLclVarAddrNode(comp->lvaInlinedPInvokeFrameVar);