-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove shared IL stubs for P/Invokes. #117901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove shared IL stubs for P/Invokes. #117901
Conversation
|
@kg @janvorli This is a simple change that removes the shared IL stubs and use of the secret argument for P/Invokes. This isn't something that would go in until .NET 11, but might be sufficient to prototype P/Invokes via the interpreter. A follow-up approach would be to remove the use of IL Stubs entirely and rely on the transient code pattern. Using the transient code pattern proved to be a bit more work thant I'd anticipated so I reduced it to this approach. /cc @jkotas |
|
There is more cleanup that should be done as part of this:
|
Yep. This was a quick and dirty solution I could pass off to the interpreter team. |
Done.
Inserted a
Removed the PInvoke check.
Usage is blocked by |
If I am reading the code correctly, runtime/src/coreclr/vm/stackwalk.cpp Line 3030 in 2db9fdf
|
This removes usage of the secret argument in P/Invokes. It also removes all usage of shared IL stubs.
3c29ece to
2b6f869
Compare
You're right. I don't know the best way to do this. I suppose I could get the target from the |
|
I think it would best to minimize stackwalker dependencies if possible. Can we get runtime/src/coreclr/jit/lower.cpp Lines 6595 to 6612 in 97d9422
It is also going to fix a type mismatch: |
Sure, I can give that a shot. This doesn't ever appear to be set for coreclr JIT, the runtime/src/coreclr/vm/jitinterface.cpp Lines 10455 to 10473 in 97d9422
Side note, I've really got no idea what is expected here. All of this is a huge confusion about various states of fields and very loosely typed in practice. I'm really just randomly guessing what things are expected at this point, sorry. |
|
My confusion here is about |
instead of the IL Stub's DynamicMethodDesc.
src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes shared IL stubs for P/Invokes except for CALLI instructions. The primary objective is to eliminate the use of secret arguments in P/Invoke stubs while maintaining sharing only for CALLI scenarios.
Key changes:
- Removes secret argument handling from P/Invoke IL stubs
- Updates VarargPInvokeStubWorker to take fewer parameters
- Modifies stub sharing logic to exclude forward P/Invokes (except CALLI)
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/stubmgr.h | Adds new GetFirstArg method and refactors GetThisPtr to use it |
| src/coreclr/vm/stubmgr.cpp | Updates logging format specifiers and removes P/Invoke handling from IL stub tracing |
| src/coreclr/vm/stackwalk.cpp | Moves variable declaration closer to usage |
| src/coreclr/vm/prestub.cpp | Removes precompiled IL stub sharing for P/Invokes and updates assertion logic |
| src/coreclr/vm/method.hpp | Renames RequiresMethodDescCallingConvention to RequiresMDContextArg and updates related methods |
| src/coreclr/vm/method.cpp | Implements renamed methods and removes P/Invoke context argument requirements |
| src/coreclr/vm/jitinterface.cpp | Adds P/Invoke method descriptor to VASigCookie creation |
| src/coreclr/vm/i386/asmhelpers.asm | Reduces parameter count for VarargPInvokeStubWorker call |
| src/coreclr/vm/i386/asmhelpers.S | Removes unused parameter from assembly stub |
| src/coreclr/vm/frames.h | Updates comments to clarify PInvokeMethodDesc usage |
| src/coreclr/vm/dynamicmethod.cpp | Updates method name calls to use new convention |
| src/coreclr/vm/dllimport.h | Adds shared stub flag and reorganizes stub checking logic |
| src/coreclr/vm/dllimport.cpp | Major refactoring of P/Invoke stub generation to remove secret argument usage |
| src/coreclr/vm/comdelegate.cpp | Removes redundant MethodDesc qualification |
| src/coreclr/vm/codeman.h | Converts CodeHeapRequestInfo to proper class with encapsulated members |
| src/coreclr/vm/codeman.cpp | Updates to use new CodeHeapRequestInfo interface and improves method descriptor handling |
| src/coreclr/vm/cgensys.h | Updates VarargPInvokeStubWorker signature |
| src/coreclr/vm/ceeload.h | Adds MethodDesc field to VASigCookie and improves encapsulation |
| src/coreclr/vm/ceeload.cpp | Refactors VASigCookie creation to embed MethodDesc and use loader allocator |
| src/coreclr/vm/amd64/pinvokestubs.S | Removes unused parameter from stub worker call |
| src/coreclr/vm/amd64/PInvokeStubs.asm | Removes unused parameter from stub worker call |
Comments suppressed due to low confidence (1)
src/coreclr/vm/method.cpp:1
- The removal of the fEstimateForChunk parameter and related logic eliminates the interface check optimization that was previously guarded by the parameter. This may impact performance for interface method processing during chunk estimation.
// Licensed to the .NET Foundation under one or more agreements.
GCStress is not able to find the original version of the code for PInvoke stubs after dotnet#117901. We need to compensate for the MethodDesc adjustment done for PInvoke stubs when storing the original version of the code during GC stress.
Interop marshalling of varargs needs MethodDesc calling convention to support ldftn <PInvoke method with varargs>. It is not possible to smugle the target MethodDesc* via vararg cookie in this case.
GCStress is not able to find the original version of the code for PInvoke stubs after dotnet#117901. We need to compensate for the MethodDesc adjustment done for PInvoke stubs when storing the original version of the code during GC stress.
Interop marshalling of varargs needs MethodDesc calling convention to support ldftn <PInvoke method with varargs>. It is not possible to smugle the target MethodDesc* via vararg cookie in this case.
GCStress is not able to find the original version of the code for PInvoke stubs after dotnet#117901. We need to compensate for the MethodDesc adjustment done for PInvoke stubs when storing the original version of the code during GC stress.
Interop marshalling of varargs needs MethodDesc calling convention to support ldftn <PInvoke method with varargs>. It is not possible to smugle the target MethodDesc* via vararg cookie in this case.
* Fix GCStress regression GCStress is not able to find the original version of the code for PInvoke stubs after #117901. We need to compensate for the MethodDesc adjustment done for PInvoke stubs when storing the original version of the code during GC stress. * Partial revert of #117901 for vararg stubs Interop marshalling of varargs needs MethodDesc calling convention to support ldftn <PInvoke method with varargs>. It is not possible to smuggle the target MethodDesc* via vararg cookie in this case. Co-authored-by: Aaron Robinson <arobins@microsoft.com>
This removes usage of the secret argument in P/Invokes. It removes sharing for all P/Invoke IL stubs except CALLI.
Depends on #118462