feat(relinker): support Windows guest TLS reads by ALU register-address instructions #1651
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1651"
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 emirplus on 2026-10-08T15:40:43Z.
What
Recognize read-direction ALU forms (
add,or,adc,sbb,and,sub,xor,cmp) reading fromfs:[mem]wherememhas a base or index register (such as64 48 33 03,xor rax, fs:[rbx], reported on NHL 27 in #217).Following the approach from #767 (for disp32 ALU) and #1233 (for register-addressed MOV loads):
lea, loads the thread pointer, performs the ALU operation against[thread_pointer + offset], and restores scratch registers without disturbing arithmetic flags.rax,rcx, and general/extended registers (rbx..r15), for both 64-bit and 32-bit forms.Tested
core/relinker/relinker/tests/test_tls_function_coverage.pywith:xor rax, fs:[rbx],xor rcx, fs:[rax],xor rbx, fs:[rax],add rax, fs:[rbx],cmp rax, fs:[rbx],xor r13, fs:[rbx + rcx - 0x10](SIB + disp8), and 32-bitxor edx, fs:[rbx].short-alu-before-return).register-address-alufrom the rejected list.empty_tls,tls_function_coverage,tls_diagnostics,guest_tls) pass 100% under ctest.check_conventions.pypasses with zero violations.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)Refs #217
Co-Authored-By: Claude Opus 5.5 [email protected]
Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T17:50:44Z.
Tested on Linux x86-64 (Ubuntu 24.04.5, GCC 13.3.0), merged onto
6b56175a.windows_image_runner.pyexecutes every converted case there.tls_function_coverage,tls_diagnostics,empty_tlsandguest_tlspass.One bug, in the 32-bit
rcxpath. It restores rcx withmov ecx, [rsp+8], which zeroes rcx's upper half. For the ops that write ecx that doesn't matter, since the 32-bit result zero-extends anyway.cmpwrites nothing, though, socmp ecx, fs:[rax](64 3b 08) comes back with rcx's upper 32 bits cleared. The test doesn't catch it becauseregister_alu_bodyalso sets the expected value of a 32-bitcmpdestination tores & 0xffffffff.With the case below and
cmpkeeping the full register in the expectation,register-alu-cmp-ecx-rax-202fails (the runner exits 1). Restoring the full rcx before the 32-bit op fixes it.I also added
adcandsbbcases, run with both of the existing flag values (CF clear and set). They pass, so the stubs keep the incoming carry. Note that the flags the ALU op produces aren't compared after it; only registers are. Everything after the op in these stubs ispop/lea, so they survive, but nothing guards that.With both changes, all four tests pass on Linux.
Imported from boykopovar/AnyPS5. Originally posted by emirplus on 2026-10-08T19:02:08Z.
Thanks @hashaam1217 for catching the 32-bit
cx preservation bug and providing the regression cases.
Pushed
8c45db71:cx intact (while writing ops zero-extend naturally).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:25Z.
The conventions job fails on the description: it needs the template's
### What,### Testedand### Checklistsections (## Testingisn't picked up). Editing the body is enough; the code jobs are green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:58:50Z.
Checked the register/rax/rcx stub paths (64/32-bit, REX.R destinations): flags are untouched after the ALU op, scratch registers are restored, and
cmp ecx, fs:[rax]keeps rcx's upper half. Local build and relinker ctest green;tls_function_coveragefails without theWindowsTlsBuilder.cppchange. Linux/Windows CI green.I rewrote the PR body under the template headings (
### What/### Tested/### Checklist) so the conventions check passes; your text is unchanged. Note #1913 also editstest_tls_function_coverage.py, so whichever lands second will need a rebase. Merging.