-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[NativeAOT] Port x86 ResumeSP logic from CoreCLR #99866
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
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
src/coreclr/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp
Outdated
Show resolved
Hide resolved
This problem is specific to callee-pop calling convention. x86 is the only arch that uses callee-pop calling convention. |
I'm not sure how specifically it related to the callee-pop calling convention. We already handle that in unwinding with (Also, so far I was not able to reproduce the error on locally built binaries because they don't contain the "push 0" opcodes as in the original example, which I downloaded from CI build in Helix. I'll have to clean everything and try to build it from scratch on the same branch as the CI, something is odd there. I may have triggered some incorrect codegen by enabling |
The SP is constant throughout the main method body with caller pop (except for localloc). You never need to |
I do see the different approach in |
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.
cc @dotnet/jit-contrib for the JIT change
On x86 with funclets that's a scenario where exception can happen with argument registers pushed on the stack. One such case is in the
Invariant.Tests
's methodInvariant_Tests!Invariant_Tests_System_Globalization_Tests_InvariantModeTests__PredefinedCulturesOnly
:The exception is followed by calling a catch funclet and then jumping to the epilog of the main method. This currently fails on NativeAOT since there's no code that restores the correct SP for the epilog that accounts for the pushed arguments. On CoreCLR this is handled by the
EECodeManager::GetResumeSp
method and fixing up the context after calling the catch funclet and before proceeding to jump to the epilog.Following the CoreCLR method exactly is possible but not necessarily easy and efficient due to separation between managed and native code. In this PR I opted to save the ResumeSP in
StackFrameIterator
into separate field inREGDISPLAY
structure.RhCallCatchFunclet
reads the ResumeSP field instead of SP now.Additionally, this restores
locAllocSPvar
in the NativeAOT ABI to save the SP offset in methods that uselocalloc
. This is necessary to calculate the correct SP value after the catch block.