-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Ensure all types are loaded when methods are accessed as function pointers #62158
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
Conversation
|
The change is fixing the GC stress crash. On a second thought, I am wondering whether we want to make this work; or whether we should declare this invalid code and fix the test instead (e.g. by passing the struct by reference). If we decide to make this work, I think there are more places that will need the same fix. @davidwrighton Could you please take a look and share your opinion? The problem is:
This fails under GC stress with "valuetype type not loaded" crash when we are in the prestub of the function. |
|
Type punning like this isn't something that we generally support throughout the runtime, but we do support it as part of type equivalence. So, at the very minimum, we need to have the valuetypes loaded eagerly if the function pointer utilizes any type equivalent types, so a fix here is needed to some extent. However, the fix as written makes me uncomfortable in several ways.
OTOH, type punning of this form is likely common in C++/CLI and the fact that we still have this issue is likely indicative of a lack of GC stress testing on complex C++/CLI scenarios. I think we should either scale back the fix to only cover type equivalent structures, or go the extra mile to make sure that ldftn and ldvirtftn instructions when not paired with a delegate allocation force the more complete parameter type load. Scaling back could be done by just calling Also, this should be tested with a type system test which is explicitly testing this, not an artifact of the COM test suite. I'd like to know if we really need this construct of type punning to use the COM api, or if something else is going on here. |
|
@AaronRobinsonMSFT As a set of tests covering the type punning scenarios, that looks good. Please don't check in until we conclude we actually want to support punning. |
|
An outstanding case is when It would be helpful if someone from the @dotnet/jit-contrib could provide some guidance on how one could detect the runtime/src/coreclr/jit/importer.cpp Lines 14605 to 14624 in 70d20f1
|
# Conflicts: # src/coreclr/tools/Common/JitInterface/CorInfoBase.cs
|
@davidwrighton I've pushed up all the tests for this scenario. The failing scenario was only occurring during a GCStress run so in order to confirm that needs to happen. I believe this PR is now in a good state. and can be merged unless there are further JIT or Type system concerns. |
AndyAyersMS
left a comment
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.
LGTM.
|
Does the fix work for crossgen/R2R? |
No. That needs to be looked at. @davidwrighton is going to pick this up next week. I might look into this weekend if I have time. |
|
@jkotas Is there an example in CrossGen2 that I could look at that would help me to understand how to fix this there? I assume I need some new helper to call prior to the PreStub being executed. |
|
@AaronRobinsonMSFT looks like there's a sample using the old runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs Line 1832 in f754496
Maybe you could add the checks in |
|
@jkoritzinsky Thanks. That helped and I was able to get runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs Lines 1877 to 1884 in f754496
I am trying to figure out why. I don't see the JIT involved at all during run-time so I am confused. I could be not understanding how to debug this though. |
|
@jkoritzinsky Oops. Wrong. I misread that |
|
Thanks @jkoritzinsky ! That worked and was simple to follow. @jkotas and @davidwrighton The tests now pass under CrossGen/R2R. @dotnet/crossgen-contrib Please take a look at the CrossGen changes and let me know if there is a better way. |
davidwrighton
left a comment
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.
Please look into the scenario of using ldftn involving type punning with a virtual method.
|
@davidwrighton Please take another look. I added a test for using |
Fixes #62067
This issue was occurring due to Type punning using C# function pointers. Consider the following where using a function pointer can circumvent type safety. Using function pointers enables a vast array of scenarios where type loading can occur at invalid times. This PR handles cases involving Type Equivalence, direct
ldftnandldvirtftn, indirectldftnandldvirtftnviaDelegateactivation, and scenarios involving Generics./cc @jkotas @davidwrighton @AndyAyersMS @jkoritzinsky @elinor-fung