cpu: accept LEAVE on a proven RBP anchor in cpu_switch_aot #900

Closed
opened 2026-11-23 16:39:36 +00:00 by legacy-code-archaeologist · 2 comments
legacy-code-archaeologist commented 2026-11-23 16:39:36 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T16:39:36Z.


Claim and design question: accept LEAVE on a proven RBP anchor in cpu_switch_aot

leave is in the Integer group of docs/coverage/x64_zen2.tsv. No translator accepts it: there is no M.LEAVE in tools/. It is the usual frame-pointer epilogue (mov rsp, rbp; pop rbp). Since 169289b, cpu_switch_aot proves a fixed RBP anchor after mov rbp, rsp or lea rbp, [rsp+d]. Today any other write of RSP is rejected as a dynamic frame, so a function that ends in leave is refused. I found no open issue or PR about it and would like to take it as one small PR.

Proposed rule (frame proof in step())

  • Accept LEAVE only while the RBP anchor is known on every path into it, as the agreeing-at-joins rule already requires for RSP.
  • It acts as RSP := anchor, followed by the existing POP RBP rule:
    • an 8-byte read at the anchor that must hold the saved RBP;
    • RSP := anchor + 8;
    • the anchor is cleared.
  • The bytes between the old RSP and the anchor are released, as ADD RSP releases them since 7fb6a9a.
  • Reject LEAVE without a known anchor. Also reject it when the anchor lies below the current RSP, which would move RSP down instead of releasing the frame.
  • ENTER stays rejected. mov rsp, rbp as a separate instruction also stays rejected, unless you prefer it accepted under the same rule.

Proposed fixture (source-built MASM, differential, ; coverage: source cpu_aot_leave)

Exports would cover:

  • a push rbp / mov rbp, rsp / sub rsp, N frame with locals, ending in leave; ret;
  • the lea rbp, [rsp+d] anchor form;
  • a branch join where both paths keep the same anchor.

Native and translated outputs (RAX plus an output buffer) must match over generated inputs. Negative controls must each be rejected with a named message:

  • leave after RBP was overwritten (no anchor);
  • leave on a path where the anchor differs at a join;
  • leave where the saved slot was never written;
  • a read of a released local after leave.

Question before I start

Is accepting LEAVE on a proven anchor the intended next step for this translator? Or should frame-pointer epilogues wait for a broader dynamic-frame model? And should mov rsp, rbp be accepted by the same rule in the same PR, or stay rejected?

Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564066791 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/907). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-23T16:39:36Z. --- ### Claim and design question: accept `LEAVE` on a proven RBP anchor in `cpu_switch_aot` `leave` is in the Integer group of `docs/coverage/x64_zen2.tsv`. No translator accepts it: there is no `M.LEAVE` in `tools/`. It is the usual frame-pointer epilogue (`mov rsp, rbp; pop rbp`). Since `169289b`, `cpu_switch_aot` proves a fixed RBP anchor after `mov rbp, rsp` or `lea rbp, [rsp+d]`. Today any other write of RSP is rejected as a dynamic frame, so a function that ends in `leave` is refused. I found no open issue or PR about it and would like to take it as one small PR. **Proposed rule (frame proof in `step()`)** - Accept `LEAVE` only while the RBP anchor is known on every path into it, as the agreeing-at-joins rule already requires for RSP. - It acts as RSP := anchor, followed by the existing `POP RBP` rule: - an 8-byte read at the anchor that must hold the saved RBP; - RSP := anchor + 8; - the anchor is cleared. - The bytes between the old RSP and the anchor are released, as `ADD RSP` releases them since `7fb6a9a`. - Reject `LEAVE` without a known anchor. Also reject it when the anchor lies below the current RSP, which would move RSP down instead of releasing the frame. - `ENTER` stays rejected. `mov rsp, rbp` as a separate instruction also stays rejected, unless you prefer it accepted under the same rule. **Proposed fixture (source-built MASM, differential, `; coverage: source cpu_aot_leave`)** Exports would cover: - a `push rbp / mov rbp, rsp / sub rsp, N` frame with locals, ending in `leave; ret`; - the `lea rbp, [rsp+d]` anchor form; - a branch join where both paths keep the same anchor. Native and translated outputs (RAX plus an output buffer) must match over generated inputs. Negative controls must each be rejected with a named message: - `leave` after RBP was overwritten (no anchor); - `leave` on a path where the anchor differs at a join; - `leave` where the saved slot was never written; - a read of a released local after `leave`. **Question before I start** Is accepting `LEAVE` on a proven anchor the intended next step for this translator? Or should frame-pointer epilogues wait for a broader dynamic-frame model? And should `mov rsp, rbp` be accepted by the same rule in the same PR, or stay rejected? Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:49:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:50:16Z.


Yes, please proceed with LEAVE as a fixed-frame epilogue. Keep ENTER and standalone MOV RSP,RBP outside this PR. Reuse the saved-RBP proof, preserve flags, and invalidate the whole freed interval through anchor+8, including the pop slot. Your fixtures and refusals fit the scope. Please include a saved slot overwritten with ordinary data so the test distinguishes restoring the original RBP from merely reading eight defined bytes. #895 also edits the shared Frame class, so please check that the existing synchronous stack-output cases still pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107747481 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/907#issuecomment-7107747481). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:50:16Z. --- Yes, please proceed with LEAVE as a fixed-frame epilogue. Keep ENTER and standalone MOV RSP,RBP outside this PR. Reuse the saved-RBP proof, preserve flags, and invalidate the whole freed interval through anchor+8, including the pop slot. Your fixtures and refusals fit the scope. Please include a saved slot overwritten with ordinary data so the test distinguishes restoring the original RBP from merely reading eight defined bytes. #895 also edits the shared Frame class, so please check that the existing synchronous stack-output cases still pass.
R0Y00 commented 2026-11-24 06:49:28 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:27:47Z.


Completed by #933. The fixed-frame lowering restores RBP from its proven saved slot, frees the stack interval through that slot, and preserves the flags from before LEAVE. The differential and refusal controls passed, including an overwritten saved slot and a 16-bit operand-size override. ENTER and standalone MOV RSP,RBP remain outside this scope.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110198170 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/907#issuecomment-7110198170). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:27:47Z. --- Completed by #933. The fixed-frame lowering restores RBP from its proven saved slot, frees the stack interval through that slot, and preserves the flags from before LEAVE. The differential and refusal controls passed, including an overwritten saved slot and a 16-bit operand-size override. ENTER and standalone MOV RSP,RBP remain outside this scope.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#900
No description provided.