fix(relinker): require a non-empty PT_TLS for guest module TLS relocations #13915
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13915"
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-31T12:37:49Z.
What
#10730 made executable TLS relocations require a
PT_TLSwith a nonzerop_memsz; glibc gives an object a TLS module only for such aPT_TLS(rtld_setup_main_mapinelf/rtld.cfor the main program,_dl_map_object_from_fdinelf/dl-load.c, which skips an emptyPT_TLS, for loaded objects). Guest modules still use the old condition. Onb7d3fd3c52(line numbers below refer to it) the guest image reader accepts relocations that name the module's own TLS block whenever aPT_TLSheader exists, also one withp_memsz0: aDTPMOD64,DTPOFF64orTPOFF64against symbol 0 and aDTPMOD64orDTPOFF64against the zero-value section symbol ofownTlsBlockneed onlytls != nullptr(GuestImageReader.cpp:300-301), and one against anSTT_TLSsymbol the module defines needs only the symbol-table bound of line 211 (TLS symbol exceeds TLS segment), which a symbol with value 0 and size 0 passes whenp_memszis 0. What happens next depends on the target and the type: for aDTPMOD64orDTPOFF64against the section symbol of a module, plain or SCE-tagged, whosePT_TLShasp_fileszandp_memsz0, Linux output kept both relocations with exit 0;--windowsrefused theDTPMOD64withGuest TLS relocation has no TLS block(WindowsGuestModuleWriter.cpp:94) and--macoswithGuest TLS module relocation without a non-empty PT_TLS(MacOsImage.cpp:456), while both converted theDTPOFF64with exit 0.tls != nullptr && tls->MemorySize != 0where it checks a TLS relocation, uses it in place oftls != nullptrfor symbol 0 and the section symbol, and also requires it for a relocation against anSTT_TLSsymbol with a nonzero section index, as #10730 does for executables with symbol 0 and definedSTT_TLSsymbols. These relocations then fail asInvalid guest TLS relocation, the message the reader already gives a symbol-0 TLS relocation in a module withoutPT_TLS, on every target and before any output. Relocations against an undefinedSTT_TLSsymbol (an import from another module), modules with a nonemptyPT_TLSand modules without TLS relocations are unchanged. The predicate is computed at the point of use, not with the program header loop, so the header loop and itsPT_TLSchecks stay as they are.pr_overlap.py --branchreports no overlap with open pull requests.Tested
Windows 11, WinLibs GCC 15.2.0, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON, Ninja, Release), on015778c83e(based onb7d3fd3c52;mainatb8f0a6b202changed none of these files and merges cleanly):guest_own_tls_relocationsgains cases with aPT_TLSofp_fileszandp_memsz0 for a plain and an SCE-tagged module:DTPMOD64andDTPOFF64against the section symbol, andDTPMOD64,DTPOFF64andTPOFF64against symbol 0 and against a localSTT_TLSsymbol defined in section 1, must fail withInvalid guest TLS relocationand write neither the module nor the output, for Linux,--windowsand--macos; the same three relocations against the defined symbol with the fixture's nonemptyPT_TLSmust still convert on all three targets. Onb7d3fd3c52the test fails at the first case (exit 0 on Linux), and with only the first commit of this branch (94c6552030) at the first defined-symbol case (exit 0 on Linux); on015778c83eit passes, and so do the 48 tests matchingtls.ctest --test-dir build-relinker -j 5on015778c83e: 543 tests, 537 passed,long_pathsskipped;annotate_module, a Python test oftools/annotate_module.pythat does not run the relinker, timed out under the parallel load and passes alone in about 15.5 s (it sits close to its 20 s limit on this machine);select_testsand its three partsselect_tests_SelectGraphStateTests,select_tests_SelectBuildTestsandselect_tests_SelectArgumentTestsfail with the Windows symlink fixture'sFileExistsError, as onmainon this machine; this change touches nothing undertools/.python tools/check_conventions.py --base b7d3fd3c52with this title and description passed on015778c83e.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-31T12:39:40Z.
Review: APPROVED
Reviewed — looks good
The exact head
015778c83ef889b64980ddc96f621a768dc20350now rejects guest-module TLS relocations when the module has no non-emptyPT_TLS, while retaining the imported-symbol path.I ran
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13915against base60bdb061356db736928eee431cd8bd4c9ba68036: diff, conventions, Python syntax, test registration, and mergeability passed. The author reports an exact-head Windows relinker-only build, 48 TLS-focused tests, and a 543-test CTest run with 537 passing, one skipped, and six unrelated failures also present onmain. I did not build or run tests locally; hosted relinker jobs were still in progress at the latest refresh.