Skip to content

fix: avoid broad fallback for unresolved JALR calls - #436

Open
Tzeentchnet wants to merge 2 commits into
ran-j:mainfrom
Tzeentchnet:upstream/jalr-return-resume
Open

Tzeentchnet wants to merge 2 commits into
ran-j:mainfrom
Tzeentchnet:upstream/jalr-return-resume

Conversation

@Tzeentchnet

@Tzeentchnet Tzeentchnet commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary

  • Keep the instruction after an unresolved link-producing JALR delay slot as a resumable caller entry.
  • Avoid promoting every caller instruction to an indirect fallback entry for JALR calls.
  • Preserve broad fallback for unresolved JR and JALR $zero indirect jumps.

Rationale

A JALR with a nonzero link destination is emitted as an indirect call through the runtime dispatcher, and execution resumes in the caller at pc + 8. The analyzer already records that return PC, but then falls through to unresolved-jump handling and marks every instruction in the caller as a possible indirect jump target. This creates unnecessary entry points and labels for indirect calls.

Returning immediately after recording the call's resume address keeps call and jump semantics separate. JALR $zero, $rs does not produce a return link and remains on the existing unresolved indirect-jump fallback path, as does JR.

Testing

Updated focused control-flow coverage to verify that:

  • a link-producing JALR makes pc + 8 a resume entry and emitted caller label;
  • unrelated caller instructions are not indirect fallback entries for that call;
  • JALR $zero does not add a return entry and retains broad indirect fallback;
  • no jump-table target is fabricated.

The existing unresolved-JR fallback test continues to pass.

Windows Release builds:

  • MSVC 19.44: ps2x_tests — 447 passed, 0 failed.
  • ClangCL 19.1.5: ps2x_tests — 447 passed, 0 failed.

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.

1 participant