[clr-interp] Detect Swift calling convention for transient-IL P/Invokes#128257
Open
kotlarmilos wants to merge 1 commit into
Open
[clr-interp] Detect Swift calling convention for transient-IL P/Invokes#128257kotlarmilos wants to merge 1 commit into
kotlarmilos wants to merge 1 commit into
Conversation
After P/Invokes were converted to transient IL (dotnet#126509), the P/Invoke MethodDesc itself carries the IL with the calli to the native target. MethodDesc::IsILStub() returns true only for DynamicMethodDesc, so the Swift detection in CInterpreterJitInfo::GetCookieForInterpreterCalliSig from dotnet#125177 leaves pContextMD NULL for transient-IL P/Invokes. ComputeCallStub cannot then detect the Swift calling convention, never runs RewriteSignatureForSwiftLowering, and emits a stub that does not preserve x21. SwiftError is lost on return, and the multiple-SwiftError InvalidProgramException validation is skipped. Pass the method-being-compiled as pContextMD when it is a P/Invoke. The existing IsPInvoke branch in ComputeCallStub then resolves the unmanaged calling convention via PInvoke::GetCallingConvention_IgnoreErrors. Fixes dotnet#127897 Fixes dotnet#127898 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg |
Member
Author
|
/azp run runtime-interpreter |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CoreCLR interpreter calli-cookie generation so transient-IL P/Invokes provide their PInvokeMethodDesc as context to call-stub generation, allowing Swift calling-convention handling to work consistently with the earlier IL-stub path.
Changes:
- Preserves the existing IL-stub target MethodDesc context behavior.
- Adds P/Invoke MethodDesc context for transient-IL P/Invokes.
- Keeps calli-cookie generation uncached on the P/Invoke MethodDesc for unmanaged target calls.
Show a summary per file
| File | Description |
|---|---|
src/coreclr/vm/jitinterface.cpp |
Updates CInterpreterJitInfo::GetCookieForInterpreterCalliSig to pass P/Invoke context for transient-IL P/Invoke calli stubs. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#125177 implemented Swift calling convention detection in the interpreter's calli cookie generation. It inspects m_pMethodBeingCompiled->IsILStub() and walks the IL stub resolver to its StubTargetMethodDesc. This worked when forward P/Invokes were compiled as separate IL-stub DynamicMethodDescs.
#126509 changed P/Invoke compilation: the PInvokeMethodDesc itself now carries the transient IL with the calli to the native target. MethodDesc::IsILStub() returns true only for DynamicMethodDesc, so IsILStub() returns false for a transient-IL P/Invoke and pContextMD stays NULL.
With no context MD, CallStubGenerator::ComputeCallStub cannot enter either of its Swift detection branches. It falls through to the generic calling convention switch, leaves m_isSwiftCallConv = false, and:
Never calls RewriteSignatureForSwiftLowering, so the [ref SwiftError, ref SwiftError] validation never throws InvalidProgramException. Generates a generic stub that does not preserve x21 across the native call, so SwiftError is lost on return.
Fix
In CInterpreterJitInfo::GetCookieForInterpreterCalliSig, also pass the method being compiled as pContextMD when it is a P/Invoke. The IsPInvoke branch already in ComputeCallStub then detects the Swift calling convention via PInvoke::GetCallingConvention_IgnoreErrors.
Fixes #127897
Fixes #127898