Fix recursive inlining of PInvoke stubs (dotnet/coreclr#18737)
authorJan Kotas <jkotas@microsoft.com>
Sun, 1 Jul 2018 13:02:04 +0000 (06:02 -0700)
committerGitHub <noreply@github.com>
Sun, 1 Jul 2018 13:02:04 +0000 (06:02 -0700)
PInvoke stubs can be inlined into a regular methods in CoreRT. PInvoke transition
has to be inlined as well when that happens. Otherwise, there is a risk of recursive
inlining in corner cases.

Commit migrated from https://github.com/dotnet/coreclr/commit/55023b7c1007c528b0147fe839cea5ac4a100e2f

src/coreclr/src/jit/importer.cpp

index 8ec9303..6f6bd21 100644 (file)
@@ -6112,9 +6112,9 @@ void Compiler::impCheckForPInvokeCall(
             return;
         }
 
-        // PInvoke CALL in IL stubs must be inlined on CoreRT. Skip the ambient conditions checks and
-        // profitability checks
-        if (!(opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB) && IsTargetAbi(CORINFO_CORERT_ABI)))
+        // Legal PInvoke CALL in PInvoke IL stubs must be inlined to avoid infinite recursive
+        // inlining in CoreRT. Skip the ambient conditions checks and profitability checks.
+        if (!IsTargetAbi(CORINFO_CORERT_ABI) || (info.compFlags & CORINFO_FLG_PINVOKE) == 0)
         {
             if (!impCanPInvokeInline())
             {