Skip to content

winch(aarch64): Improve addressing modes#12708

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
saulecabrera:winch-improve-addressing-modes
Mar 31, 2026
Merged

winch(aarch64): Improve addressing modes#12708
alexcrichton merged 1 commit intobytecodealliance:mainfrom
saulecabrera:winch-improve-addressing-modes

Conversation

@saulecabrera
Copy link
Copy Markdown
Member

Prior to this commit, Winch's Address representation relied on the general (reg, offset) form for offset-based addressing, leaving the materialization of the addressing mode to Cranelift. This approach led to the following bug found by the fuzzer:

When offsets cannot be encoded as a 9-bit signed immediate offset or a 12-bit unsigned immediate offset with scaling, the offset must be loaded into a register and the addressing mode is transformed to its (reg, reg) form. Cranelift's addressing mode materialization currently uses x16 as a scratch register to load the offset; even though both Cranelift and Winch use x16 as a scratch register, its usage is not in sync, therefore clobbers can happen.

This commit improves addressing modes by requiring early materialization of addressing modes into their respective Cranelift variants.

Prior to this commit, Winch's `Address` representation relied on the
general `(reg, offset)` form for offset-based addressing, leaving the
materialization of the addressing mode to Cranelift. This approach led
to the following bug found by the fuzzer:

When offsets cannot be encoded as a 9-bit signed immediate offset or a
12-bit unsigned immediate offset with scaling, the offset must be
loaded into a register and the addressing mode is transformed to its
`(reg, reg)` form. Cranelift's addressing mode materialization currently
uses `x16` as a scratch register to load the offset; even though
both Cranelift and Winch use `x16` as a scratch register, its usage is
not in sync, therefore clobbers can happen.

This commit improves addressing modes by requiring early
materialization of addressing modes into their respective Cranelift
variants.
@saulecabrera saulecabrera requested review from a team as code owners March 3, 2026 18:01
@saulecabrera saulecabrera requested review from fitzgen and removed request for a team March 3, 2026 18:01
Comment on lines +324 to +325
let constant = self.add_constant(&imm.to_bytes());
let addr = AMode::Const { addr: constant };
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed this from the top-level Address since it's only used here, which removes one level of indirection.

@github-actions github-actions Bot added the winch Winch issues or pull requests label Mar 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Subscribe to Label Action

cc @saulecabrera

Details This issue or pull request has been labeled: "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.

Copy link
Copy Markdown
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

LGTM, sorry I missed this one!

@saulecabrera saulecabrera added this pull request to the merge queue Mar 30, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 30, 2026
@alexcrichton alexcrichton added this pull request to the merge queue Mar 30, 2026
Merged via the queue into bytecodealliance:main with commit 8268b1d Mar 31, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

winch Winch issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants