tests: fail when gta6rt.exe has TLS callbacks (TEST-GTA6RT-NO-TLS-CALLBACKS) #2225
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2225"
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 ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-26T07:31:33Z.
Claimed in the coordination issue as: TEST-GTA6RT-NO-TLS-CALLBACKS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185302665)
Depends on: #2195 (this test fails on current main by design and passes once #2195 is merged)
What and why
A thread_local with a destructor in gta6rt gives gta6rt.exe two TLS callbacks (
__dyn_tls_init,__dyn_tls_dtor). The UCRT accepts only one_register_thread_local_exe_atexit_callbackper process and the title registers its own, so the game exits at startup with 0xC0000409 (#2195, RT-XMEM-STARTUP-FASTFAIL). Nothing stopped that from coming back; this is the guard I suggested in my test report on #2195.runtime/test/check_pe_tls_callbacks.pyreads the PE32+ TLS directory of the file it is given, walksAddressOfCallBacksto its zero terminator, and exits 1 if any callback is listed. Standard library only.runtime/CMakeLists.txtregisters it as the CTestgta6rt_no_tls_callbackson$<TARGET_FILE:gta6rt>(next torun_module_names).tests/test_check_pe_tls_callbacks.py(stdlib, run by ci.yml aspython -I) checks the parser on two in-memory PE32+ images, one with callbacks and one without, plus the exit codes for a non-PE and a missing file. It needs no MSVC and no game data.Trivially destructible thread_local data adds no callback and stays allowed. The check is stricter than strictly needed: any future TLS callback in gta6rt.exe will fail it and have to be discussed.
CI note: this pull request's CI will be red on
gta6rt_no_tls_callbacksuntil #2195 is merged, because main still has the two callbacks. I think it should wait for #2195 rather than land withWILL_FAIL, which someone has to remove by hand afterwards and which would hide the very regression it guards against. I will merge main in once #2195 lands.Tested
gta6rtonly.ctest -R gta6rt_no_tls_callbacks:a73a57e13: Failed, "gta6rt.exe has 2 TLS callback(s)".eaf0b8d0c): Passed.python -I tests/test_check_pe_tls_callbacks.py: ok; pytest on the same file: 3 passed.tests/test_runner_calls_all_tests.pyandtests/test_ci_registration.py: OK.scripts/check_no_game_data.pyon the three changed files: clean.git diff --check: clean.GPUs tested: n/a (the test reads the executable file and uses no GPU)
AI-assisted: yes (Claude Code, Claude Fable 5.2, wrote the test and ran it; a second agent reviewed it)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator rule)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-26T08:32:14Z.
Test of this PR at head
74bab76c9(RTX 2070 SUPER, NVIDIA 616.56, Windows 11 Pro 26300, MSVC (VS 18) RelWithDebInfo, own 1.0.2.1 package). AI-assisted.runtime/test/check_pe_tls_callbacks.pywithpython -Ion three gta6rt.exe builds that boot here: maina73a57e13+ #2195, and two older ones from before #2094. All three reportno TLS callbacksand exit 0.python -I tests/test_check_pe_tls_callbacks.py: ok. The non-PE and missing-file cases print their messages and give exit codes as described.a73a57e13alone I only have the fast-fail stack from #2195 (abort<-terminate<-_register_thread_local_exe_atexit_callback), the same stack MoonEyes saw there, matching the two callbacks reported for that exe.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T08:47:44Z.
Review: COMMENTED
The parser tests pass. The native CTest rejects a real
gta6rt.exewith the two callbacks on main, and the same script accepts the separately built #2195 executable. I also checked test registration in cross-compiling mode. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T08:47:44Z.
Code review location:
runtime/CMakeLists.txt; line 951[P3] Register this check for cross-compiled Windows binaries too. I configured the same tree with CMake's cross-compiling mode enabled (
CMAKE_SYSTEM_NAME=Windows) andctest -N -R '^gta6rt_no_tls_callbacks$'listed zero tests, versus one in the native build. The checker runs host Python and only reads the target image. Moving this registration outside the guard forrun_module_names, with host Python discovery, keeps the startup regression covered for cross-built binaries.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-26T10:24:26Z.
@lixonik good catch, thanks. The checker only reads the PE with the host Python, so I moved the registration out of the
run_module_namesguard, with its own Python3 lookup (812d5cfa6).Native configure still lists the test (
ctest -N -R gta6rt_no_tls_callbacksshows 1). I could not try the cross mode here (no xwin toolchain), so a check with yourCMAKE_SYSTEM_NAME=Windowssetup would help.clang-cl-xwinbuilds the same MSVC ABI and UCRT as the native build, so I did not limit it toif(MSVC); MinGW is not a gta6rt toolchain in CI.AI-assisted: yes (Claude Code, Claude Fable 5.2)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:32:32Z.
Retested
812d5cfa6withCMAKE_SYSTEM_NAME=Windowson the Windows host. CMake recordsCMAKE_CROSSCOMPILING=TRUE, andctest -N -R ^gta6rt_no_tls_callbacks$now lists one test. I ran that cross-configured CTest against the same two locally built PE files: it rejected the main binary with two callbacks and passed the #2195 binary. This verifies the registration fix in that CMake configuration. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-26T14:29:30Z.
I ran this with #2195 merged on top of main
73516a290, on Windows 10 / MSVC 14.44 RelWithDebInfo.gta6rt_no_tls_callbacksfails there, on a build that is fixed:The callback at RVA
0x5b990isstd::sys::thread_local::guard::windows::tls_callback, Rust std's.dumpbin /disasmnames it, anddumpbin /tlslists it alongside__dyn_tls_initand__dyn_tls_dtoron plain main. It comes from the XMA2 decoder, whichruntime/CMakeLists.txt(around line 120) builds with cargo and links intogta6rtwhenevercargois on PATH. So on any machine with a Rust toolchain installed, the guard fails although the exe has none of the MSVC callbacks that cause the0xC0000409. A build without cargo does not link the decoder and would not see it. The Python unit tests pass.Two ways to keep the guard and drop the false alarm:
gta6rt, and allow exactly one callback then.gta6rt.pdbsits next to the exe, as it does for RelWithDebInfo, fail only on__dyn_tls_init/__dyn_tls_dtor. Those are the two that come with an MSVCthread_localthat has a destructor, and the two #2195 removes.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-26T16:51:18Z.
@qhukz13 thanks, you are right. gta6rt now links with
/MAP, and the check usesgta6rt.mapto name each TLS callback, following an/INCREMENTALjump thunk if there is one.__dyn_tls_init(tlsdyn.obj) and__dyn_tls_dtor(tlsdtor.obj), or anything else from those two objects, fail the check. Rust std's thread-local callback passes. Any other callback fails, and so does a callback the map does not name.I chose names over a count because a count of 1 lets a real
__dyn_tls_dtorthrough whenever the Rust callback is missing. It also breaks when both decoders bring a copy of std. The map needs no extra tool on CI.Without a map, an exe with callbacks fails, and the message says to link with
/MAPor pass--map. A map with another timestamp or load address, or with no timestamp, also fails.Tested: MSVC 19.44, Ninja, RelWithDebInfo, no cargo. The link writes
gta6rt.mapnext to the exe, the exe has no callbacks and the test passes. I also ran the parser on that real map: it reads every symbol line and names a function through its incremental thunk.Not tested: an exe that really has the Rust callback, the Visual Studio generator (where the .map lands), and lld-link. Could you rebuild with cargo on PATH and run
ctest -R gta6rt_no_tls_callbacks -V? It should printallowedwith the Rusttls_callbacksymbol and pass. If it printsno symbol at this address in the maporno linker map, please paste that output and the map lines around that RVA.AI-assisted: yes (Claude Code. A sub-agent wrote the change; a separate agent reviewed it on a real linker map; Claude Fable 5.2 built and tested it.)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T18:02:10Z.
Review: COMMENTED
Rechecked the current head on Windows 11. The synthetic PE test script passed. I also ran the checker against two locally built
gta6rt.exefiles: it flagged two callbacks on the older build and accepted the newer build with zero callbacks. The CMake registration is outside the runnable-module guard. No new findings.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:12:28Z.
#2225 | head
8e3f4c6b8281c117fa1b1871fca6d74f3c6900ea|python3 -m pytest -q -rA tests/test_check_pe_tls_callbacks.py,py -3.12 -I runtime/test/check_pe_tls_callbacks.py <build>/gta6rt.exe,ctest --test-dir <build> -R ^gta6rt_no_tls_callbacks$ --output-on-failure(merged registration) | red: 5 passed synthetic / native checker exit 1 (no linker map) | green: 5 passed synthetic / native checker exit 0, CTest 1/1 | Native build check red → greenThe Python file includes both the checker and its synthetic fixtures in the baseline overlay. I also built only the gta6rt target on each real tree with MSVC/Ninja, RelWithDebInfo, Rust audio decoders and local Vulkan headers. On plain main the executable had a callback and no linker map, so the PR checker could not identify the callback and exited 1. After merging, the linker produced the map, the checker recognized the allowed Rust callback and the registered CTest passed. The prerequisite #2195 is already in this main. The game executable was inspected as a file.
Pinned main
33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 for synthetic cases and Windows 11 Pro, MSVC 19.44, Python 3.12.10 for the native build. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:47:06Z.
Merged, thank you @MoonEyes!
What it does: tests: fail when gta6rt.exe has TLS callbacks (TEST-GTA6RT-NO-TLS-CALLBACKS)
How it was checked: sodove tested this PR at head
8e3f4c6b8on main33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (import error: checker module is new); with the PR, green (pytest 5 passed).Its native check (the checker run against a real
gta6rt.exebuild plus the registered ctest) was run by sodove: exit 1 on main without a linker map, exit 0 and ctest 1/1 with this PR.CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the
cs_dpp_cmp.asmtranslator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.
AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.