Windows relinker: TLS thread pointer ignores PT_TLS alignment rounding #3136

Closed
opened 2026-10-10 22:57:01 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-10 22:57:01 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-10T22:57:01Z.


AI-assisted (Claude Code), reviewed by the contributor.

Finding: On Windows the relinker's .gtcode trampoline for fs:0 reads loaded the thread pointer displacement from blockSize instead of align_up(p_memsz, p_align). PS5 code reads TLS variables at tp - align_up(memsz, p_align), so the converted code reads the wrong slot when the two differ.

Evidence: a synthetic ELF with PT_TLS memsz=0x21, align=8, first variable 0x2a, second 0x63, and code mov rax, fs:0; mov eax, [rax-0x28]. Before the change the converted exe exits with 0x63, after it with 0x2a. The regression test is core/relinker/relinker/tests/test_windows_tls_thread_pointer.py (verified failing without the fix, passing with it, on Windows).

In a real title (RE4, PPSA07411) the wrong offset made a thread read another thread variable; this is how I found it. I did not verify that this alone makes the title run; other blockers remain.

Branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/relinker-windows-tls-thread-pointer (2 commits on current main, tools/check_conventions.py passes). Not opened as PR because intake is paused for new contributors; happy for a maintainer to carry the commits.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5796031397 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3136). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-10T22:57:01Z. --- AI-assisted (Claude Code), reviewed by the contributor. **Finding:** On Windows the relinker's `.gtcode` trampoline for `fs:0` reads loaded the thread pointer displacement from `blockSize` instead of `align_up(p_memsz, p_align)`. PS5 code reads TLS variables at `tp - align_up(memsz, p_align)`, so the converted code reads the wrong slot when the two differ. **Evidence:** a synthetic ELF with PT_TLS `memsz=0x21`, `align=8`, first variable `0x2a`, second `0x63`, and code `mov rax, fs:0; mov eax, [rax-0x28]`. Before the change the converted exe exits with `0x63`, after it with `0x2a`. The regression test is `core/relinker/relinker/tests/test_windows_tls_thread_pointer.py` (verified failing without the fix, passing with it, on Windows). In a real title (RE4, PPSA07411) the wrong offset made a thread read another thread variable; this is how I found it. I did not verify that this alone makes the title run; other blockers remain. **Branch:** https://github.com/xXPBSXx/AnyPS5/tree/fix/relinker-windows-tls-thread-pointer (2 commits on current `main`, `tools/check_conventions.py` passes). Not opened as PR because intake is paused for new contributors; happy for a maintainer to carry the commits.
reyani-dev commented 2026-10-11 05:35:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T05:35:20Z.


Carried as #3290 with both your commits unchanged. On native Windows 11 (GCC 15.2), the relinker suite passes 101/101 and the new test fails against main with read 0x63 instead of the first variable 0x2a. Three catalog homebrew titles have the same PT_TLS shape (memsz 0x258, align 8): Prospero Explorer, Multi Tools and Vibrate. Their converted TLS accesses use thread-pointer offset 0x260 on main and 0x258 with your fix, so those are affected too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105881073 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3136#issuecomment-6105881073). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T05:35:20Z. --- Carried as #3290 with both your commits unchanged. On native Windows 11 (GCC 15.2), the relinker suite passes 101/101 and the new test fails against `main` with `read 0x63 instead of the first variable 0x2a`. Three catalog homebrew titles have the same PT_TLS shape (`memsz 0x258`, `align 8`): Prospero Explorer, Multi Tools and Vibrate. Their converted TLS accesses use thread-pointer offset `0x260` on `main` and `0x258` with your fix, so those are affected too.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3136
No description provided.