Skip to content

ZJIT: A64 backend miscomp fixes (and a CI fix) #13904

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 6 commits into from
Jul 16, 2025

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Jul 16, 2025

I noticed that SP movement still weren't single instruction after my other
PR and that led me to find a few bugs.

Please check commit message for each.

  • ZJIT: Have make zjit-test use the same Cargo features as miniruby
    We should now be running the disassembly tests in the backend on CI.
  • ZJIT: A64: Fix asm.add_into(NATIVE_STACK_POINTER, ...)
    Probably the most important one because we use this for side exits.
  • ZJIT: A64: Fix the optimization merging asm.add(reg, imm) with Mov
  • ZJIT: A64: Fix bad operand swapping in asm.sub(imm, reg)

@matzbot matzbot requested a review from a team July 16, 2025 00:53

This comment has been minimized.

@XrXr XrXr force-pushed the zjit-test-cargo-feature-set branch from e1fa282 to 8090c2a Compare July 16, 2025 01:06
Copy link
Contributor

@tekknolagi tekknolagi left a comment

Choose a reason for hiding this comment

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

I don't know much about Arm but looks reasonable at first glance. Delegating to Kokubun

XrXr added 5 commits July 16, 2025 13:26
This is so that e.g. building with `--enable-zjit=dev` will test with the
disassembly feature. It makes more sense, saves on build time and
reveals that
`backend::arm64::tests::sp_movements_are_single_instruction` was in
fact failing with the `disasm` feature.
Previously, it issued CMN, which doesn't add to the stack pointer.
The raw bytes didn't disassemble to the disassembly, but we missed this
since CI didn't run `make zjit-test` with the disasm feature.

Fixes: 1317377 ("ZJIT: A64: Have add/sub to SP be
single-instruction")
Previously, my buggy optimization would turn `asm.sub(imm, reg)`
into `subs out, reg, imm` since it runs through the addition path which
relies on the commutative property. Don't do that because subtraction
does not commute. Good thing no one seems to use this form.

Also, delete the 2 regs match arm for Add because it's already covered
by the fallback arm -- both split_load_operand() and
split_shifted_immediate() are no-op when the input is a register.

Fixes: 1317377 ("ZJIT: A64: Have add/sub to SP be
single-instruction")
The stack canary gets killed in test_yjit.rb:224 for some reason. Needs
investigation. Example CI failure:
https://github.com/ruby/ruby/actions/runs/16307837724/job/46057558066
@XrXr XrXr force-pushed the zjit-test-cargo-feature-set branch from 755220b to cd28885 Compare July 16, 2025 17:32
@XrXr XrXr enabled auto-merge (rebase) July 16, 2025 17:33
@XrXr XrXr merged commit ccbbe06 into ruby:master Jul 16, 2025
83 checks passed
@XrXr XrXr deleted the zjit-test-cargo-feature-set branch July 16, 2025 18:10
@@ -22,7 +22,8 @@ path = "jit.rs"

[features]
disasm = ["yjit?/disasm", "zjit?/disasm"]
runtime_checks = []
# TODO(GH-642) Turning this on trips a btest failure.
Copy link
Member

Choose a reason for hiding this comment

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

It's hard for other contributors to figure out it refers to Shopify/ruby when you're looking at ruby/ruby, so it might be nice to mention the repository name. It confused me at first too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy