feat(relinker): executable TLS relocations (TPOFF64, DTPOFF64, DTPMOD64) #5262
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5262"
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 NaitikJoshiPro on 2026-10-13T15:57:10Z.
What
A PS5 executable can keep initial-exec TLS as
R_X86_64_TPOFF64GOT relocations against its own TLS block. The SuperTuxKart homebrew eboot (STKT00001) has 13, all without a symbol. The relocation allowlist rejected them (Unsupported relocation type 0x12), so the executable could not be converted for any target.STT_TLSsymbol whose value is folded into the addend) go to the Linux ELF as symbolless dynamic relocations. The dynamic loader resolves them against where it placed the executable'sPT_TLSblock. A relocation against an imported symbol keeps its name and is typedSTT_TLS.TPOFF64andDTPOFF64statically: the block sitsAlignUp(p_memsz, p_align)below the thread pointer, the same offset thatWindowsTlsBuilderandMacOsImageuse. Those targets rejectDTPMOD64and imported TLS with an error.PT_TLS, andDTPMOD64with a nonzero addend fail the relink.TPOFF32stays unsupported.This is separate from #4739, which changes
TPOFF64in guest modules (WindowsGuestModuleWriter); this PR only changes the executable's relocations.Tested
macOS 27.0.1 on Apple M3 (arm64), AppleClang from the Command Line Tools, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON) on main9d0a41d5a:ctest: 147/147 pass, including the newexecutable_tls_relocations. It covers the Linux, Windows and macOS outputs and the rejected cases, and it fails on main withUnsupported relocation type 0x12.--windows) and macOS (--macos). The Linux ELF has 13 symbollessTPOFF64dynamic relocations.python3 tools/check_conventions.py --base upstream/main: passed.Not run: the converted executables were not run on Linux or Windows, because I have no x86-64 host. The Linux path relies on the dynamic loader's standard handling of symbol-0
TPOFF64/DTPOFF64/DTPMOD64in the executable.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)RelinkerPipeline.cpp, relocation symbol extraction) and #5229 (ElfConstants.hpp,RelinkerPipeline.cpp). It does not build on either and implements nothing they do (neither touches TLS relocations). I will rebase onto whichever merges first.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:03:20Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/relinker/src/pipeline/RelinkerPipeline.cppL263-266core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hppL146Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T21:00:59Z.
Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, relinker-only Release, this PR (
6f856a7cd) merged ontomain0aa4cb1c2(AI-assisted: Claude Code).ctest: 151/151, includingexecutable_tls_relocations.image()fixture whose entry reads the thread pointer (mov rax, fs:[0]), loads theTPOFF64GOT slot at 0x1000, and returnsmovzx eax, byte [rax + rcx]as the exit code. The TLS template holds bytes 1..8. Relinked with--windowsand run:STT_TLSsymbol (value 0x10), addend -0xdSo the statically resolved
TPOFF64values match where the converted executable's TLS block sits below the thread pointer at run time.Imported from boykopovar/AnyPS5. Originally posted by NaitikJoshiPro on 2026-10-13T23:25:04Z.
Thanks @simonbronk, that covers the gap I couldn't test: the statically resolved
TPOFF64values for Windows output, run on real hardware, including theSTT_TLS-symbol case and an offset past the template. The Linux path (symbol-0TPOFF64/DTPOFF64/DTPMOD64left to the dynamic loader) is still unexecuted here, so a Linux run would close the last part.(Reply written with AI assistance, Claude Code.)
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T00:24:07Z.
Linux runtime follow-up on exact head
6f856a7cda16568b4bd7e48e0e4b9029512de4e7, no additional source changes: the executable-local TLS relocations are resolved correctly by glibc 2.39 in these synthetic probes.Linux x86-64, GCC, relinker-only Release,
BUILD_TESTING=ON: 156/156 CTests pass, includingexecutable_tls_relocations(23.24 s total).For runtime coverage I reused this PR's
image()fixture, with TLS initializer bytes 1..8 and the samePT_TLSmemory size/alignment. The entry forTPOFF64readsfs:[0], loads the relocated GOT slot at 0x1000, reads the byte at TP + that offset, and returns it in RAX. The other entries return the resolved GOT value. Relinked to Linux and executed the unmodified output through its normal/lib64/ld-linux-x86-64.so.2interpreter. No loader shim, preload, or post-relink byte patch was used.The generated entry trampoline ends in
UD2after the guest entry returns, so I used GDB to inspect RAX at that expected stop and verified the stopped instruction bytes were0f 0b.8 probes × 3 = 24 successful runtime assertions. This covers local executable relocations on this Linux loader, including defined-symbol folding and TLS zero-fill. Imported TLS, a complete SuperTuxKart run, and other Linux loaders remain untested here; the DTPOFF64/DTPMOD64 rows inspect relocation values rather than calling
__tls_get_addr.