Skip to content
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

Fix incorrect assumption around the presence of ICF frames in EH codebase for 64-bit targets #34526

Merged
merged 1 commit into from
Apr 6, 2020

Conversation

fadimounir
Copy link
Contributor

Fix for #34524.

The main issue here is a disconnect between what the JIT produces, and the assumption we had around it in the EH code:
https://github.com/dotnet/runtime/blob/master/src/coreclr/src/vm/exceptionhandling.cpp#L1824

Clearly this is not what the JIT does:
https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/lower.cpp#L3497

This means that it is not correct to limit this define to only 32-bit targets:
https://github.com/dotnet/runtime/blob/master/src/coreclr/src/vm/exceptionhandling.h#L16

To fix this issue, we should have one standard for all targets (which is the case today anyways): The ICF is always initialized and linked in the prolog of any method that contains PInvokes, and unlinked at the method epilog for jitted code (R2R is a slightly different story)

@jkotas
Copy link
Member

jkotas commented Apr 3, 2020

The ICF is always initialized and linked in the prolog of any method that contains PInvokes, and unlinked at the method epilog for jitted code (R2R is a slightly different story)

I thought that we agree on that link / unlink around PInvoke is the right thing to standardize on (ie same as R2R).

We can initialize the frame in the prolog or right before the PInvoke, but that is just a local detail - it does not affect how exception handling works.

@@ -13,10 +13,6 @@
#include "eexcp.h"
#include "exstatecommon.h"

#if defined(TARGET_ARM) || defined(TARGET_X86)
#define USE_PER_FRAME_PINVOKE_INIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need matching changes in the JIT as well. You should see a functional test failures without matching changes in the JIT.

Copy link
Contributor Author

@fadimounir fadimounir Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JIT today links/unlinks the ICF in the method prolog/epilog, and activates/deactivates the ICF around the pinvoke call. It does this for both 32-bits and 64-bits. The fix here is to match the behavior in the EH codebase.

@jkotas jkotas requested a review from janvorli April 3, 2020 23:43
@janvorli
Copy link
Member

janvorli commented Apr 3, 2020

I thought that we agree on that link / unlink around PInvoke is the right thing to standardize on (ie same as R2R).

I would also prefer that. The presence of linked but inactive InlinedCallFrame is just confusing.

@fadimounir
Copy link
Contributor Author

fadimounir commented Apr 3, 2020

As a second step after this fix is in, I can look into merging the linking+activation in one step around the pinvoke call (this will match the behavior of R2R code as well), but that would be a slightly bigger change I believe. At this point, I want to fix the bug first (to also unblock my other PR that is failing with gcstress runs because of this).

Should be an easy JIT change, but there's a lot of places on the runtime side I've seen where the assumption of disconnected linking/activation is baked in, and that will be a bigger change

@fadimounir
Copy link
Contributor Author

gcstress results are comparable to a baseline I ran a few days ago: https://dev.azure.com/dnceng/public/_build/results?buildId=582616&view=ms.vss-test-web.build-test-results-tab

We can merge these changes at this point to unblock #33733, then I'll make the changes to activate+link the ICF around the pinvoke calls.

@jkotas @janvorli Does this plan sound good?

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

@fadimounir fadimounir merged commit 59ca590 into dotnet:master Apr 6, 2020
@fadimounir fadimounir deleted the FixEHAroundICF branch April 15, 2020 19:43
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants