Fix missing case for function pointer signatures in Crossgen2 - #73341
Conversation
As Andy Ayers suggested in the issue dotnet#72822 and I confirmed, Crossgen2 signature emitter was missing the code path for emitting function pointer signatures. This change fixes this deficiency. The change also removes the issues.targets exclusion of the affected test that Andy originally merged in to mitigate the issue. Thanks Tomas
|
|
||
| if ((type.Signature.Flags & MethodSignatureFlags.Static) == 0) | ||
| { | ||
| callingConvention |= CorCallingConvention.IMAGE_CEE_CS_CALLCONV_HASTHIS | CorCallingConvention.IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS; |
There was a problem hiding this comment.
Is IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS right here?
There was a problem hiding this comment.
Hmm, that's exactly what I'm trying to get my head around. I believe that ECMA managed method signatures do include the this pointer so I would assume it's explicit but I may be misunderstanding the purpose of the flag, it's not used very broadly in the CoreCLR native runtime.
There was a problem hiding this comment.
The MethodSignature initialization only uses HasThis to initialize the Static bit:
runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaSignatureParser.cs
Lines 399 to 400 in 83bd401
so the reverse should do the same.
If we need to preserve HasExplicitThis too (I do not think we need to), we would need to store it in MethodSignature.
There was a problem hiding this comment.
Based on your clarification I have removed the ExplicitThis flag when emitting the non-static function pointer signatures.
There was a problem hiding this comment.
I am still not sure about the ExplicitThis. I have looked into it some more and I think we should probably store it on MethodSignature when we are initializing it from Ecma metadata, store it here; and also send it to the JIT so that the JIT can do the right thing with it.
There was a problem hiding this comment.
We have number of IL tests that exercise explicit this (look for "explicit instance" in *.il under tests). I am surprised that none of them fails.
There was a problem hiding this comment.
Ack, yes, we should handle explicitthis, although fixing all the places that work with that may be beyond the scope of what we should try to fix with this PR. I think it will likely be a fairly large fix to a bunch of places unrelated to the general thrust of the code written here.
There was a problem hiding this comment.
I have created a .NET 8 tracking issue for this task, #73407.
FWIW, the type system takes the casting shortcut: runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaSignatureParser.cs Lines 389 to 394 in 83bd401 |
I have reverted the additions to CorConstants and modified the code to use the constants in System.Reflection.Metadata. I have removed the flag translation based on Jan's confirmation that the calling convention part of MethodSignatureFlags is indeed kept in sync with the CoreCLR native runtime calling conventions and I dropped the explicit this flag. Thanks Tomas
davidwrighton
left a comment
There was a problem hiding this comment.
I believe we should probably fix the explicit this problem, but I'd like to see such a fix done as part of fixing explicit this throughout our product, not just in this situation.
|
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
As Andy Ayers conjectured in the issue #72822 and I confirmed,
Crossgen2 signature emitter was missing the code path for
emitting function pointer signatures. This change fixes this
deficiency. The change also removes the issues.targets exclusion
of the affected test that Andy originally merged in to mitigate
the issue.
Thanks
Tomas
P.S. Even though MethodSignatureFlags more or less corresponds
to CoreCLR runtime calling convention, I have ignored this fact
and implemented an explicit conversion as I find it cleaner, please
let me know if you think otherwise. I would also appreciate
double-checking of the logic around Static vs. HASTHIS as I'm not
completely sure about the exact interpretation of this runtime flag.
/cc @dotnet/crossgen-contrib
Fixes: #72822