fix(relinker): reject non-TLS executable relocations against STT_TLS symbols #11881
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11881"
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-27T11:13:25Z.
What
extractRelainRelinkerPipeline.cppchecks the symbol type only forR_X86_64_DTPMOD64,DTPOFF64andTPOFF64(line 345); a relocation of any other type against anSTT_TLSsymbol, defined or undefined, is accepted without a symbol-type check (line 406). On untouched801d5b9bc1thetest_executable_tls_relocations.pyfixture with oneR_X86_64_64,PC32,GLOB_DATor32relocation against the definedSTT_TLSsymbolTlsor the undefinedSTT_TLSsymbolImportedTlsconverts with exit 0 for Linux and--lazy-binding, and for macOS withR_X86_64_64andGLOB_DAT; the Linux output carries, for example,GLOB_DATat 0x401000 againstTlstypedSTT_TLS. Windows fails on the same inputs only later and for unrelated reasons (ELF imports have no DT_NEEDED libraries,Relocation type 2 is not supported for this target).STT_TLScan be referenced only by special thread-local storage relocations, and that a defined one gives the assigned offset for the symbol, not the actual address, while the x86-64 psABI computesR_X86_64_64,PC32,32,GLOB_DATandJUMP_SLOTfromSas an address.GuestImageReader.cpp:267already rejectsR_X86_64_64,GLOB_DATandJUMP_SLOTagainstSTT_TLSin guest modules (Invalid guest symbol relocation).extractRelanow throwsNon-TLS relocation names an STT_TLS symbolwith the relocation entry's offset right aftersymbolEntryPos(two lines), mirroring the converse checkTLS relocation names a defined symbol that is not STT_TLS(line 345); it runs forDT_RELAandDT_JMPRELbefore every target's writer, so all four targets fail with the same message and write no output. TLS relocations againstSTT_TLSsymbols, imported or defined, are unchanged. This changes one expectation of #10017:test_import_symbol_types.pyrelinksGLOB_DATandJUMP_SLOTimports for every type value inrange(16)and expected type 6 to relink typedSTT_TLS; nothing in #10017 or its review names a title or loader that uses such an import, so type 6 is covered only by the loop, and it now expects exit 2 with the new message and no output while the other 15 types keep their assertion.test_executable_tls_relocations.pyrelinksR_X86_64_64,PC32,GLOB_DATand32againstTlsandImportedTlson Linux,--lazy-binding,--windowsand--macos(32 cases,symbol_bytes=96so that macOS also reaches exit 0 onmain) and asserts exit 2,FAIL: Non-TLS relocation names an STT_TLS symbol (offset 0x4700)and no output; the same four relocations against theSTT_OBJECTsymbolDatastill convert on Linux.JUMP_SLOTinDT_RELAis not used there becauseSysVDynamicSectionBuilder.cpp:122already rejects it onmain(JUMP_SLOT relocation is not aligned to the original .rela.plt entry size); the changed type-6 case oftest_import_symbol_types.pycoversJUMP_SLOTinDT_JMPRELandGLOB_DATinDT_RELAwith global and weak binding.pr_overlap.pyreports no shared lines with open pull requests that merge withmain. It cannot compare this branch with #10861 (RelinkerPipeline.cpp), because that pull request does not merge withmain. Checked by hand at #10861's head8a4fa9adf7: itsRelinkerPipeline.cpphunks are at the includes, afterkEtCoreand from line 409 of its base on, not at thesymbolEntryPosline inextractRela(line 393 onmain) where this PR adds the check; a trial merge of this branch with #10861 conflicts only inCodeInstructionCollector.cpp, asmainwith #10861 does.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.801d5b9bc1executable_tls_relocationsfails at the first new case withAssertionError: ('linux-non-tls-1-1', 0, '')andimport_symbol_typeswithAssertionError: (6, 1, 0, ''). Run one by one there, the 32 new cases give exit 0 with an output on Linux and--lazy-bindingfor all four types and on macOS forR_X86_64_64andGLOB_DAT, and exit 2 on Windows withELF imports have no DT_NEEDED librariesorRelocation type 2/10 is not supported for this targetand on macOS with the latter; the four type-6 cases ofimport_symbol_typesgive exit 0. With the change every one of these cases exits 2 with the new message and no output, and the fourDatacontrols still exit 0.executable_tls_relocationspassed in 14.1 s alone (22.5 s in the focused run under load; 8.7 s for the file ofmain) andimport_symbol_typesin 4.1 s alone.ctest -R 'tls|import_symbol|import|executable_'onb6c9e39abb: 66 tests passed, among themguest_tls_export_references,guest_own_tls_relocations,linux_named_imports,windows_named_imports,weak_importsandexecutable_export_bounds.ctest --test-dir build-relinker -j 5onb6c9e39abb: 369 tests, 366 passed,long_pathsskipped; failures known on this machine onmainas well:select_tests(Windows symlink fixture) andpatch_advisor_unit(path with spaces, which open #10667 fixes); both failed again alone.python tools/check_conventions.py --base upstream/mainwith this title and description passed onb6c9e39abb.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 rooklz on 2026-10-27T11:58:00Z.
Review: APPROVED
Build-verified on macOS at head
b6c9e39abb(ANYPS5_RELINKER_ONLY build, touched suites, full cest 361/361 — also covers the pending macOS CI lanes).src/reverted to base801d5b9bc1,linux-non-tls-1-1(R_X86_64_64 against the defined STT_TLS symbol) and the STT_TLS import case in test_import_symbol_types.py both convert with exit 0, exactly as the body describes; at head both fail with the new message and no output file.isTlsRelocationguards DTPMOD64/DTPOFF64/TPOFF64 so legitimate TLS relocs against STT_TLS symbols still pass (the suite's original cases) and the newnon-tls-*-datapositive controls confirm ordinary symbols keep converting on every target.801d5b9bc1and current main, so the merge is trivial.Nothing blocking.