WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTO #755

Draft
siantm wants to merge 1 commit from siantm/Longshot:fix/coff-thinlto-tls into main
First-time contributor

Type: fix · Risk: medium · Tested on: Windows 11, MSYS2 UCRT64 Clang 23.1.4 & LLVM-MinGW 23.1.5, game-free · Needs: Linux TLS/recorder checks and full native Windows llvm-mingw ThinLTO renderer link

Why

Under Windows COFF ThinLTO (-flto=thin -fuse-ld=lld), an inline thread_local variable at namespace scope can leave unresolved thread-local initialization routine references across translation units for mkwvk::prof_t and mkwvk::rec::t_arena. Fixing TLS ownership and initialization keeps cross-TU linkage coherent without enabling ThinLTO by default or claiming any FPS improvement.

Searching the issue tracker and PR history (ThinLTO, thread_local) found no matching bug issue (related COFF/ThinLTO context appears in #579 and #1122).

How to reproduce

Seen on: Windows 11, MSYS2 UCRT64 Clang 23.1.4 with lld (-static) and LLVM-MinGW Clang 23.1.5 with lld.
Settings and switches: C++20 -O2, comparing non-LTO native objects against -flto=thin -fuse-ld=lld.
Steps: run python -I -B tests/test_thinlto_tls.py --cxx clang++ --source-ref 71b1edd, then run python -I -B tests/test_thinlto_tls.py --cxx clang++ on this rebased branch (0796c1ec).
Expected: both native and ThinLTO executables compile, link across all three translation units (a.cpp, b.cpp, main.cpp), share one prof_t and t_arena per thread, separate threads, and drain queued Enc packets on boundary and thread exit.
Actual: on main @ 71b1edd, the native executable links and passes, while ThinLTO linking fails (exit code 1) with ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t and ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena.

What changed

Zero-initialize the profiler's POD prof_t at compile time with inline constinit thread_local ProfThread prof_t{};, and move rec::t_arena into a function-local static thread_local Arena accessor rec::t_arena() so its dynamic self-referential initialization and exit-time ~Arena() drain remain coherent across translation units under COFF ThinLTO.

  • gpu/vk/vk_internal.h: change inline thread_local ProfThread prof_t; to inline constinit thread_local ProfThread prof_t{};.
  • gpu/vk/vk_recorder.h: replace inline thread_local Arena t_arena; with inline Arena& t_arena() returning static thread_local Arena arena; and update drain(), fallback(), and Enc::Enc() callers to t_arena().
  • tests/recorder_sync_test.cpp, tests/test_recorder_sync.py: migrate all rec::t_arena test accesses and the fallback without the drain broken-variant source patch to t_arena().
  • tests/test_thinlto_tls.py: add a 3-TU C++20 game-free test compiling production profiler scopes and recorder core at -O2 (native and -flto=thin -fuse-ld=lld), with --source-ref support for before/after verification.
  • docs/development.md, docs/tested/2026-11-15-coff-thinlto-tls-siantm-check01.md: document the COFF ThinLTO TLS rule and reproduction steps, and preserve the initial check01 run record.

Measurements

Verdict: main @ 71b1edd reproduces both undefined COFF ThinLTO TLS initialization symbol errors at link time, while this rebased branch (0796c1ec) compiles, links, and passes both native and ThinLTO runs plus all completed recorder and profiler checks with zero run_all.py regressions.

Hardware: Windows 11, Intel Core i7-9700, 31.8 GiB usable RAM, MSYS2 UCRT64 Clang 23.1.4 + ld.lld + Vulkan headers (C:\msys64\ucrt64\include); Python 3.12.10 (also initially verified on 9e6f231d with LLVM-MinGW 23.1.5 + Python 3.14.7 in docs/tested/2026-11-15-coff-thinlto-tls-siantm-check01.md); no GPU used.
Scene: Game-free 3-TU C++20 cross-translation-unit TLS harness and real profiler/recorder consumer test binaries on Windows 11 (no game scene loaded).
Method: identical tests/test_thinlto_tls.py harness against origin/main (--source-ref 71b1edd) and rebased 0796c1ec, followed by tests/test_prof_sampling.py, tests/test_recorder_own_idle.py, tests/test_recorder_sync.py, and tests/run_all.py --changed origin/main.
How to reproduce: run python -I -B tests/test_thinlto_tls.py --cxx clang++ --source-ref 71b1edd, then python -I -B tests/test_thinlto_tls.py --cxx clang++ and python -I -B tests/test_recorder_sync.py --cxx clang++ --headers <vk-include> on commit 0796c1ec.

Check Before: main @ 71b1edd After: this PR @ 0796c1ec
test_thinlto_tls.py native C++20 -O2 Link + run pass Link + run pass
test_thinlto_tls.py -flto=thin -fuse-ld=lld Fail (exit 1): undefined TLS init for mkwvk::prof_t and mkwvk::rec::t_arena PASS (exit 0)
test_recorder_sync.py (all modes + broken variants) Timed out at 300s in initial PR draft PASS (exit 0 in 134.0s)
ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t
ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena
---- (rebased 0796c1ec)
PASS: native/ThinLTO production cross-TU TLS identity, thread isolation and Enc exit drain
PASS: nested phases bounded, slow paths exact once, totals unbiased, prof_full exact (400000 draws, 50212 timed)
PASS: RX_VK_PROF_ALL=1 times every scope exactly (400000 draws)
recorder own/idle: all passed
PASS recorder sync: identical streams, poisoned caller memory, coverage, fallback order; broken variants caught

Flags and settings

None (no switch is added and production optimization/LTO defaults do not change).

Testing

Tested: rebased commit 0796c1ec onto main @ 71b1edd under Windows 11 + MSYS2 UCRT64 Clang 23.1.4 (C:\msys64\ucrt64\include) + Python 3.12.10:

  • tests/test_thinlto_tls.py --source-ref 71b1edd: native passes, ThinLTO fails to link (exit 1) on both prof_t and t_arena.
  • tests/test_thinlto_tls.py on 0796c1ec: passes (exit 0).
  • tests/test_prof_sampling.py: passes (exit 0).
  • tests/test_recorder_own_idle.py: passes (all 22 switch cases and broken variants, exit 0).
  • tests/test_recorder_sync.py: passes completely in 134.0s (exit 0, resolving the earlier 300s timeout).
  • tests/test_doc_anchors.py, scripts/tested_configurations.py, scripts/check_third_party.py, git grep -n "\bt_arena\b" (zero non-accessor callers remain), and git diff --check origin/main..HEAD all pass cleanly.
  • python -I -B tests/run_all.py --changed origin/main: 31 passed, 7 failed, 2 skipped in 140 s — all 7 failures (tests/test_fsr_uniform_ownership.py, tests/test_oot_state_tap.py, tests/test_crash_dialog.py, tests/test_replay_write_order.py, tests/test_walk_key.py, tests/test_vk_occlusion_queries.py, tests/test_prepare_stall.py) are pre-existing on unmodified main @ 71b1edd (verified in the 32-test main @ 71b1edd Windows baseline, alongside tests/test_pipeline_cache_file.py, tests/test_pipeline_play_cache.py, tests/test_linux_preflight.py, tests/test_make_game_cache.py, tests/test_bug_report_defaults.py, tests/test_job_queue.py, tests/test_run_all_changed.py, tests/test_coverage_run.py, tests/test_dlss_feature_size.py, tests/test_import_reach.py, tests/test_spawn_emit.py, tests/test_portable_builder_home.py, tests/test_tested_configurations.py, tests/test_fpx_sticky.py, tests/test_pending_guest_import.py, tests/test_missing_nup.py, tests/test_guest_imported.py, tests/test_audio_output_devices.py, tests/test_fastfp_fma.py, tests/test_failed_compile_keeps_objects.py, tests/test_pads_after_menu.py, tests/test_auto_handheld.py, tests/test_lift_lookups.py, tests/test_portable_builder_startup.py, tests/test_crt_options.py).

Not tested: full native longshot_vk.dll / Linux renderer ThinLTO link and in-game run, and native Linux tests/run_all.py. Note: scripts/check_guide_screenshots.py --review-sources already fails on main @ 71b1edd because gpu/vk/vk_internal.h changed in earlier main commits (#474/#1107) since the guide screenshot manifest hashes.

Must be tested:

  • Linux and Windows, native toolchain and full renderer link: run tests/test_thinlto_tls.py, tests/test_recorder_sync.py, and python -I -B tests/run_all.py on Linux, and link the full Windows Vulkan renderer under llvm-mingw with COFF ThinLTO enabled, expecting clean links and passing tests (Test Farm: @Beanstalk linux, plus by hand for full Windows renderer ThinLTO link).

Risks

What could break: cross-TU per-thread Arena initialization or thread-exit ~Arena() drain ordering if a recorder call runs after thread-local destruction begins.

Turning it off: revert the commit (no runtime switch is added).

Compatibility: Nothing changes for saves, longshot_options.ini, shader/pipeline caches, or public MKWVK_API_VERSION ABI.

Issues

See #755

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A file in docs/tested/ for each new measured run (format in docs/tested-configurations.md).
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Docs updated.
**Type:** fix · **Risk:** medium · **Tested on:** Windows 11, MSYS2 UCRT64 Clang 23.1.4 & LLVM-MinGW 23.1.5, game-free · **Needs:** Linux TLS/recorder checks and full native Windows llvm-mingw ThinLTO renderer link ## Why Under Windows COFF ThinLTO (`-flto=thin -fuse-ld=lld`), an `inline thread_local` variable at namespace scope can leave unresolved `thread-local initialization routine` references across translation units for `mkwvk::prof_t` and `mkwvk::rec::t_arena`. Fixing TLS ownership and initialization keeps cross-TU linkage coherent without enabling ThinLTO by default or claiming any FPS improvement. Searching the issue tracker and PR history (`ThinLTO`, `thread_local`) found no matching bug issue (related COFF/ThinLTO context appears in `#579` and `#1122`). ## How to reproduce **Seen on:** Windows 11, MSYS2 UCRT64 Clang 23.1.4 with `lld` (`-static`) and LLVM-MinGW Clang 23.1.5 with `lld`. **Settings and switches:** C++20 `-O2`, comparing non-LTO native objects against `-flto=thin -fuse-ld=lld`. **Steps:** run `python -I -B tests/test_thinlto_tls.py --cxx clang++ --source-ref 71b1edd`, then run `python -I -B tests/test_thinlto_tls.py --cxx clang++` on this rebased branch (`0796c1ec`). **Expected:** both native and ThinLTO executables compile, link across all three translation units (`a.cpp`, `b.cpp`, `main.cpp`), share one `prof_t` and `t_arena` per thread, separate threads, and drain queued `Enc` packets on boundary and thread exit. **Actual:** on `main @ 71b1edd`, the native executable links and passes, while ThinLTO linking fails (exit code 1) with `ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t` and `ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena`. ## What changed Zero-initialize the profiler's POD `prof_t` at compile time with `inline constinit thread_local ProfThread prof_t{};`, and move `rec::t_arena` into a function-local `static thread_local Arena` accessor `rec::t_arena()` so its dynamic self-referential initialization and exit-time `~Arena()` drain remain coherent across translation units under COFF ThinLTO. - `gpu/vk/vk_internal.h`: change `inline thread_local ProfThread prof_t;` to `inline constinit thread_local ProfThread prof_t{};`. - `gpu/vk/vk_recorder.h`: replace `inline thread_local Arena t_arena;` with `inline Arena& t_arena()` returning `static thread_local Arena arena;` and update `drain()`, `fallback()`, and `Enc::Enc()` callers to `t_arena()`. - `tests/recorder_sync_test.cpp`, `tests/test_recorder_sync.py`: migrate all `rec::t_arena` test accesses and the `fallback without the drain` broken-variant source patch to `t_arena()`. - `tests/test_thinlto_tls.py`: add a 3-TU C++20 game-free test compiling production profiler scopes and recorder core at `-O2` (native and `-flto=thin -fuse-ld=lld`), with `--source-ref` support for before/after verification. - `docs/development.md`, `docs/tested/2026-11-15-coff-thinlto-tls-siantm-check01.md`: document the COFF ThinLTO TLS rule and reproduction steps, and preserve the initial `check01` run record. ## Measurements **Verdict:** `main @ 71b1edd` reproduces both undefined COFF ThinLTO TLS initialization symbol errors at link time, while this rebased branch (`0796c1ec`) compiles, links, and passes both native and ThinLTO runs plus all completed recorder and profiler checks with zero `run_all.py` regressions. Hardware: Windows 11, Intel Core i7-9700, 31.8 GiB usable RAM, MSYS2 UCRT64 Clang 23.1.4 + `ld.lld` + Vulkan headers (`C:\msys64\ucrt64\include`); Python 3.12.10 (also initially verified on `9e6f231d` with LLVM-MinGW 23.1.5 + Python 3.14.7 in `docs/tested/2026-11-15-coff-thinlto-tls-siantm-check01.md`); no GPU used. Scene: Game-free 3-TU C++20 cross-translation-unit TLS harness and real profiler/recorder consumer test binaries on Windows 11 (no game scene loaded). Method: identical `tests/test_thinlto_tls.py` harness against `origin/main` (`--source-ref 71b1edd`) and rebased `0796c1ec`, followed by `tests/test_prof_sampling.py`, `tests/test_recorder_own_idle.py`, `tests/test_recorder_sync.py`, and `tests/run_all.py --changed origin/main`. How to reproduce: run `python -I -B tests/test_thinlto_tls.py --cxx clang++ --source-ref 71b1edd`, then `python -I -B tests/test_thinlto_tls.py --cxx clang++` and `python -I -B tests/test_recorder_sync.py --cxx clang++ --headers <vk-include>` on commit `0796c1ec`. | Check | Before: main @ 71b1edd | After: this PR @ 0796c1ec | |---|---|---| | `test_thinlto_tls.py` native C++20 `-O2` | Link + run pass | Link + run pass | | `test_thinlto_tls.py` `-flto=thin -fuse-ld=lld` | Fail (exit 1): undefined TLS init for `mkwvk::prof_t` and `mkwvk::rec::t_arena` | `PASS` (exit 0) | | `test_recorder_sync.py` (all modes + broken variants) | Timed out at 300s in initial PR draft | `PASS` (exit 0 in `134.0s`) | ``` ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena ---- (rebased 0796c1ec) PASS: native/ThinLTO production cross-TU TLS identity, thread isolation and Enc exit drain PASS: nested phases bounded, slow paths exact once, totals unbiased, prof_full exact (400000 draws, 50212 timed) PASS: RX_VK_PROF_ALL=1 times every scope exactly (400000 draws) recorder own/idle: all passed PASS recorder sync: identical streams, poisoned caller memory, coverage, fallback order; broken variants caught ``` ### Flags and settings None (no switch is added and production optimization/LTO defaults do not change). ## Testing **Tested:** rebased commit `0796c1ec` onto `main @ 71b1edd` under Windows 11 + MSYS2 UCRT64 Clang 23.1.4 (`C:\msys64\ucrt64\include`) + Python 3.12.10: - `tests/test_thinlto_tls.py --source-ref 71b1edd`: native passes, ThinLTO fails to link (exit 1) on both `prof_t` and `t_arena`. - `tests/test_thinlto_tls.py` on `0796c1ec`: passes (`exit 0`). - `tests/test_prof_sampling.py`: passes (`exit 0`). - `tests/test_recorder_own_idle.py`: passes (all 22 switch cases and broken variants, `exit 0`). - `tests/test_recorder_sync.py`: passes completely in `134.0s` (`exit 0`, resolving the earlier 300s timeout). - `tests/test_doc_anchors.py`, `scripts/tested_configurations.py`, `scripts/check_third_party.py`, `git grep -n "\bt_arena\b"` (zero non-accessor callers remain), and `git diff --check origin/main..HEAD` all pass cleanly. - `python -I -B tests/run_all.py --changed origin/main`: `31 passed, 7 failed, 2 skipped in 140 s` — all 7 failures (`tests/test_fsr_uniform_ownership.py`, `tests/test_oot_state_tap.py`, `tests/test_crash_dialog.py`, `tests/test_replay_write_order.py`, `tests/test_walk_key.py`, `tests/test_vk_occlusion_queries.py`, `tests/test_prepare_stall.py`) are pre-existing on unmodified `main @ 71b1edd` (verified in the 32-test `main @ 71b1edd` Windows baseline, alongside `tests/test_pipeline_cache_file.py`, `tests/test_pipeline_play_cache.py`, `tests/test_linux_preflight.py`, `tests/test_make_game_cache.py`, `tests/test_bug_report_defaults.py`, `tests/test_job_queue.py`, `tests/test_run_all_changed.py`, `tests/test_coverage_run.py`, `tests/test_dlss_feature_size.py`, `tests/test_import_reach.py`, `tests/test_spawn_emit.py`, `tests/test_portable_builder_home.py`, `tests/test_tested_configurations.py`, `tests/test_fpx_sticky.py`, `tests/test_pending_guest_import.py`, `tests/test_missing_nup.py`, `tests/test_guest_imported.py`, `tests/test_audio_output_devices.py`, `tests/test_fastfp_fma.py`, `tests/test_failed_compile_keeps_objects.py`, `tests/test_pads_after_menu.py`, `tests/test_auto_handheld.py`, `tests/test_lift_lookups.py`, `tests/test_portable_builder_startup.py`, `tests/test_crt_options.py`). **Not tested:** full native `longshot_vk.dll` / Linux renderer ThinLTO link and in-game run, and native Linux `tests/run_all.py`. Note: `scripts/check_guide_screenshots.py --review-sources` already fails on `main @ 71b1edd` because `gpu/vk/vk_internal.h` changed in earlier `main` commits (`#474`/`#1107`) since the guide screenshot manifest hashes. **Must be tested:** - Linux and Windows, native toolchain and full renderer link: run `tests/test_thinlto_tls.py`, `tests/test_recorder_sync.py`, and `python -I -B tests/run_all.py` on Linux, and link the full Windows Vulkan renderer under `llvm-mingw` with COFF ThinLTO enabled, expecting clean links and passing tests (Test Farm: `@Beanstalk` linux, plus by hand for full Windows renderer ThinLTO link). ## Risks **What could break:** cross-TU per-thread `Arena` initialization or thread-exit `~Arena()` drain ordering if a recorder call runs after thread-local destruction begins. **Turning it off:** revert the commit (no runtime switch is added). **Compatibility:** Nothing changes for saves, `longshot_options.ini`, shader/pipeline caches, or public `MKWVK_API_VERSION` ABI. ## Issues See #755 ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A file in `docs/tested/` for each new measured run (format in `docs/tested-configurations.md`). - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Docs updated.
fix(vk): keep TLS initialization coherent under COFF ThinLTO
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
484daadbcd
Focused extraction of local Longshot changes: 073ed616. Authored tests and verification limits included; no game-derived artifacts.

Assisted-by: OpenAI Codex
HumanBean force-pushed fix/coff-thinlto-tls from 484daadbcd
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 4150b1f2e9
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 4s
Third-party parts / As their notes say (pull_request) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-15 18:45:01 +00:00
Compare
siantm force-pushed fix/coff-thinlto-tls from 4150b1f2e9
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 4s
Third-party parts / As their notes say (pull_request) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
to 0796c1ec62
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
2026-11-16 15:27:17 +00:00
Compare
Author
First-time contributor

Rebased onto origin/main (71b1edd) as 0796c1ec (resolving a docs/development.md conflict with the Links skipped, and the compile commands section added on main):

  • Before (origin/main @ 71b1edd): tests/test_thinlto_tls.py --source-ref 71b1edd under MSYS2 UCRT64 Clang 23.1.4 + ld.lld passes native C++20 -O2 and fails ThinLTO linking (exit 1) on ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t and ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena.
  • After (0796c1ec):
    • tests/test_thinlto_tls.py passes both native and -flto=thin -fuse-ld=lld (exit 0).
    • tests/test_prof_sampling.py passes (exit 0).
    • tests/test_recorder_own_idle.py passes (exit 0, all 22 switch cases + broken variants).
    • tests/test_recorder_sync.py now runs to completion and passes (exit 0 in 134.0s, resolving the previous 300s wrapper timeout).
    • tests/test_doc_anchors.py, scripts/tested_configurations.py, scripts/check_third_party.py, git grep -n "\bt_arena\b", and git diff --check origin/main..HEAD are all clean.
    • python -I -B tests/run_all.py --changed origin/main: 31 passed, 7 failed, 2 skipped — all 7 failures are pre-existing on main @ 71b1edd.
  • Updated PR description to match .forgejo/pull_request_template.md cleanly (WIP: retained pending Linux checks and a full llvm-mingw COFF ThinLTO renderer link).
Rebased onto `origin/main` (`71b1edd`) as `0796c1ec` (resolving a `docs/development.md` conflict with the `Links skipped, and the compile commands` section added on `main`): - **Before (`origin/main @ 71b1edd`)**: `tests/test_thinlto_tls.py --source-ref 71b1edd` under MSYS2 UCRT64 Clang 23.1.4 + `ld.lld` passes native C++20 `-O2` and fails ThinLTO linking (`exit 1`) on `ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_t` and `ld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena`. - **After (`0796c1ec`)**: - `tests/test_thinlto_tls.py` passes both native and `-flto=thin -fuse-ld=lld` (`exit 0`). - `tests/test_prof_sampling.py` passes (`exit 0`). - `tests/test_recorder_own_idle.py` passes (`exit 0`, all 22 switch cases + broken variants). - **`tests/test_recorder_sync.py` now runs to completion and passes** (`exit 0` in `134.0s`, resolving the previous 300s wrapper timeout). - `tests/test_doc_anchors.py`, `scripts/tested_configurations.py`, `scripts/check_third_party.py`, `git grep -n "\bt_arena\b"`, and `git diff --check origin/main..HEAD` are all clean. - `python -I -B tests/run_all.py --changed origin/main`: `31 passed, 7 failed, 2 skipped` — all 7 failures are pre-existing on `main @ 71b1edd`. - Updated PR description to match `.forgejo/pull_request_template.md` cleanly (`WIP:` retained pending Linux checks and a full `llvm-mingw` COFF ThinLTO renderer link).
Owner

Could you explain briefly what this actually fixes for you?

Could you explain briefly what this actually fixes for you?
HumanBean changed title from WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTO to fix(vk): keep TLS initialization coherent under COFF ThinLTO 2026-11-17 17:56:05 +00:00
HumanBean changed title from fix(vk): keep TLS initialization coherent under COFF ThinLTO to WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTO 2026-11-17 17:56:19 +00:00
Author
First-time contributor

It fixes a link failure, not something a player sees today. With ThinLTO on Windows (llvm-mingw, -flto=thin -fuse-ld=lld), prof_t and rec::t_arena are inline thread_local variables that each translation unit references through a TLS init routine, and lld can't resolve those routines across units. The link stops with undefined symbol: thread-local initialization routine for mkwvk::prof_t (and …rec::t_arena). tests/test_thinlto_tls.py --source-ref <main> reproduces it. I hit it while trying a local ThinLTO build of the renderer. Main doesn't build with ThinLTO, so the normal builds are unaffected. The change makes prof_t constinit and moves t_arena behind an accessor so it links either way, with no behaviour change in the default build.

It fixes a link failure, not something a player sees today. With ThinLTO on Windows (llvm-mingw, `-flto=thin -fuse-ld=lld`), `prof_t` and `rec::t_arena` are `inline thread_local` variables that each translation unit references through a TLS init routine, and lld can't resolve those routines across units. The link stops with `undefined symbol: thread-local initialization routine for mkwvk::prof_t` (and `…rec::t_arena`). `tests/test_thinlto_tls.py --source-ref <main>` reproduces it. I hit it while trying a local ThinLTO build of the renderer. Main doesn't build with ThinLTO, so the normal builds are unaffected. The change makes `prof_t` `constinit` and moves `t_arena` behind an accessor so it links either way, with no behaviour change in the default build.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/coff-thinlto-tls:siantm-fix/coff-thinlto-tls'
git switch 'siantm-fix/coff-thinlto-tls'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!755
No description provided.