fix(relinker): reject out-of-range executable TLS symbols #11058
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11058"
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 plexerPK on 2026-10-25T16:07:47Z.
What
Reject defined STT_TLS symbols whose value or size falls outside the nonempty PT_TLS segment before folding executable TLS relocations. Previously an out-of-range symbol could convert successfully. The subtraction-safe check accepts an empty symbol at the segment end and preserves the missing/empty-TLS diagnostics introduced by #10730.
Tested
macOS arm64, relinker-only Release build; synthetic fixtures, no title or guest execution. Exact head
5f4c8cb9278af74518872a3453ddf9fbb21db87con main35ac3402c80b152983e8aa11196835d3a16370bf. The original baseline regression against main8864d0e3230ccac2603366474a43f880523a1d4bfailed because value 37, size 0 is accepted with exit 0. After this rebase and a Release rebuild, 7/7 focused CTests pass: executable_tls_relocations, guest_own_tls_relocations, guest_tls, tls_diagnostics, executable_export_bounds, linux_executable_exports and macos_executable_exports.The three affected #8076 suites also pass on this combined tree: control_flow_graph, sce_code_extent and sce_module_code_extent (10/10 focused CTests in total).
Coverage includes three invalid and two valid value/size pairs across Linux, lazy Linux, Windows and macOS conversion (20 cases), plus the unchanged 24 empty-TLS diagnostic cases. No native Linux/Windows guest runtime, GPU or hosted-CI result is claimed.
Conventions and diff checks pass. #8076 merged first at
b744c37f4eeb63f7fff9fd7a6928cd4081591283on 2026-10-26. This branch is rebased onto main containing that merge; the rebase is patch-equivalent, without conflict or changes to the TLS fix. Current #10947 and #11038 compose cleanly in source checks and implement distinct guards. The official overlap checker could not compare #10792 and #10861 because they conflict with the base; their exact authored diffs were reviewed manually and affect syscall routing and tail analysis rather than this TLS guard. No duplicate TLS-bounds implementation was found.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 thepoppfish on 2026-10-25T16:27:08Z.
Review: APPROVED
Reviewed exact head
f76d3bc51c511df4a55430ced1c93b6e44cb6b67against current main0119103fa9ed65a894a931da02b6510669991b45. Approve; no actionable findings in this focused review.The symbol extent is checked against
PT_TLS.p_memsz, including zero-fill, before folding local TLS relocations. The short-circuit subtraction avoids unsigned overflow, permits a zero-sized symbol exactly at the segment end, and keeps missing/empty-TLS handling separate. This matches the executable/DSO TLS symbol-offset model in ELF Handling For Thread-Local Storage, section 2. Imported-symbol handling and relocation addends are unchanged.Independent Windows 11 build 26200 validation, Python 3.14.7, MSYS2 UCRT64 GCC 16.2.0-6, CMake 4.3.1 and Ninja 1.13.2:
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, targetrelinker, 88 Ninja steps each.elf_offsets,macos_empty_tlsandwindows_tls_thread_pointer. The unchangedguest_tlstest also exercises the Windows loader and six generated Windows programs returning42 on each version.test_executable_tls_relocations.pyagainst the unchanged main binary fails at the new regression: Linux value37, size0 is accepted with exit0. This is the expected assertion failure, not a build/setup error.origin/mainand whitespace checks pass; both source worktrees remain clean.Linux and macOS are output-conversion/inspection targets here. No native Linux/macOS execution, full system-library build, commercial title, GPU, console or hosted-CI validation is claimed. The Windows loader/runtime results above are synthetic fixtures.
Reproduction, using the two pinned checkouts and a compiler/runtime on PATH:
The final command should exit1 with
AssertionError: ('linux', 37, 0, 0, ''). Use the platform's executable filename.Complete additional paired CLI probe
Save as
probe-executable-tls-bounds.py, then run:The head checkout is asserted by commit ID; build the main binary from the pinned main commit above.
AI-assisted review and probe; commands and native outcomes above were run locally.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T16:48:03Z.
Review: COMMENTED
Manual overlap follow-up: merging the current #11058 and #8076 heads conflicts in
RelinkerPipeline.cppand several relinker files/tests, including the technical-debt entry. There is also a semantic interaction: #8076 changes the TLS relocation requirement from a non-emptyPT_TLSto anyPT_TLS, while this PR adds a bounds check against the non-empty segment. Please coordinate with #8076’s author on merge order, state any dependency, and verify the combined TLS behavior/tests before merging either branch.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T16:50:16Z.
Review: COMMENTED
I manually checked the overlap with #8076. The current heads do not combine cleanly:
git merge-treereports conflicts inRelinkerPipeline.cpp,RelativeJumpTables.cpp,GuestModuleBuilder.cpp, several tests anddocs/dev/debt/relinker.md. There is also a TLS-specific behavior interaction: #8076 changes the relocation prerequisite from a non-emptyPT_TLSto anyPT_TLS, while this PR checks defined TLS symbol bounds against a non-empty segment. Please coordinate with #8076’s author on order and verify the combined TLS cases before merging; recordDepends onif the order is required.