Skip to content

[release/10.0] JIT: Use r9,r10 for GS cookie check in Swift reverse pinvokes#120744

Closed
jakobbotsch wants to merge 1 commit into
dotnet:release/10.0from
jakobbotsch:fix-swift-reg-10.0
Closed

[release/10.0] JIT: Use r9,r10 for GS cookie check in Swift reverse pinvokes#120744
jakobbotsch wants to merge 1 commit into
dotnet:release/10.0from
jakobbotsch:fix-swift-reg-10.0

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Oct 15, 2025

Copy link
Copy Markdown
Member

Customer Impact

  • Customer reported
  • Found internally

The JIT corrupts return values from x64 Swift reverse pinvokes when 4 registers are used to return in if the method simultaneously uses unsafe value types that induce a GS cookie check.

Regression

  • Yes
  • No

Introduced by #119864.

Testing

Internal stress testing (that forces GS cookie check) caught this in our existing Swift tests.

Risk

Low. Change only affects Swift reverse pinvokes with GS cookie checks.

Swift returns values in r8, so it cannot be used for the cookie check.
Switch it to r9,r10 instead.
Copilot AI review requested due to automatic review settings October 15, 2025 11:40
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 15, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a regression in the JIT compiler where return values from Swift reverse pinvokes were corrupted when 4 registers were used for return values and the method required a GS (Guard Stack) cookie check. The fix changes the registers used for GS cookie checks in Swift calling convention from R8/R9 to R9/R10, avoiding conflicts with Swift return value registers.

  • Updates register allocation for GS cookie checks in Swift calling convention
  • Prevents corruption of Swift reverse pinvoke return values when using unsafe code

Comment thread src/coreclr/jit/codegenxarch.cpp
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@jakobbotsch jakobbotsch requested review from a team and VSadov October 15, 2025 11:50
@JulieLeeMSFT JulieLeeMSFT added the Servicing-consider Issue for next servicing release review label Oct 15, 2025
@LoopedBard3

LoopedBard3 commented Oct 28, 2025

Copy link
Copy Markdown
Member

Closing in favor of: dotnet/performance#5024 Sorry, updated incorrect PR.

@PranavSenthilnathan

Copy link
Copy Markdown
Member

Since this PR is targeting release/10.0, this is a reminder that code complete is Monday November 17. If you want the changes in the PR in the release, please merge it on time.

@jakobbotsch

Copy link
Copy Markdown
Member Author

Won't push this for servicing given Swift reverse pinvoke + GS cookie check + macOS x64 requirements, and no customer reports.

@github-actions github-actions Bot locked and limited conversation to collaborators Dec 18, 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 Servicing-consider Issue for next servicing release review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants