Skip to content

refactor(relinker): take the dynamic symbol type of TLS imports from the input symbol - #18161

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:refactor/relinker-tls-import-symbol-type
Nov 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:refactor/relinker-tls-import-symbol-type

Conversation

@roboterspinne

Copy link
Copy Markdown
Contributor

What

On c548802 (line numbers below refer to it), SysVDynamicSectionBuilder::BuildDynamicSection writes every import whose relocation is R_X86_64_DTPMOD64, DTPOFF64 or TPOFF64 with type STT_TLS, whatever type the input symbol has (tls ? STT_TLS : ref.SymbolType, core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp:93-95). #12341 (d6e9570) made the pipeline reject every TLS relocation against an undefined symbol that is not STT_TLS, and its description left removing this override for a follow-up, because the override no longer changes any type. This is that follow-up. The ELF gABI (Symbol Table, STT_TLS) states that thread-local storage relocations can only reference STT_TLS symbols, and the pipeline enforces it before any import is recorded. NidReference is built for the output in one place, nidRefs.push_back in extractRela (core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp:441), with SymbolType = st_info & 15 (line 439). A TLS relocation with symbol index 0 or against a defined STT_TLS symbol is folded and skipped (line 419). definedTlsSymbolValue throws for an undefined symbol that is not STT_TLS (lines 363-364) and for a defined one (367-368), and returns std::nullopt only for an undefined STT_TLS symbol (365-366). So every TLS reference that reaches line 441 already has SymbolType == STT_TLS. The other direction is closed as well: a non-TLS relocation against an STT_TLS symbol throws (lines 423-424, #11881). Between extraction and BuildDynamicSection (line 602), the IUnusedNidFilter::Filter calls at line 558 (strict filter, level 2) and line 577 (CFG/GOT filter, level 1) only copy a subset of the references (StrictNidFilter.cpp:209, UnusedNidFilter.cpp:46), and CompactPlt (line 596) copies the kept references and changes only RelocationTableOffset of JUMP_SLOT references (PltCompactor.cpp:17, :34). RelocationTypeValue and SymbolType stay as extracted. The only other caller of the builder is StrictNidFilterTests.cpp:554, which passes JUMP_SLOT references only. The written type now comes from the input symbol for every relocation type, and the output does not change for any input.

Tested

Windows 11, WinLibs GCC 15.2.0, relinker-only build directory configured with Ninja, Release, -DANYPS5_RELINKER_ONLY=ON and BUILD_TESTING=ON, on this branch based on 697b66b. The baseline, the counter-check and the timeout note come from the same branch based on e907e6d; between the two bases no cited file and no file under core/relinker/relinker/src/output or src/pipeline changed:

  • The branch was then rebased onto c548802. Between 697b66b and c548802 none of the files cited in the description and no file under core/relinker/relinker/src/output or src/pipeline changed (git diff --stat is empty), so the tests were not rerun after the rebase.
  • Baseline, untouched code: ctest --test-dir build-relinker -R '^(executable_tls_relocations|call_registry|call_registry_writer|strict_nid_filter|guest_tls|guest_tls_export_references|guest_own_tls_relocations|restricted_undefined_symbols_.*)$' --output-on-failure: 12/13 pass, and the 13th passes when rerun alone (see the timeout note below).
  • With the change: cmake --build build-relinker --parallel 4, then the same ctest command: 13/13 pass on 697b66b and on e907e6d.
  • Other builds ran on the machine at the same time. One test hit its ctest timeout once in each configuration and passed when rerun alone: restricted_undefined_symbols_guest_7 (20 s) on the baseline, and guest_own_tls_relocations (30 s) with the change, in an earlier run of the same command.
  • Counter-check, to show that the existing test checks the type on the new path: with the new line changed locally to write STT_OBJECT for an STT_TLS input type (not committed), ctest --test-dir build-relinker -R '^executable_tls_relocations$' --output-on-failure failed at test_executable_tls_relocations.py:152 with (4198432, 18, 'ImportedTls', 1, 0) instead of type 6. With the line restored it passes.
  • python tools/check_conventions.py --base upstream/main --head HEAD (upstream/main at c548802) with this title and description passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

@ycbuzi

ycbuzi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Tested ab03238ac7 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Linux: Debian 13 in ChromeOS's Linux environment on a Pentium Silver N6000 (4 cores, SSE4.2, no AVX), GCC 14.2.0, relinker-only build (-DANYPS5_RELINKER_ONLY=ON): run 1: 100% tests passed, 0 tests failed out of 856; run 2: 100% tests passed, 0 tests failed out of 856; run 3: 100% tests passed, 0 tests failed out of 856.

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@oneandonlydean
oneandonlydean merged commit da9790d into boykopovar:main Nov 13, 2026
14 checks passed
@roboterspinne
roboterspinne deleted the refactor/relinker-tls-import-symbol-type branch November 13, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants