WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTO #755
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!755
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:fix/coff-thinlto-tls"
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?
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), aninline thread_localvariable at namespace scope can leave unresolvedthread-local initialization routinereferences across translation units formkwvk::prof_tandmkwvk::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#579and#1122).How to reproduce
Seen on: Windows 11, MSYS2 UCRT64 Clang 23.1.4 with
lld(-static) and LLVM-MinGW Clang 23.1.5 withlld.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 runpython -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 oneprof_tandt_arenaper thread, separate threads, and drain queuedEncpackets on boundary and thread exit.Actual: on
main @ 71b1edd, the native executable links and passes, while ThinLTO linking fails (exit code 1) withld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_tandld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena.What changed
Zero-initialize the profiler's POD
prof_tat compile time withinline constinit thread_local ProfThread prof_t{};, and moverec::t_arenainto a function-localstatic thread_local Arenaaccessorrec::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: changeinline thread_local ProfThread prof_t;toinline constinit thread_local ProfThread prof_t{};.gpu/vk/vk_recorder.h: replaceinline thread_local Arena t_arena;withinline Arena& t_arena()returningstatic thread_local Arena arena;and updatedrain(),fallback(), andEnc::Enc()callers tot_arena().tests/recorder_sync_test.cpp,tests/test_recorder_sync.py: migrate allrec::t_arenatest accesses and thefallback without the drainbroken-variant source patch tot_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-refsupport 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 initialcheck01run record.Measurements
Verdict:
main @ 71b1eddreproduces 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 zerorun_all.pyregressions.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 on9e6f231dwith LLVM-MinGW 23.1.5 + Python 3.14.7 indocs/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.pyharness againstorigin/main(--source-ref 71b1edd) and rebased0796c1ec, followed bytests/test_prof_sampling.py,tests/test_recorder_own_idle.py,tests/test_recorder_sync.py, andtests/run_all.py --changed origin/main.How to reproduce: run
python -I -B tests/test_thinlto_tls.py --cxx clang++ --source-ref 71b1edd, thenpython -I -B tests/test_thinlto_tls.py --cxx clang++andpython -I -B tests/test_recorder_sync.py --cxx clang++ --headers <vk-include>on commit0796c1ec.71b1edd0796c1ectest_thinlto_tls.pynative C++20-O2test_thinlto_tls.py-flto=thin -fuse-ld=lldmkwvk::prof_tandmkwvk::rec::t_arenaPASS(exit 0)test_recorder_sync.py(all modes + broken variants)PASS(exit 0 in134.0s)Flags and settings
None (no switch is added and production optimization/LTO defaults do not change).
Testing
Tested: rebased commit
0796c1econtomain @ 71b1eddunder 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 bothprof_tandt_arena.tests/test_thinlto_tls.pyon0796c1ec: 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 in134.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), andgit diff --check origin/main..HEADall 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 unmodifiedmain @ 71b1edd(verified in the 32-testmain @ 71b1eddWindows baseline, alongsidetests/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 Linuxtests/run_all.py. Note:scripts/check_guide_screenshots.py --review-sourcesalready fails onmain @ 71b1eddbecausegpu/vk/vk_internal.hchanged in earliermaincommits (#474/#1107) since the guide screenshot manifest hashes.Must be tested:
tests/test_thinlto_tls.py,tests/test_recorder_sync.py, andpython -I -B tests/run_all.pyon Linux, and link the full Windows Vulkan renderer underllvm-mingwwith COFF ThinLTO enabled, expecting clean links and passing tests (Test Farm:@Beanstalklinux, plus by hand for full Windows renderer ThinLTO link).Risks
What could break: cross-TU per-thread
Arenainitialization 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 publicMKWVK_API_VERSIONABI.Issues
See #755
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.484daadbcd4150b1f2e94150b1f2e90796c1ec62Rebased onto
origin/main(71b1edd) as0796c1ec(resolving adocs/development.mdconflict with theLinks skipped, and the compile commandssection added onmain):origin/main @ 71b1edd):tests/test_thinlto_tls.py --source-ref 71b1eddunder MSYS2 UCRT64 Clang 23.1.4 +ld.lldpasses native C++20-O2and fails ThinLTO linking (exit 1) onld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::prof_tandld.lld: error: undefined symbol: thread-local initialization routine for mkwvk::rec::t_arena.0796c1ec):tests/test_thinlto_tls.pypasses both native and-flto=thin -fuse-ld=lld(exit 0).tests/test_prof_sampling.pypasses (exit 0).tests/test_recorder_own_idle.pypasses (exit 0, all 22 switch cases + broken variants).tests/test_recorder_sync.pynow runs to completion and passes (exit 0in134.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", andgit diff --check origin/main..HEADare all clean.python -I -B tests/run_all.py --changed origin/main:31 passed, 7 failed, 2 skipped— all 7 failures are pre-existing onmain @ 71b1edd..forgejo/pull_request_template.mdcleanly (WIP:retained pending Linux checks and a fullllvm-mingwCOFF ThinLTO renderer link).Could you explain briefly what this actually fixes for you?
WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTOto fix(vk): keep TLS initialization coherent under COFF ThinLTOfix(vk): keep TLS initialization coherent under COFF ThinLTOto WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTOIt fixes a link failure, not something a player sees today. With ThinLTO on Windows (llvm-mingw,
-flto=thin -fuse-ld=lld),prof_tandrec::t_arenaareinline thread_localvariables that each translation unit references through a TLS init routine, and lld can't resolve those routines across units. The link stops withundefined 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 makesprof_tconstinitand movest_arenabehind an accessor so it links either way, with no behaviour change in the default build.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.