From 77891730d64b9d110133a4dfd2fd15f461aedc31 Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Sun, 29 Nov 2026 22:15:24 +0200
Subject: [PATCH 1/6] Add repro for x86 dispatch slow path unwinding in
funclets
---
.../DispatchSlowFunclet.cs | 47 +++++++++++++++++++
.../DispatchSlowFunclet.csproj | 12 +++++
2 files changed, 59 insertions(+)
create mode 100644 src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
create mode 100644 src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
diff --git a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
new file mode 100644
index 00000000000000..60798bc3dcdb1b
--- /dev/null
+++ b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+interface IManyArgs { int Sum(int a, int b, int c, int d, int e, int f); }
+
+[DynamicInterfaceCastableImplementation]
+interface IManyArgsImpl : IManyArgs
+{
+ int IManyArgs.Sum(int a, int b, int c, int d, int e, int f) => a + b + c + d + e + f;
+}
+
+sealed class Castable : IDynamicInterfaceCastable
+{
+ public static int Resolutions;
+
+ // Called from the dispatch slow path (RhpInterfaceDispatchSlow -> RhpCidResolve).
+ public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle t)
+ {
+ Resolutions++;
+ GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
+ return typeof(IManyArgsImpl).TypeHandle;
+ }
+
+ public bool IsInterfaceImplemented(RuntimeTypeHandle t, bool throwIfNotImplemented) => true;
+}
+
+static class Program
+{
+ [MethodImpl(MethodImplOptions.NoInlining)] static IManyArgs Get() => (IManyArgs)(object)new Castable();
+ [MethodImpl(MethodImplOptions.NoInlining)] static void Throw() => throw new InvalidOperationException();
+
+ static int Main(string[] args)
+ {
+ int sum = 0;
+ for (int i = 0; i < 8; i++)
+ {
+ try { Throw(); }
+ catch (InvalidOperationException) { sum += Get().Sum(1, 2, 3, 4, 5, 6); }
+ }
+ Console.WriteLine($"sum={sum} resolutions={Castable.Resolutions}");
+ return sum == 8 * 21 ? 100 : 1;
+ }
+}
diff --git a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
new file mode 100644
index 00000000000000..d1900cd9d0b0fe
--- /dev/null
+++ b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ 0
+ true
+ true
+ false
+
+
+
+
+
From 27e685dadc55905541294d78255b9995a552cf1b Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Sun, 29 Nov 2026 22:36:44 +0200
Subject: [PATCH 2/6] Resolve interface calls in x86 funclets with a helper
The interface dispatch slow path cannot unwind into funclets on x86
since it does not know the size of the callee-popped arguments.
Fixes #138481
---
src/coreclr/jit/importer.cpp | 5 +++++
src/coreclr/jit/importercalls.cpp | 18 +++++++++++++++++-
.../DependencyAnalysis/KnownExternFunctions.cs | 5 ++---
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp
index 925a3d7b77570a..9b2e8ae8fb95f4 100644
--- a/src/coreclr/jit/importer.cpp
+++ b/src/coreclr/jit/importer.cpp
@@ -2706,6 +2706,11 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr,
}
#ifdef TARGET_WASMARCH
else if (IsNativeAot() && isInterface)
+#elif defined(TARGET_X86)
+ // Interface calls in funclets, see impImportCall
+ else if (IsNativeAot() && isInterface && (pCallInfo->kind == CORINFO_VIRTUALCALL_STUB))
+#endif
+#if defined(TARGET_WASMARCH) || defined(TARGET_X86)
{
GenTree* dispatchCell = impLookupToTree(&pCallInfo->codePointerLookup, GTF_ICON_GLOBAL_PTR, nullptr);
if (dispatchCell == nullptr)
diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp
index 3b7157677d1fd6..36bd64be654eef 100644
--- a/src/coreclr/jit/importercalls.cpp
+++ b/src/coreclr/jit/importercalls.cpp
@@ -502,7 +502,23 @@ var_types Compiler::impImportCall(OPCODE opcode,
exactContextHnd = callInfo->contextHandle;
exactContextNeedsRuntimeLookup = callInfo->exactContextNeedsRuntimeLookup;
- switch (callInfo->kind)
+ CORINFO_CALL_KIND callKind = callInfo->kind;
+
+#ifdef TARGET_X86
+ // The interface dispatch slow path cannot unwind into funclets on x86 since it does not know the size of the
+ // callee-popped arguments. Resolve the target from the dispatch cell with a helper call instead.
+ if ((callKind == CORINFO_VIRTUALCALL_STUB) && IsNativeAot() &&
+ (compIsForInlining() ? impInlineInfo->iciBlock : compCurBB)->hasHndIndex())
+ {
+ callKind = CORINFO_VIRTUALCALL_LDVIRTFTN;
+ if (!callInfo->stubLookup.lookupKind.needsRuntimeLookup)
+ {
+ callInfo->stubLookup.constLookup.accessType = IAT_VALUE;
+ }
+ }
+#endif
+
+ switch (callKind)
{
case CORINFO_VIRTUALCALL_STUB:
{
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/KnownExternFunctions.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/KnownExternFunctions.cs
index 2f8d2970ae266a..fa9a7a60949d29 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/KnownExternFunctions.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/KnownExternFunctions.cs
@@ -83,7 +83,7 @@ public static Utf8String GetName(ReadyToRunHelper function, TargetDetails target
ReadyToRunHelper.GVMLookupForSlot => "RhpDispatchResolve",
ReadyToRunHelper.InterfaceDispatch => "RhpInterfaceDispatch",
ReadyToRunHelper.InterfaceDispatchGuarded => "RhpInterfaceDispatchGuarded",
- ReadyToRunHelper.ResolveInterfaceMethodFast => "RhpResolveInterfaceMethodFast",
+ ReadyToRunHelper.ResolveInterfaceMethodFast => "RhpDispatchResolve",
ReadyToRunHelper.ResolveInterfaceMethod => "RhpResolveInterfaceMethod",
ReadyToRunHelper.StackProbe => "RhpStackProbe",
@@ -189,8 +189,7 @@ ReadyToRunHelper.CheckedWriteBarrier_ESI or
ReadyToRunHelper.GVMLookupForSlot => MakeSignature(nativeIntType, objectType, nativeIntType),
ReadyToRunHelper.ResolveInterfaceMethod => MakeSignature(nativeIntType, objectType, nativeIntType),
- ReadyToRunHelper.ResolveInterfaceMethodFast => throw new NotImplementedException(
- $"{nameof(ReadyToRunHelper.ResolveInterfaceMethodFast)} is not implemented by the runtime."),
+ ReadyToRunHelper.ResolveInterfaceMethodFast => MakeSignature(nativeIntType, objectType, nativeIntType),
ReadyToRunHelper.InterfaceDispatch or
ReadyToRunHelper.InterfaceDispatchGuarded => null,
From 83e8a1119655e32e4186508245a34d3ad5f6785c Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Mon, 30 Nov 2026 00:43:04 +0200
Subject: [PATCH 3/6] Run the test on Apple mobile as well
---
.../SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
index d1900cd9d0b0fe..fae7adab8d0515 100644
--- a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
+++ b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
@@ -2,7 +2,6 @@
Exe
0
- true
true
false
From b1698bcdc95b31731e158fd1ab6513907779b7b3 Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Mon, 30 Nov 2026 00:52:33 +0200
Subject: [PATCH 4/6] Make the test a regular regression test
---
.../coreclr/GitHub_138481/test138481.cs | 59 +++++++++++++++++++
.../coreclr/GitHub_138481/test138481.csproj | 8 +++
.../DispatchSlowFunclet.cs | 47 ---------------
.../DispatchSlowFunclet.csproj | 11 ----
4 files changed, 67 insertions(+), 58 deletions(-)
create mode 100644 src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
create mode 100644 src/tests/Regressions/coreclr/GitHub_138481/test138481.csproj
delete mode 100644 src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
delete mode 100644 src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
diff --git a/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs b/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
new file mode 100644
index 00000000000000..4cbeeaa091fbfa
--- /dev/null
+++ b/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using Xunit;
+
+// On x86, the NativeAOT interface dispatch slow path could not unwind into funclets since it does not know the size
+// of the callee-popped arguments, so a GC while resolving an interface call in a catch corrupted the stack walk.
+public class Runtime_138481
+{
+ private interface IManyArgs
+ {
+ int Sum(int a, int b, int c, int d, int e, int f);
+ }
+
+ [DynamicInterfaceCastableImplementation]
+ private interface IManyArgsImpl : IManyArgs
+ {
+ int IManyArgs.Sum(int a, int b, int c, int d, int e, int f) => a + b + c + d + e + f;
+ }
+
+ private sealed class Castable : IDynamicInterfaceCastable
+ {
+ public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle interfaceType)
+ {
+ GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
+ return typeof(IManyArgsImpl).TypeHandle;
+ }
+
+ public bool IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) => true;
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static IManyArgs Get() => (IManyArgs)(object)new Castable();
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void Throw() => throw new InvalidOperationException();
+
+ [Fact]
+ public static void InterfaceCallInCatch()
+ {
+ int sum = 0;
+ for (int i = 0; i < 8; i++)
+ {
+ try
+ {
+ Throw();
+ }
+ catch (InvalidOperationException)
+ {
+ sum += Get().Sum(1, 2, 3, 4, 5, 6);
+ }
+ }
+
+ Assert.Equal(8 * 21, sum);
+ }
+}
diff --git a/src/tests/Regressions/coreclr/GitHub_138481/test138481.csproj b/src/tests/Regressions/coreclr/GitHub_138481/test138481.csproj
new file mode 100644
index 00000000000000..5ad9a2d72a5f3a
--- /dev/null
+++ b/src/tests/Regressions/coreclr/GitHub_138481/test138481.csproj
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
deleted file mode 100644
index 60798bc3dcdb1b..00000000000000
--- a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-interface IManyArgs { int Sum(int a, int b, int c, int d, int e, int f); }
-
-[DynamicInterfaceCastableImplementation]
-interface IManyArgsImpl : IManyArgs
-{
- int IManyArgs.Sum(int a, int b, int c, int d, int e, int f) => a + b + c + d + e + f;
-}
-
-sealed class Castable : IDynamicInterfaceCastable
-{
- public static int Resolutions;
-
- // Called from the dispatch slow path (RhpInterfaceDispatchSlow -> RhpCidResolve).
- public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle t)
- {
- Resolutions++;
- GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
- return typeof(IManyArgsImpl).TypeHandle;
- }
-
- public bool IsInterfaceImplemented(RuntimeTypeHandle t, bool throwIfNotImplemented) => true;
-}
-
-static class Program
-{
- [MethodImpl(MethodImplOptions.NoInlining)] static IManyArgs Get() => (IManyArgs)(object)new Castable();
- [MethodImpl(MethodImplOptions.NoInlining)] static void Throw() => throw new InvalidOperationException();
-
- static int Main(string[] args)
- {
- int sum = 0;
- for (int i = 0; i < 8; i++)
- {
- try { Throw(); }
- catch (InvalidOperationException) { sum += Get().Sum(1, 2, 3, 4, 5, 6); }
- }
- Console.WriteLine($"sum={sum} resolutions={Castable.Resolutions}");
- return sum == 8 * 21 ? 100 : 1;
- }
-}
diff --git a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj b/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
deleted file mode 100644
index fae7adab8d0515..00000000000000
--- a/src/tests/nativeaot/SmokeTests/DispatchSlowFunclet/DispatchSlowFunclet.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- Exe
- 0
- true
- false
-
-
-
-
-
From 838d1387069c98c917291fe568b3540c1ea22339 Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:29:54 +0200
Subject: [PATCH 5/6] Add repro for pending GC args across interface dispatch
Co-authored-by: Cursor
---
.../coreclr/GitHub_138481/test138481.cs | 51 ++++++++++++++++++-
1 file changed, 49 insertions(+), 2 deletions(-)
diff --git a/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs b/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
index 4cbeeaa091fbfa..c0f93c8eca4b62 100644
--- a/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
+++ b/src/tests/Regressions/coreclr/GitHub_138481/test138481.cs
@@ -6,8 +6,9 @@
using System.Runtime.InteropServices;
using Xunit;
-// On x86, the NativeAOT interface dispatch slow path could not unwind into funclets since it does not know the size
-// of the callee-popped arguments, so a GC while resolving an interface call in a catch corrupted the stack walk.
+// On x86, the NativeAOT interface dispatch slow path unwinds to the caller with an SP that does not account for the
+// callee-popped arguments of the interface method. A GC while resolving the interface call then corrupted the stack
+// walk when the caller was a funclet, or misreported pending pushed GC ref arguments in partially interruptible code.
public class Runtime_138481
{
private interface IManyArgs
@@ -26,18 +27,55 @@ private sealed class Castable : IDynamicInterfaceCastable
public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle interfaceType)
{
GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
+
+ // Reuse the memory of anything that was not reported so that a stale reference is visible.
+ for (int i = 0; i < 1000; i++)
+ s_junk[i % s_junk.Length] = new long[] { -1, -1, -1, -1 };
+
return typeof(IManyArgsImpl).TypeHandle;
}
public bool IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) => true;
}
+ private static object[] s_junk = new object[64];
+
+ private sealed class Payload
+ {
+ public int Magic;
+ public Payload(int magic) => Magic = magic;
+ }
+
+ private const int ExpectedMagic = 0x12345678;
+
[MethodImpl(MethodImplOptions.NoInlining)]
private static IManyArgs Get() => (IManyArgs)(object)new Castable();
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Throw() => throw new InvalidOperationException();
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static Payload MakePayload() => new Payload(ExpectedMagic);
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static int Outer(int a, int b, Payload obj, int sum)
+ {
+ if (obj.GetType() != typeof(Payload) || obj.Magic != ExpectedMagic)
+ {
+ Console.WriteLine($"Bad payload: magic=0x{obj.Magic:X}");
+ return -1;
+ }
+ return a + b + sum;
+ }
+
+ // Partially interruptible, no EH, no loops. `obj` is pushed on the stack for Outer
+ // before the nested interface call is made.
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static int Caller()
+ {
+ return Outer(1, 2, MakePayload(), Get().Sum(1, 2, 3, 4, 5, 6));
+ }
+
[Fact]
public static void InterfaceCallInCatch()
{
@@ -56,4 +94,13 @@ public static void InterfaceCallInCatch()
Assert.Equal(8 * 21, sum);
}
+
+ [Fact]
+ public static void InterfaceCallWithPendingGcArg()
+ {
+ for (int i = 0; i < 8; i++)
+ {
+ Assert.Equal(3 + 21, Caller());
+ }
+ }
}
From cb0a85d425fa6b203b6e2260175e8c0e3c9defec Mon Sep 17 00:00:00 2001
From: am11 <3840695+am11@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:31:20 +0200
Subject: [PATCH 6/6] Resolve all interface calls on x86 with a helper
The interface dispatch slow path does not know the size of the
callee-popped arguments, so it cannot unwind to the caller correctly
outside funclets either: pending pushed GC refs of an outer call in
partially interruptible code were misreported.
Co-authored-by: Cursor
---
src/coreclr/jit/importer.cpp | 7 +------
src/coreclr/jit/importercalls.cpp | 18 +-----------------
.../JitInterface/CorInfoImpl.RyuJit.cs | 10 ++++++----
3 files changed, 8 insertions(+), 27 deletions(-)
diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp
index 9b2e8ae8fb95f4..4507bd9e432155 100644
--- a/src/coreclr/jit/importer.cpp
+++ b/src/coreclr/jit/importer.cpp
@@ -2704,13 +2704,8 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr,
call = gtNewVirtualFunctionLookupHelperCallNode(CORINFO_HELP_GVMLOOKUP_FOR_SLOT, TYP_I_IMPL, thisPtr,
dispatchCell);
}
-#ifdef TARGET_WASMARCH
- else if (IsNativeAot() && isInterface)
-#elif defined(TARGET_X86)
- // Interface calls in funclets, see impImportCall
- else if (IsNativeAot() && isInterface && (pCallInfo->kind == CORINFO_VIRTUALCALL_STUB))
-#endif
#if defined(TARGET_WASMARCH) || defined(TARGET_X86)
+ else if (IsNativeAot() && isInterface)
{
GenTree* dispatchCell = impLookupToTree(&pCallInfo->codePointerLookup, GTF_ICON_GLOBAL_PTR, nullptr);
if (dispatchCell == nullptr)
diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp
index 36bd64be654eef..3b7157677d1fd6 100644
--- a/src/coreclr/jit/importercalls.cpp
+++ b/src/coreclr/jit/importercalls.cpp
@@ -502,23 +502,7 @@ var_types Compiler::impImportCall(OPCODE opcode,
exactContextHnd = callInfo->contextHandle;
exactContextNeedsRuntimeLookup = callInfo->exactContextNeedsRuntimeLookup;
- CORINFO_CALL_KIND callKind = callInfo->kind;
-
-#ifdef TARGET_X86
- // The interface dispatch slow path cannot unwind into funclets on x86 since it does not know the size of the
- // callee-popped arguments. Resolve the target from the dispatch cell with a helper call instead.
- if ((callKind == CORINFO_VIRTUALCALL_STUB) && IsNativeAot() &&
- (compIsForInlining() ? impInlineInfo->iciBlock : compCurBB)->hasHndIndex())
- {
- callKind = CORINFO_VIRTUALCALL_LDVIRTFTN;
- if (!callInfo->stubLookup.lookupKind.needsRuntimeLookup)
- {
- callInfo->stubLookup.constLookup.accessType = IAT_VALUE;
- }
- }
-#endif
-
- switch (callKind)
+ switch (callInfo->kind)
{
case CORINFO_VIRTUALCALL_STUB:
{
diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs
index d720daaaf2a8b9..973649ddfd9e0a 100644
--- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs
+++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs
@@ -1612,8 +1612,10 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
&& ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) == 0
|| _compilation.TypeSystemContext.Target.Architecture == TargetArchitecture.Wasm32))
{
- bool isWasm = _compilation.TypeSystemContext.Target.Architecture == TargetArchitecture.Wasm32;
- pResult->kind = isWasm
+ // On x86, the interface dispatch slow path cannot unwind to the caller since it does not know the size of
+ // the callee-popped arguments, so the target is resolved with a helper call instead.
+ bool resolveWithHelper = _compilation.TypeSystemContext.Target.Architecture is TargetArchitecture.Wasm32 or TargetArchitecture.X86;
+ pResult->kind = resolveWithHelper
? CORINFO_CALL_KIND.CORINFO_VIRTUALCALL_LDVIRTFTN
: CORINFO_CALL_KIND.CORINFO_VIRTUALCALL_STUB;
@@ -1630,7 +1632,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
{
pResult->codePointerOrStubLookup.lookupKind.needsRuntimeLookup = false;
pResult->codePointerOrStubLookup.constLookup.accessType =
- isWasm ? InfoAccessType.IAT_VALUE : InfoAccessType.IAT_PVALUE;
+ resolveWithHelper ? InfoAccessType.IAT_VALUE : InfoAccessType.IAT_PVALUE;
#pragma warning disable SA1001, SA1113, SA1115 // Commas should be spaced correctly
pResult->codePointerOrStubLookup.constLookup.addr = (void*)ObjectToHandle(
_compilation.NodeFactory.DispatchCell(targetMethod
@@ -1641,7 +1643,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
#pragma warning restore SA1001, SA1113, SA1115 // Commas should be spaced correctly
}
- pResult->nullInstanceCheck = isWasm;
+ pResult->nullInstanceCheck = resolveWithHelper;
}
else if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) == 0)
{