fix(relinker): reject non-TLS guest relocations bound to a guest TLS export #10732
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10732"
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 roboterspinne on 2026-10-24T19:57:16Z.
What
A guest
STT_NOTYPEimport that resolves to another guest module'sSTT_TLSexport was accepted whenR_X86_64_GLOB_DAT,R_X86_64_64orR_X86_64_JUMP_SLOTreferenced it: Linux, Windows and macOS relinked with exit 0 and wrote both guest outputs. The Linux consumer keptGLOB_DATagainst the undefinedNOTYPEtls_value#guest, which glibc resolves to the provider's load base plus the TLS offset 0; Windows and macOS bind the slot to the provider's TLS export record (.tlsrefsinWindowsGuestModuleWriter.cpp, theTlsExportsrecords inMacOsImage.cpp). None of these is the variable, while the same import typedSTT_OBJECTorSTT_FUNCalready fails withGuest import/export type mismatch.GuestModuleBuilder.cpp, right after the type-mismatch check, aNOTYPEimport whose provider export isSTT_TLSand that a relocation of the importing module references throwsNon-TLS relocation against guest TLS export: <name>. The gABI lets only TLS relocations reference anSTT_TLSsymbol; the reader and the Windows and macOS guest writers already reject a non-TLS relocation against a TLS-typed import (Invalid guest symbol relocation), and the reader rejects TLS relocations against aNOTYPEsymbol (Invalid guest TLS relocation) andRELATIVEagainst an undefined symbol (RELATIVE relocation has a symbol), so every relocation reaching the new check isR_X86_64_64,GLOB_DATorJUMP_SLOT. UnreferencedNOTYPEentries bind nothing and stay accepted. Executable imports of guest exports have no type check at all; that is a separate follow-up.test_guest_tls_export_references.py, registered afterguest_tls: providera.prxwithPT_TLS(memsz 0x40) and a globalSTT_TLSexport, consumerb.prxwithDT_NEEDED a.prxand an undefinedtls_value. On Linux, Windows and macOS,NOTYPEwithGLOB_DATorR_X86_64_64inDT_RELAand withJUMP_SLOTinDT_JMPRELexits 2 with the new message and writes no output;OBJECTwithGLOB_DATkeeps the existing type-mismatch message;NOTYPEwithout a relocation,NOTYPEwithGLOB_DATagainst anSTT_OBJECTexport ofa.prx, andSTT_TLSwithDTPMOD64plusDTPOFF64exit 0. On untouched code the threeNOTYPEcases exit 0 on every target.pr_overlap.pycannot compare this branch with #5021 (core/relinker/CMakeLists.txt) and #8076 (GuestModuleBuilder.cpp), because those do not merge withmain, and reports no other shared lines. Checked by hand: theCMakeLists.txthunk of #5021 starts at line 505, this PR adds three lines after 618; theGuestModuleBuilder.cpphunks of #8076 are at the includes and at lines 343 to 355, this PR adds one line after 291.Tested
Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.main(50757b01c6):guest_tls_export_referencesfails withAssertionError: ('notype-glob-dat', 'linux', 0, ''); a probe of all 21 runs showed exit 0 with both guest outputs for the threeNOTYPEcases on every target and exit 2 withGuest import/export type mismatch: tls_valueforOBJECT.guest_tls_export_referencespasses in 1.0 s (21 relinks);guest_tls,guest_own_tls_relocations,guest_export_lookupandguest_symbol_namespass, andctest -R 'guest|tls'passes 71 of 71.ctest --test-dir build-relinker -j 4: 245 tests, 241 passed,long_pathsskipped;select_tests(Windows symlink fixture,FileExistsError) andpatch_advisor_unit(build path with spaces, fix open in #10667) fail on this machine onmainas well;shader_cache_runtime_sourcestimed out at 180 s under parallel load and passed when rerun alone (108.1 s).python tools/check_conventions.py --base upstream/mainwith this title and description passed.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:08:51Z.
Review: APPROVED
Reviewed head
cd7b8bff00965f63c1e77a9082a062c795ed9970. The new guard is placed after the existing symbol type-mismatch check and rejects only referencedNOTYPEimports resolved to guestSTT_TLSexports. The fixture exercises the three non-TLS relocation forms across Linux, Windows and macOS, verifies no output is produced for rejected inputs, and includes unaffected controls for unreferenced imports, object exports and valid TLS relocations. The author reports the focused Windows suite and 245-test relinker suite with known baseline failures; the official Linux, Windows, macOS, ASAN, conventions, intake and labels checks pass. I could not independently run a local build here.