feat(relinker): convert for Rosetta with --to-rosetta #2119
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2119"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-09T09:23:16Z.
What
Adds
--to-rosettato the relinker. Rosetta (macOS on Apple silicon) runs AVX2, FMA, BMI1/2, F16C and MOVBE, but unlike an Intel host it has neither RDSEED, CLWB nor RDPID.--to-rosettaconverts everything--to-inteldoes and lowers these three as well. It is the Rosetta step I said would get its own flag on #1, so Intel output and--macosoutput are unchanged./6form of the same opcode). Both return a random value and set CF.TSC_AUXis a constant, not a processor index, so every thread reports processor 0. A site with no movable instruction after it for the jump is kept, as for the other optional stubs.--to-inteland conflicts with--windows. The target is a parameter of the converter and the matcher, Intel by default.Tested
amd64_only_converterandto_rosettaincluded; they and the conventions check pass on my fork (https://github.com/mugurc/AnyPS5/actions/runs/37909850030) and are running on this pull request. The full Linux and Windows builds only run by manual dispatch, and this change does not touch the libraries.amd64_only_converter) cover the matching of each instruction (including the look-alikes: VMPTRST, TPAUSE, CLFLUSHOPT), the replacement bytes, the RDPID stub for each register, the kept site, and that the Intel target converts none of them.to_rosetta: relinks an executable that contains RDSEED and CLWB with no flag,--to-intel,--to-rosettaand both, and reads the output: only the Rosetta runs lower them. It also checks that--to-rosetta --windowsis refused.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:15:00Z.
Please remove the new code comments:
Amd64OnlySubstitutionTypes.hpp:11-12,DecodedInstruction.hpp:26,Amd64OnlyInstructionMatcher.cpp:110-111,202,208,211andDecodedInstruction.cpp:265,296. CONVENTIONS only allows technical-debt markers; the RDPID note already lives in TechnicalDebt, and the rest can go in the commit message.Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-09T20:56:11Z.
Removed, thank you: all the comments at the places you listed (ten of them, across the four files). The commit message already says what they said, and the RDPID note is in TechnicalDebt. Rebased on current
main; the relinker tests pass locally (35 of 35).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:52Z.
This conflicts with main again after today's merges (
CliArgs.cpp,main.cpp,GuestModuleBuilder.cpp,Amd64OnlyConverter.cpp,CMakeLists.txt,USAGE.md); please rebase.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:02:17Z.
Review: CHANGES_REQUESTED
Thanks for removing the comments. I tried the rebase on current
mainand it isn't mechanical, so I'm leaving it to you:mainnow has--macos(Mach-O that runs under Rosetta;toMacosis passed toGuestModuleBuilder::BuildandCliArgs.cpp). The PR predates it and doesn't say how--to-rosettarelates to it: should--macosimply the Rosetta lowerings, conflict with--to-rosetta, or are they independent? Please decide, document it indocs/user/USAGE.mdand cover it into_rosetta.core/relinker/CMakeLists.txt(newentry_point_bounds/init_array_rootstests next toto_rosetta),CliArgs.cpp(the newUsage()helper and--help; add[--to-rosetta]there, not in an inline string),Amd64OnlyConverter.cpp(_matcheris now default-initialised in the member),main.cpp,GuestImage.hpp/GuestModuleBuilder.cpp(Buildhas gainedmacos),USAGE.md.to_rosettawith--macosin the mix.Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-10T09:19:55Z.
Thank you for checking the rebase. They are independent:
--to-rosettaonly changes what the x86 conversion produces, so--macosalone leaves RDSEED, CLWB and RDPID as they are (as on an Intel Mac), and a title for Rosetta is relinked with--macos --to-rosetta.--to-rosettastill implies--to-inteland conflicts with--windows.Rebuilt on current
main(11cb1b75) as one commit:Usage()carries[--to-rosetta],CliArgs.cpphas the flag, andBuildtakestoRosettaaftertoIntel, next tomacos.Amd64OnlyConverter.cppkeeps the target-taking constructor; its member is no longer default-initialised.USAGE.mdsays how the two relate and what to run on a Mac.to_rosettanow also relinks with--macos,--macos --to-inteland--macos --to-rosetta: the output is a Mach-O in all three, and only the last has RDSEED and CLWB lowered. The test registration moved to the end of the Python block, so it no longer sits where the new tests land.The relinker tests pass locally (81 of 81).
Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T17:52:35Z.
Checked
87273f5fon Linux (Ubuntu 26.04 in WSL2, GCC 15.2.0, relinker-only Release build). The head already contains currentmain(57f96fd2), and the relinker ctest run is already covered by this PR's CI job; the checks below are the ones it does not do:main(tests andadd_testkept):to_rosettafails withunknown option: --to-rosetta, andamd64_only_converter_testsno longer compiles (Codegen::Amd64OnlyTargethas not been declared).Usage()lists[--to-rosetta];--to-rosettasetstoInteland is refused with--windows;Amd64OnlyConvertertakes the target in its constructor and_matcheris no longer default-initialised;BuildtakestoRosettaaftertoIntel;USAGE.mdsays the two flags are independent;to_rosettanow relinks with--macos,--macos --to-inteland--macos --to-rosetta, checks the Mach-O magic, and is registered afterentry_point_bounds/init_array_roots.llvm-mc -triple=x86_64(LLVM 21): RDSEED0F C7 /7and RDRAND0F C7 /6differ only in ModRM bit 3, which is the bit the matcher clears (0F C7 F8->F0,49 0F C7 FF->F7); RDPID isF3 0F C7 /7with mod=11 and CLWB is66 0F AE /6with a memory operand, as the predicates require. The look-alikes in the tests are the real encodings: VMPTRST0F C7 38, TPAUSE66 0F AE F0+r, CLFLUSHOPT66 0F AE 38; SENDUIPIF3 0F C7 F0(reg 6) is not taken for RDPID (reg 7). The RDPID stub'smov r32, 0zero-extends, so the 64-bit forms get 0 too.add_testblock (CMakeLists.txt:317); no source file is shared.Not checked here: that the converted code runs under Rosetta (no Mac), and nothing ran in a game.
AI-assisted: yes (Claude Code).
Edited: removed the ctest pass count, which this PR's relinker CI job already reports.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T19:49:50Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/cli/src/CliArgs.cppL11core/relinker/main.cppL111core/relinker/relinker/include/relinker/guest/GuestImage.hppL61core/relinker/relinker/src/guest/GuestModuleBuilder.cppL53core/relinker/CMakeLists.txtL332core/relinker/CMakeLists.txtL332Imported from boykopovar/AnyPS5. Originally posted by Bruggi-ch on 2026-10-10T21:55:09Z.
Checked
92b20608on an Apple M5 (MacBook Air, macOS 27.0.1, Rosetta 2, Apple clang 21.0.0, CMake 4.4.4), relinker-only build withBUILD_TESTING=ON. This covers what orishamir's review could not (running the converted code under Rosetta) on a second machine and OS version.ctest: 93 of 93 pass,to_rosettaandamd64_only_converterincluded.rdseed eax,clwb [rsp]andrdpid rax, then callsputsandexit(eax), with the libc.prx from amacos-portbuild. Relinked and run under Rosetta:--macos: SIGILL (exit 132)--macos --to-intel: SIGILL (exit 132)--macos --to-rosetta: prints the message and exits 0 (3 runs). The relinker log shows RDSEED and CLWB replaced in place and RDPID replaced through a 15-byte stub.--to-rosetta --windowsis refused with--to-rosetta conflicts with --windows.I did not test which of the three instructions faults on its own, and nothing ran in a game. The fixture generator is a short Python script; I can post it if it is useful for the macOS fixtures.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:26:23Z.
Review: APPROVED
Checked on current
main: relinker build + ctest 90/90 (amd64_only_converter,to_rosettapass); both tests fail without the non-test changes; decoder look-alikes (VMPTRST, TPAUSE, CLFLUSHOPT) are covered; no code comments; USAGE and TechnicalDebt updated. Thanks for the comment removal and rebase, and to @orishamir and @Bruggi-ch for the independent runs. Merging.