fix(relinker): lower MCOMMIT and RDPRU in --to-intel instead of failing the relink #2771

Closed
Alessandro-GC7 wants to merge 2 commits from upstream-pr/2771 into main
Alessandro-GC7 commented 2026-10-10 14:02:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Alessandro-GC7 on 2026-10-10T14:02:54Z.


What

--to-intel lowered MONITORX and MWAITX in place but still returned Unsupported for MCOMMIT and RDPRU, which aborts the whole relink when a converted title contains either. Both are AMD-only and #UD on Intel hosts, so they have to be neutralized like the other no-equivalent instructions. This closes the "--to-intel does not lower RDPRU/MCOMMIT" technical-debt item.

  • MCOMMIT (F3 0F 01 FA) is lowered in place to CLC (plus NOP padding), guarded by the same _validWait check as MONITORX/MWAITX so a LOCK-prefixed or over-length encoding still fails. MCOMMIT's only architecturally observable effect is rFLAGS.CF (cleared on success); on host memory with no error-logging resource reporting an error it always succeeds, so CLC reproduces the result (AMD64 APM, pub. 24594).
  • RDPRU (0F 01 FD) is lowered through an out-of-line stub that writes 0 into EDX:EAX with two flag-preserving MOVs (RDPRU leaves rFLAGS unchanged). The host exposes no MPERF/APERF process-register counters; zero is also what RDPRU returns for an unsupported register selector.

docs/dev/TechnicalDebt.md is updated accordingly. The two converter tests that used RDPRU as their unsupported-instruction sample now use a LOCK-prefixed MWAITX, which still fails.

If you'd prefer MCOMMIT to be a plain NOP (as MONITORX is) or RDPRU to keep failing the relink, say so — both are easy to change; I went with the most faithful neutralization.

Tested

Windows, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, GCC 16.2.0 / Ninja). ctest green: 100% of 93 tests. Added matcher cases to amd64_only_converter for MCOMMIT (base, prefixed, LOCK-rejected, over-length) and RDPRU (trampoline + the stub zeroes EDX:EAX). No game title tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source — n/a
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4811752816 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2771). Originally posted by [Alessandro-GC7](https://github.com/Alessandro-GC7) on 2026-10-10T14:02:54Z. --- ### What `--to-intel` lowered MONITORX and MWAITX in place but still returned `Unsupported` for MCOMMIT and RDPRU, which aborts the whole relink when a converted title contains either. Both are AMD-only and `#UD` on Intel hosts, so they have to be neutralized like the other no-equivalent instructions. This closes the "`--to-intel` does not lower RDPRU/MCOMMIT" technical-debt item. - **MCOMMIT** (`F3 0F 01 FA`) is lowered in place to `CLC` (plus NOP padding), guarded by the same `_validWait` check as MONITORX/MWAITX so a LOCK-prefixed or over-length encoding still fails. MCOMMIT's only architecturally observable effect is `rFLAGS.CF` (cleared on success); on host memory with no error-logging resource reporting an error it always succeeds, so `CLC` reproduces the result (AMD64 APM, pub. 24594). - **RDPRU** (`0F 01 FD`) is lowered through an out-of-line stub that writes 0 into EDX:EAX with two flag-preserving `MOV`s (RDPRU leaves `rFLAGS` unchanged). The host exposes no MPERF/APERF process-register counters; zero is also what RDPRU returns for an unsupported register selector. `docs/dev/TechnicalDebt.md` is updated accordingly. The two converter tests that used RDPRU as their unsupported-instruction sample now use a LOCK-prefixed MWAITX, which still fails. If you'd prefer MCOMMIT to be a plain NOP (as MONITORX is) or RDPRU to keep failing the relink, say so — both are easy to change; I went with the most faithful neutralization. ### Tested Windows, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, GCC 16.2.0 / Ninja). `ctest` green: 100% of 93 tests. Added matcher cases to `amd64_only_converter` for MCOMMIT (base, prefixed, LOCK-rejected, over-length) and RDPRU (trampoline + the stub zeroes EDX:EAX). No game title tested. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source — n/a - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-10 14:03:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T14:03:06Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098287922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2771#issuecomment-6098287922). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T14:03:06Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

Sign in to join this conversation.
No reviewers
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
boykopovar/AnyPS5!2771
No description provided.