From: Fadi Hanna Date: Tue, 3 Dec 2019 04:56:43 +0000 (-0800) Subject: Fix inlining issue for raw pinvoke calls when using debug builds (#455) X-Git-Tag: submit/tizen/20210909.063632~10834 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bf3be8037bcd7dfdad4d158db23db86a1c2bae2;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix inlining issue for raw pinvoke calls when using debug builds (#455) * Fix inlining issue for raw pinvoke calls when using debug builds * Do not generate PInvoke stubs for cross-module pinvokes outside of version bubble --- diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 2e13643..c474744 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -6496,17 +6496,25 @@ void Compiler::impCheckForPInvokeCall( // inlining in CoreRT. Skip the ambient conditions checks and profitability checks. if (!IsTargetAbi(CORINFO_CORERT_ABI) || (info.compFlags & CORINFO_FLG_PINVOKE) == 0) { - if (!impCanPInvokeInline()) + if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB) && opts.ShouldUsePInvokeHelpers()) { - return; + // Raw PInvoke call in PInvoke IL stub generated must be inlined to avoid infinite + // recursive calls to the stub. } - - // Size-speed tradeoff: don't use inline pinvoke at rarely - // executed call sites. The non-inline version is more - // compact. - if (block->isRunRarely()) + else { - return; + if (!impCanPInvokeInline()) + { + return; + } + + // Size-speed tradeoff: don't use inline pinvoke at rarely + // executed call sites. The non-inline version is more + // compact. + if (block->isRunRarely()) + { + return; + } } } diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index fb1f990..bad1708 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -636,15 +636,8 @@ namespace Internal.JitInterface result |= CorInfoFlag.CORINFO_FLG_SHAREDINST; if (method.IsPInvoke) - { result |= CorInfoFlag.CORINFO_FLG_PINVOKE; - if (method.IsRawPInvoke()) - { - result |= CorInfoFlag.CORINFO_FLG_FORCEINLINE; - } - } - #if READYTORUN if (method.RequireSecObject) { diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunSingleAssemblyCompilationModuleGroup.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunSingleAssemblyCompilationModuleGroup.cs index a079c20..9778cc8 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunSingleAssemblyCompilationModuleGroup.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunSingleAssemblyCompilationModuleGroup.cs @@ -200,6 +200,11 @@ namespace ILCompiler Debug.Assert(method is EcmaMethod); + // If the PInvoke is declared on an external module, we can only compile it if + // that module is part of the version bubble. + if (!_versionBubbleModuleSet.Contains(((EcmaMethod)method).Module)) + return false; + if (((EcmaMethod)method).Module.Equals(method.Context.SystemModule)) return true;