Skip to content

Conversation

filipnavara
Copy link
Member

The restoring of stack pointer is handled by EECodeManager::GetResumeSp (CoreCLR on linux-x86) and ResumeSp in context (NativeAOT on win-x86). We are short on registers on x86 so ECX is not used and it was unnecessarily set to a value.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 22, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo
Copy link
Member

EgorBo commented Mar 24, 2025

@dotnet/jit-contrib can someone take a look?

@filipnavara
Copy link
Member Author

For reference, here's the x64 ABI:

* Generates code for an EH funclet prolog.
*
* Funclets have the following incoming arguments:
*
* catch/filter-handler: rcx = InitialSP, rdx = the exception object that was caught (see GT_CATCH_ARG)
* filter: rcx = InitialSP, rdx = the exception object to filter (see GT_CATCH_ARG)
* finally/fault: rcx = InitialSP
*
* Funclets set the following registers on exit:
*
* catch/filter-handler: rax = the address at which execution should resume (see BBJ_EHCATCHRET)
* filter: rax = non-zero if the handler should handle the exception, zero otherwise (see GT_RETFILT)
* finally/fault: none
*

and here's the x86 ABI:

* Generates code for an EH funclet prolog.
*
*
* Funclets have the following incoming arguments:
*
* catch/filter-handler: eax = the exception object that was caught (see GT_CATCH_ARG)
* filter: eax = the exception object that was caught (see GT_CATCH_ARG)
* finally/fault: none
*
* Funclets set the following registers on exit:
*
* catch/filter-handler: eax = the address at which execution should resume (see BBJ_EHCATCHRET)
* filter: eax = non-zero if the handler should handle the exception, zero otherwise (see GT_RETFILT)
* finally/fault: none
*
* Funclet prolog/epilog sequence and funclet frame layout are TBD.

@filipnavara
Copy link
Member Author

filipnavara commented Mar 30, 2025

On a second thought, we probably don't need to set the RCX on NativeAOT x64 ABI either. PSPSym is not used with NativeAOT ABI, so compiler->lvaPSPSym == BAD_VAR_NUM and hence the part of genFuncletProlog that uses RCX is never used with that ABI.

@davidwrighton davidwrighton requested a review from jkotas April 1, 2025 19:01
Copy link
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

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

Looks correct to me. @jkotas, do you agree?

@jkotas
Copy link
Member

jkotas commented Apr 1, 2025

PSPSym is not used with NativeAOT ABI, so compiler->lvaPSPSym == BAD_VAR_NUM and hence the part of genFuncletProlog that uses RCX is never used with that ABI.

Yes, I agree - it can be cleaned up separately.

@jkotas jkotas merged commit 327c262 into dotnet:main Apr 1, 2025
107 of 110 checks passed
@filipnavara filipnavara deleted the x86-funclet-abi-ecx branch April 2, 2025 19:56
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants