Skip to content

Cranelift: Adjust virtual SP after tail call-conv callees return #6586

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

Merged
merged 2 commits into from
Jun 16, 2023

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Jun 15, 2023

Callees that use the tail calling convention will pop stack arguments from the stack for their callers. They do not, however, adjust the caller's virtual SP, so that still needs to happen in our ABI and CallSite code. This is, however, slightly trickier than just emitting a nominal SP adjustment pseudo-instruction because we cannot let regalloc attempt to spill or reload values between the call and the SP adjustment because the stack offsets will be off by the size of the stack arguments to the call. Therefore, we add the number of bytes that the callee pops to the CallInfo structures and have emission update the virtual SP atomically with regards to the call itself.

Fixes #6581
Fixes #6582

@fitzgen fitzgen requested a review from a team as a code owner June 15, 2023 21:12
@fitzgen fitzgen requested review from abrown and removed request for a team June 15, 2023 21:12
@fitzgen fitzgen force-pushed the call-pop-virtual-sp branch from b20b4cb to b2e56a0 Compare June 15, 2023 21:21
@fitzgen fitzgen requested review from cfallin and removed request for abrown June 15, 2023 21:27
Callees that use the `tail` calling convention will pop stack arguments from the
stack for their callers. They do not, however, adjust the caller's virtual SP,
so that still needs to happen in our ABI and `CallSite` code. This is, however,
slightly trickier than just emitting a nominal SP adjustment pseudo-instruction
because we cannot let regalloc attempt to spill or reload values between the
call and the SP adjustment because the stack offsets will be off by the size of
the stack arguments to the call. Therefore, we add the number of bytes that the
callee pops to the `CallInfo` structures and have emission update the virtual SP
atomically with regards to the call itself.

Fixes bytecodealliance#6581
Fixes bytecodealliance#6582

Co-Authored-By: Jamey Sharp <[email protected]>
@fitzgen fitzgen force-pushed the call-pop-virtual-sp branch from b2e56a0 to 5a10b14 Compare June 15, 2023 21:29
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen winch Winch issues or pull requests labels Jun 15, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @saulecabrera

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:area:machinst", "cranelift:area:x64", "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@fitzgen
Copy link
Member Author

fitzgen commented Jun 15, 2023

Added support for tail to fuzzgen, and I've been fuzzing locally and haven't found any more bugs yet.

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Looks right to me! Just one nit below.

@fitzgen fitzgen added this pull request to the merge queue Jun 16, 2023
Merged via the queue into bytecodealliance:main with commit 9a67597 Jun 16, 2023
@fitzgen fitzgen deleted the call-pop-virtual-sp branch June 16, 2023 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cranelift: Segmentation fault on x64 with tail calling convetion Cranelift: Wrong result for function with tail calling convetion on AArch64
3 participants