fix(relinker): restore rbx in TLS coverage bodies run on the host #6929
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6929"
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 jotitadev on 2026-10-16T19:29:30Z.
What
tls_function_coverage_alu_executionandtls_function_coverage_moved_branchsegfault on Linux x86-64 with Python 3.9:The fixture bodies in both groups write
rbx(alu_check_bodyloads it as one of the ALU operands, the moved-branch prologue doesmov rbx, -16) and return to the host without restoring it.rbxis callee-saved in both the SysV and the Windows x64 ABI. On Linux the converted image is entered fromwindows_image_runner.pythrough ctypes, and Python 3.9's caller usesrbxafter the call. Python 3.14 happens not to, which is why the hosted matrix stays green.This change saves
rbxon entry and restores it before everyretin those two fixtures, the same wayregister_load_body,register_alu_bodyanddisplacement_loadalready save the callee-saved registers they use. The extrapushshifts the patched TLS address (0x1240->0x1241for ALU execution,0x124A->0x124Bfor moved branches) and the branch targets by one, and thepopbefore eachretgrows the short branch distances by one. The cases themselves (registers, operands, branch encodings, expected stubs) are unchanged.I fixed the fixtures rather than adding a register-saving trampoline to
windows_image_runner.py: the bodies are the code breaking the ABI, the runner stays a plain call, and Windows runs the same images natively, where the bodies should also be well-behaved.Tested
Intel i7-8700, Ubuntu 26.04, GCC 15.2, CMake 4.2.3, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), once with-DPython3_EXECUTABLE=<CPython 3.9.25>and once with the system Python 3.14.4.main, Python 3.9: both groups fail with the segfaults above. Python 3.14: both pass.ctest -L tls_function_coverage31/31, three runs each with Python 3.9 and 3.14.main175/182, this branch 177/182. The five left are unrelated:linux_fixed_base(#6843),pr_overlap_toolsandrelease_package(#6734, #6728),file_writer_binary/file_writer_text(this machine's coreutils, they fail with 3.14 too).file_writer_*.python3 tools/check_conventions.py --base origin/mainpasses.Not checked: Windows and macOS (Windows runs the same fixtures natively and the change keeps the bodies ABI-correct there; macOS does not execute these cases).
Rebased onto
main1b1f8483c; the files this changes are unchanged since the tested base.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by OskarLGS on 2026-10-17T21:26:35Z.
Review: COMMENTED
Reproduced and verified on Linux x86-64 (relinker-only build, GCC 13):
('alu-exec-xor-3', -11, b''),('moved-rel8-branch', -11, b'')). With this PR all groups pass under 3.9, both on the branch and merged into current main (which has since changed the same file in2a65acd86; the merge is clean). Python 3.13 passes either way, as described.tls_address=0x1241, andlen(code) - 7is the start of the 7-byte failure block.Review done with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T17:10:44Z.
Windows host run, since the description lists Windows as not checked. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:main6efb7261bwith #7524, #7006, #6612, #6929, #7119, #6896 and #6856 merged together (each merge clean, built once).tls_function_coverage_alu_executionandtls_function_coverage_moved_branchpass 3 runs of 3 on the Windows host.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:36:47Z.
Review: APPROVED
The test fixture was violating the x64 callee-saved register contract: both groups modify RBX and return through the host caller. The added push/pop pairs cover every return path, and the updated TLS addresses and relative branch targets match the one-byte prologue shift. Independent Linux reproduction and disassembly checks confirm the patched addresses and restores; external Windows runs also pass. The relinker matrix, conventions and intake checks are green. I did not run the tests locally. No blocking issue found; approved.