Repository navigation
fix(relinker): report processor 0 from RDTSCP under --to-rosetta - #6111
Conversation
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
c690012 to
e097ea1
Compare
|
Checked the RDTSCP decoder (prefix/REX handling, |
…CP under --to-rosetta (@Kernel-Hunter) Open upstream PR that adds macOS behaviour this branch did not have. The only conflict was a list both sides appended to (a debt index or the relinker test registrations), so both entries are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging boykopovar#6111 kept both versions of the --to-rosetta entry. The base's version carries the M1 and M5 instruction measurements; the PR's records that RDTSCP now reports processor 0 and which sites are kept. They are now one entry with both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e097ea1 to
c8f5264
Compare
|
Thanks for checking it. Rebased onto main again: the RDTSCP sentence in docs/dev/debt/relinker.md conflicted with the new macOS 26.4 measurements, so I kept those and changed only the RDPID/RDTSCP part. Relinker tests pass locally (178/178) and the conventions check is clean. |
…CP under --to-rosetta (@Kernel-Hunter) Open upstream PR that adds macOS behaviour this branch did not have. The only conflict was a list both sides appended to (a debt index or the relinker test registrations), so both entries are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging boykopovar#6111 kept both versions of the --to-rosetta entry. The base's version carries the M1 and M5 instruction measurements; the PR's records that RDTSCP now reports processor 0 and which sites are kept. They are now one entry with both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tta (@MarcZX100) Brings the Rosetta ADX lowering from the open upstream pull request into the fork's main ahead of its review. It and the fork's RDTSCP lowering (boykopovar#6111) each add a Rosetta case at the same point of the AMD64-only matcher; both are kept, RDTSCP first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rosetta sets RDTSCP's ECX to its constant TSC_AUX, 0xAAAAAAAB, which is not a processor index. --to-rosetta already makes RDPID return processor 0 for the same reason, so code reading the processor through RDTSCP saw a different value from code reading it through RDPID. --to-rosetta now moves RDTSCP into an optional stub that runs the instruction unchanged and then loads 0 into ECX with a MOV, which leaves the counter in EDX:EAX and the flags as they were. A site with no movable instruction after it for the jump is kept, as for RDPID. The Intel target and a plain relink are unchanged.
c8f5264 to
57e52c1
Compare
Keeps the macOS port current with 117 upstream commits. Upstream took boykopovar#6111's RDTSCP lowering; the AMD64-only matcher keeps it and the fork's ADCX/ADOX case (boykopovar#7173) after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings the pull request up to the 117 upstream commits that made it conflict. Upstream took boykopovar#6111's RDTSCP lowering; the AMD64-only matcher keeps it and the ADCX/ADOX case from boykopovar#7173 after it, as on the fork's main, where the suites passed with this merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Under Rosetta, RDTSCP loads ECX with Rosetta's constant TSC_AUX, 0xAAAAAAAB, which is not a processor index.
--to-rosettaalready lowers RDPID to processor 0 for this reason, anddocs/dev/debt/relinker.mdlists RDTSCP's ECX as not converted. So the same program could read processor 0 through RDPID and 0xAAAAAAAB through RDTSCP.With
--to-rosetta, RDTSCP (0F 01 F9, no 66/F2/F3 prefix) now goes through an optional out-of-line stub, the same mechanism RDPID uses. The stub runs the original RDTSCP, so EDX:EAX and the instruction's ordering stay the same, then doesmov ecx, 0(B9 00 00 00 00). That clears all of RCX and leaves the flags alone. As with RDPID, a site that has no movable instruction after it for the jump is kept, and a kept RDTSCP still reports Rosetta's value. The Intel target and a plain relink do not change.Changes:
DecodedInstruction::IsRdtscp, theRDTSCPtable entry, and the matcher cases in_matchRosetta,_emitOutOfLineandMatchSequence, which marks a sequence that starts with RDTSCP as optional, as it does for RDPID.Amd64OnlyConverterTests: matcher cases (Rosetta stub bytes, optional, not converted for Intel, SWAPGS0F 01 F8and66 0F 01 F9left alone), plusrdtscpExecution. That test runs the stub on x86-64 Linux and macOS hosts and checks that RCX is 0, the counter is not 0 and CF is preserved. On other hosts it is empty.--to-rosettaentries indocs/dev/debt/relinker.mdanddocs/user/USAGE.md.Tested
Apple M5 (MacBook Air), macOS 27.0.1 (26A434), Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2.
Rosetta's value, from a standalone x86-64 program built with
clang -arch x86_64and run under Rosetta: RDTSCP returns ECX =0xaaaaaaab. RDPID ends in SIGILL, which is why it is already lowered.Relinker-only build, native arm64 (
cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON):ctest --test-dir build-relinker -j8 --timeout 30: 163 of 163 pass.amd64_only_convertercases fail withRDTSCP was not lowered through an optional stub.Relinker-only build as x86-64 under Rosetta (same configure plus
-DCMAKE_OSX_ARCHITECTURES=x86_64, Python 3 run as x86-64), so thatrdtscpExecutionreally runs the stub:amd64_only_converter,to_rosettaandmacos_outputpass.RDTSCP stub was not produced.pr_overlap_encoding,stubgen_stdout_newlines,release_package,linux_fixed_base) also fail onmainin this setup, because the only x86-64 Python here is the system 3.9, which lackszip(strict=)andwrite_text(newline=).End to end under Rosetta: a byte-built PS5-style ELF (a copy of the
macos/import_fixture.pylayout) runsrdtscp, thenexit(ecx != 0). I relinked it with--macos --skip-sce-moduleand ran it with two small x86-64 stub dylibs standing in forlibc.prxandlibkernel.prx. Exit code 1 withmain's relinker, both with and without--to-rosetta. Exit code 0 with this branch and--to-rosetta.python3 tools/check_conventions.py --base origin/mainandgit diff --checkpass. I did not build or run anything on Linux or Windows; the execution test is compiled for x86-64 Linux too, so the Linux CI job runs it. No title was tested.tools/pr_overlap.pylists text overlap only, not the same function: #5784 (ANDN) touches the same_matchRosettalines and the same line inrelinker.mdandUSAGE.md, and #5683 and #5762 add calls at the same place in the converter test'smain. Whichever merges second needs a small rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)