fix(relinker): convert stack-guard and thread-pointer reads with an empty PT_TLS #1911
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1911"
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 TheAggie on 2026-10-08T23:23:41Z.
What
A title built with
-fstack-protectorreads its stack guard fromfs:0x28even when it has no thread-local data and its linker emits an emptyPT_TLS. The Windows TLS builder refused any guest TLS access in that case:Guest TLS access with empty PT_TLS. ccleste (PPSA59322) failed to relink because of it.The guard (
fs:0x28) and the thread pointer (fs:0) live in the thread control block, which the builder already emits. An emptyPT_TLSwith accesses now takes the normal path, where a zero-sized TLS block still rejects every displacement into thread-local data.Test (
empty_tls,core/relinker/relinker/tests/test_empty_tls.py): an emptyPT_TLSwith a stack-guard read and one with a thread-pointer read now relink. A read atfs:-8, which would be thread-local data, still fails withis not in the thread TLS block. The previousempty-accesscase, which expected the old error, is replaced by these.Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
mainwith this PR and four other small PRs of mine merged together (SCHED_OTHER priority range, MAP_ALIGNED_SUPER, the compatible pad vibration mode, empty-PT_TLS stack-guard reads, pthread_attr scope/getters). It was run from the generatedCTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.py --base origin/mainpasses on this branch alone.Not tested on Linux or macOS.
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 klosixgaming-arch on 2026-10-09T00:40:55Z.
Review: APPROVED
Reasonable behaviour change: instead of hard-failing a Windows relink when guest code reads the thread pointer / stack guard (fs:[0] and fs:[0x28]) against an empty PT_TLS placeholder, the builder now emits a TLS directory to back those reads, while still rejecting reads outside the TLS block (fs:[-8] → "not in the thread TLS block"). The reworked
test_empty_tls.pypins all three cases (guard read, thread-pointer read, out-of-block read) plus the no-access and non-empty baselines, and actually executes the produced.exeasserting theret 42path — a behavioural test, not just "TLS directory present".Two things worth tightening before merge:
if os.name == "nt", so on the Linux CI runners the new fs:[0]/fs:[0x28] paths are never actually executed — the test there only checks the PE carries a non-zero TLS directory. If the goal is to guard the new lowering, either make the run assertion host-independent or note why Windows-only is sufficient (this isWindowsTlsBuilder, so likely fine — just make that explicit).throw ... "Guest TLS access with empty PT_TLS"is removed. That's the intended relaxation per the title; just confirm no other call site or test depended on that exact message.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T03:06:31Z.
Review: COMMENTED
Verified on Linux — both arms, and the failure is a named assertion rather than a silent abort.
cmake --build build --target relinker→ clean;ctest --test-dir build -R '^empty_tls$'→ Passed (0.07 s).WindowsTlsBuilder.cppback atmainwith the test kept, rebuilt the same way →empty_tlsFailed,AssertionErrorattest_empty_tls.py:41with the relink output ending in the empty-PT_TLSrefusal. So the test pins this: it is the builder's refusal the change removes, and the test would catch a regression.Claim cross-check: after the change the file still carries the refusal for a displacement into thread-local data with a zero-sized block (one such message remains, where
mainhas two), which is what the body says — the thread-control-block reads (fs:0,fs:0x28) take the normal path now, while TLS data access with an empty block is still refused.Worth keeping: this one is a Python relinker test, so it runs on Linux as well as Windows — that is why both arms exist here instead of only the author's.
Not verified: Windows, and a real title relink end-to-end (the title is named, but relinking it here would only exercise the same builder path).
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Xabilimon1 on 2026-10-09T15:16:37Z.
Tested this branch with the relinker-only build on macOS (Apple M3). Besides ccleste (PPSA59322), it also fixes the same Guest TLS access with empty PT_TLS stop with windows for RetroArch (PPSA99169, v1.0.0-beta.1) and PS5MC (PPSA99420, 1.2). All three fail on main
d70b8998and relink with this PR.Imported from boykopovar/AnyPS5. Originally posted by danielradosa on 2026-10-09T18:34:31Z.
Windows run with a title for this PR. PS5MC PPSA99420 1.2 (catalog release, sha256 as in the record,
eboot.binandsce_module/libc.prxunwrapped from their SELF containers), whosePT_TLSis empty (filesz and memsz 0). Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.main0fdda7be(and4b005b22):relinker --windowsfails withFAIL: Guest TLS access with empty PT_TLS (offset 0x598c000). Linux output relinks.main0fdda7be+ this PR (+ #1650, #1748, #1944, which do not touch TLS conversion):--windowsrelinks, and the converted executable loads its libraries and stops at its first absent import,FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx(sigaction).AI-assisted: yes (Claude Code).