Skip to content

Commit

Permalink
Fix inlining issue for raw pinvoke calls when using debug builds (#455)
Browse files Browse the repository at this point in the history
* Fix inlining issue for raw pinvoke calls when using debug builds


* Do not generate PInvoke stubs for cross-module pinvokes outside of version bubble
  • Loading branch information
Fadi Hanna authored Dec 3, 2019
1 parent e9c34fa commit 1bf3be8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
24 changes: 16 additions & 8 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,8 @@ private uint getMethodAttribsInternal(MethodDesc method)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public override bool GeneratesPInvoke(MethodDesc method)

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;

Expand Down

0 comments on commit 1bf3be8

Please sign in to comment.