fix(relinker): place the Windows thread pointer after the TLS size rounded to its own alignment #3290
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3290"
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 reyani-dev on 2026-10-11T05:35:18Z.
What
Carries @xXPBSXx's fix from #3136, which was shared as a branch while intake was paused. Both commits are theirs, unchanged (
8e03bb0afix,272b9d13test), and merge cleanly onto currentmain.On Windows, the relinker's
.gtlsstub set the guest thread pointerblockSizebytes past the start of the per-thread block, whereblockSize = align_up(p_memsz, max(p_align, 16)). PS5 code (FreeBSD amd64 variant II) reads TLS variables attp - align_up(p_memsz, p_align). When the two roundings differ, every TLS read and write lands that many bytes before the variable. The stub now usesalign_up(p_memsz, p_align)for the thread pointer and for the displacement bounds check. The block allocation keepsblockSize, so the self-pointer and the stack guard attp + 0x28still fit inside it, and both are written through the sameloadPointer.The new
windows_tls_thread_pointertest builds an ELF with PT_TLSmemsz = 0x21,align = 8and reads the first variable attp - 0x28.Closes #3136.
Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, relinker-only Release build (
ANYPS5_RELINKER_ONLY=ON), the two commits merged ontomain961b25fe:ctest: 101/101, includingwindows_tls_thread_pointer. It builds without warnings.mainfails as described:read 0x63 instead of the first variable 0x2a.Homebrew titles affected. I checked PT_TLS in the 48 unwrapped catalog executables. Three have
p_memsz = 0x258,p_align = 8: Prospero Explorer (PPSA99109), Prospero Multi Tools (PPSA99110) and Prospero Vibrate (PPSA99920). The other 45 have no TLS. For those three:mainand this PR both relink them (--windows, rc 0).lea rax, [rax + imm32]that follows the TLS-slot load is0x260onmainand0x258with this PR. That holds in every stub: 686, 719 and 671 converted TLS accesses respectively.mainreads every thread variable of these titles 8 bytes before its address.I did not run the titles (static conversion only). The author found the bug at runtime in Resident Evil 4 (PPSA07411), where a thread read another thread variable.
check_conventions.py --base upstream/mainpasses, andpr_overlap.pyreports no overlap.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:26:21Z.
Checked the diff: the thread pointer and the displacement bound now use
align_up(p_memsz, p_align), while the block allocation keepsblockSize, so the self-pointer and the stack guard attp + 0x28stay inside.gtls. The relinker suite passes locally (95/95, Linux) and therelinker (windows-latest)job, which runswindows_tls_thread_pointeron Windows, is green on this head; merging.