tests: fail when gta6rt.exe has TLS callbacks (TEST-GTA6RT-NO-TLS-CALLBACKS) #2225

Open
github-bot wants to merge 4 commits from github-bot/gh-2225 into main AGit
Owner

@⁠MoonEyes on GitHub · 2026-11-26 07:31 UTC · original
MoonEyes:test/gta6rt-no-tls-callbacks → main · +423 −1 · 3 files · 4 commits · open

Claimed in the coordination issue as: TEST-GTA6RT-NO-TLS-CALLBACKS (#1608)

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_callback per 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.py reads the PE32+ TLS directory of the file it is given, walks AddressOfCallBacks to its zero terminator, and exits 1 if any callback is listed. Standard library only.
  • runtime/CMakeLists.txt registers it as the CTest gta6rt_no_tls_callbacks on $<TARGET_FILE:gta6rt> (next to run_module_names).
  • tests/test_check_pe_tls_callbacks.py (stdlib, run by ci.yml as python -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_callbacks until #2195 is merged, because main still has the two callbacks. I think it should wait for #2195 rather than land with WILL_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

  • Native Windows, MSVC 19.44, RelWithDebInfo, Ninja, target gta6rt only. ctest -R gta6rt_no_tls_callbacks:
    • main a73a57e13: Failed, "gta6rt.exe has 2 TLS callback(s)".
    • this branch merged locally with #2195 (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.py and tests/test_ci_registration.py: OK.
  • scripts/check_no_game_data.py on the three changed files: clean. git diff --check: clean.
  • The game was not started. Not tested: MinGW or clang-cl builds of gta6rt (they may list TLS callbacks of their own).

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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator rule)

🤖 Generated with Claude Code

**@⁠MoonEyes** on GitHub · 2026-11-26 07:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225) `MoonEyes:test/gta6rt-no-tls-callbacks` → `main` · +423 −1 · 3 files · 4 commits · open Claimed in the coordination issue as: TEST-GTA6RT-NO-TLS-CALLBACKS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) 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_callback` per 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.py` reads the PE32+ TLS directory of the file it is given, walks `AddressOfCallBacks` to its zero terminator, and exits 1 if any callback is listed. Standard library only. - `runtime/CMakeLists.txt` registers it as the CTest `gta6rt_no_tls_callbacks` on `$<TARGET_FILE:gta6rt>` (next to `run_module_names`). - `tests/test_check_pe_tls_callbacks.py` (stdlib, run by ci.yml as `python -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_callbacks` until #2195 is merged, because main still has the two callbacks. I think it should wait for #2195 rather than land with `WILL_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 - Native Windows, MSVC 19.44, RelWithDebInfo, Ninja, target `gta6rt` only. `ctest -R gta6rt_no_tls_callbacks`: - main `a73a57e13`: Failed, "gta6rt.exe has 2 TLS callback(s)". - this branch merged locally with #2195 (`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.py` and `tests/test_ci_registration.py`: OK. - `scripts/check_no_game_data.py` on the three changed files: clean. `git diff --check`: clean. - The game was not started. Not tested: MinGW or clang-cl builds of gta6rt (they may list TLS callbacks of their own). 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator rule) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A thread_local with a destructor gives gta6rt.exe __dyn_tls_init/__dyn_tls_dtor callbacks;
the title's own _register_thread_local_exe_atexit_callback then fast-fails (0xC0000409).
check_pe_tls_callbacks.py reads the PE TLS directory and fails on a non-empty list; a stdlib
test checks it on two in-memory PE32+ images.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:22:52 +00:00
Author
Owner

@⁠HasiKe on GitHub · 2026-11-26 08:32 UTC · original

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.

  • I ran runtime/test/check_pe_tls_callbacks.py with python -I on three gta6rt.exe builds that boot here: main a73a57e13 + #2195, and two older ones from before #2094. All three report no TLS callbacks and 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.
  • I didn't re-check the failing side myself. For main a73a57e13 alone 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.
**@⁠HasiKe** on GitHub · 2026-11-26 08:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#issuecomment-7186713410) 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. - I ran `runtime/test/check_pe_tls_callbacks.py` with `python -I` on three gta6rt.exe builds that boot here: main a73a57e13 + #2195, and two older ones from before #2094. All three report `no TLS callbacks` and 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. - I didn't re-check the failing side myself. For main a73a57e13 alone 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.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 08:47 UTC · original · reviewed

The parser tests pass. The native CTest rejects a real gta6rt.exe with 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.

**@⁠lixonik** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#pullrequestreview-6070941492) · **reviewed** The parser tests pass. The native CTest rejects a real `gta6rt.exe` with 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.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 08:47 UTC · original
On runtime/CMakeLists.txt line 951 (outdated):

@@ -945,6 +945,12 @@ if(BUILD_TESTING)
           "--report=${CMAKE_CURRENT_BINARY_DIR}/module-names-results.json")
         set_tests_properties(run_module_names PROPERTIES TIMEOUT 90)
       endif()
+      # TEST-GTA6RT-NO-TLS-CALLBACKS: a thread_local with a destructor gives gta6rt.exe TLS callbacks, and the game
+      # then fast-fails (0xC0000409) in its own _register_thread_local_exe_atexit_callback (RT-XMEM-STARTUP-FASTFAIL).
+      if(Python3_FOUND)
+        add_test(NAME gta6rt_no_tls_callbacks COMMAND "${Python3_EXECUTABLE}" -I

[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) and ctest -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 for run_module_names, with host Python discovery, keeps the startup regression covered for cross-built binaries.

**@⁠lixonik** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#discussion_r4705794499) On `runtime/CMakeLists.txt` line 951 (outdated): ```diff @@ -945,6 +945,12 @@ if(BUILD_TESTING) "--report=${CMAKE_CURRENT_BINARY_DIR}/module-names-results.json") set_tests_properties(run_module_names PROPERTIES TIMEOUT 90) endif() + # TEST-GTA6RT-NO-TLS-CALLBACKS: a thread_local with a destructor gives gta6rt.exe TLS callbacks, and the game + # then fast-fails (0xC0000409) in its own _register_thread_local_exe_atexit_callback (RT-XMEM-STARTUP-FASTFAIL). + if(Python3_FOUND) + add_test(NAME gta6rt_no_tls_callbacks COMMAND "${Python3_EXECUTABLE}" -I ``` [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`) and `ctest -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 for `run_module_names`, with host Python discovery, keeps the startup regression covered for cross-built binaries.
The checker only reads the PE file with the host's Python, so it does not need the
run_module_names guard (NOT CMAKE_CROSSCOMPILING). Move the registration out of it, with
its own host Python lookup. runtime/cmake/clang-cl-xwin.cmake builds the same MSVC ABI
and UCRT, so the same callbacks would appear; MinGW is not a supported gta6rt toolchain.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-26 10:24 UTC · original

@⁠lixonik good catch, thanks. The checker only reads the PE with the host Python, so I moved the registration out of the run_module_names guard, with its own Python3 lookup (812d5cfa6).

Native configure still lists the test (ctest -N -R gta6rt_no_tls_callbacks shows 1). I could not try the cross mode here (no xwin toolchain), so a check with your CMAKE_SYSTEM_NAME=Windows setup would help.

clang-cl-xwin builds the same MSVC ABI and UCRT as the native build, so I did not limit it to if(MSVC); MinGW is not a gta6rt toolchain in CI.

AI-assisted: yes (Claude Code, Claude Fable 5.2)

**@⁠MoonEyes** on GitHub · 2026-11-26 10:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#issuecomment-7189323596) @⁠lixonik good catch, thanks. The checker only reads the PE with the host Python, so I moved the registration out of the `run_module_names` guard, with its own Python3 lookup (812d5cfa6). Native configure still lists the test (`ctest -N -R gta6rt_no_tls_callbacks` shows 1). I could not try the cross mode here (no xwin toolchain), so a check with your `CMAKE_SYSTEM_NAME=Windows` setup would help. `clang-cl-xwin` builds the same MSVC ABI and UCRT as the native build, so I did not limit it to `if(MSVC)`; MinGW is not a gta6rt toolchain in CI. AI-assisted: yes (Claude Code, Claude Fable 5.2)
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:32 UTC · original

Retested 812d5cfa6 with CMAKE_SYSTEM_NAME=Windows on the Windows host. CMake records CMAKE_CROSSCOMPILING=TRUE, and ctest -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.

**@⁠lixonik** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#issuecomment-7189503473) Retested `812d5cfa6` with `CMAKE_SYSTEM_NAME=Windows` on the Windows host. CMake records `CMAKE_CROSSCOMPILING=TRUE`, and `ctest -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.
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-26 14:29 UTC · original

I ran this with #2195 merged on top of main 73516a290, on Windows 10 / MSVC 14.44 RelWithDebInfo. gta6rt_no_tls_callbacks fails there, on a build that is fixed:

FAIL: runtime\build\RelWithDebInfo\gta6rt.exe has 1 TLS callback(s) (RVAs 0x5b990). A thread_local with a destructor was linked in; ...

The callback at RVA 0x5b990 is std::sys::thread_local::guard::windows::tls_callback, Rust std's. dumpbin /disasm names it, and dumpbin /tls lists it alongside __dyn_tls_init and __dyn_tls_dtor on plain main. It comes from the XMA2 decoder, which runtime/CMakeLists.txt (around line 120) builds with cargo and links into gta6rt whenever cargo is 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 the 0xC0000409. 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:

  • Have CMake pass the check whether the Rust decoder is linked into gta6rt, and allow exactly one callback then.
  • Check by name: when gta6rt.pdb sits 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 MSVC thread_local that has a destructor, and the two #2195 removes.

AI-assisted (Claude Code).

**@⁠qhukz13** on GitHub · 2026-11-26 14:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#issuecomment-7194896570) I ran this with #2195 merged on top of main `73516a290`, on Windows 10 / MSVC 14.44 RelWithDebInfo. **`gta6rt_no_tls_callbacks` fails there, on a build that is fixed:** ``` FAIL: runtime\build\RelWithDebInfo\gta6rt.exe has 1 TLS callback(s) (RVAs 0x5b990). A thread_local with a destructor was linked in; ... ``` The callback at RVA `0x5b990` is `std::sys::thread_local::guard::windows::tls_callback`, Rust std's. `dumpbin /disasm` names it, and `dumpbin /tls` lists it alongside `__dyn_tls_init` and `__dyn_tls_dtor` on plain main. It comes from the XMA2 decoder, which `runtime/CMakeLists.txt` (around line 120) builds with cargo and links into `gta6rt` whenever `cargo` is 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 the `0xC0000409`. 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: - Have CMake pass the check whether the Rust decoder is linked into `gta6rt`, and allow exactly one callback then. - Check by name: when `gta6rt.pdb` sits 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 MSVC `thread_local` that has a destructor, and the two #2195 removes. AI-assisted (Claude Code).
Link gta6rt with /MAP and read gta6rt.map to name each TLS callback.
Fail on the C++ runtime's __dyn_tls_init (tlsdyn.obj) and __dyn_tls_dtor (tlsdtor.obj), allow Rust std's thread-local callback, fail on the rest.
A callback the map does not name, a missing map or a stale map fails with a message.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-26 16:51 UTC · original

@⁠qhukz13 thanks, you are right. gta6rt now links with /MAP, and the check uses gta6rt.map to name each TLS callback, following an /INCREMENTAL jump 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_dtor through 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 /MAP or 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.map next 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 print allowed with the Rust tls_callback symbol and pass. If it prints no symbol at this address in the map or no 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.)

**@⁠MoonEyes** on GitHub · 2026-11-26 16:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#issuecomment-7198181255) @⁠qhukz13 thanks, you are right. gta6rt now links with `/MAP`, and the check uses `gta6rt.map` to name each TLS callback, following an `/INCREMENTAL` jump 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_dtor` through 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 `/MAP` or 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.map` next 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 print `allowed` with the Rust `tls_callback` symbol and pass. If it prints `no symbol at this address in the map` or `no 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.)
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 18:02 UTC · original · reviewed

Rechecked the current head on Windows 11. The synthetic PE test script passed. I also ran the checker against two locally built gta6rt.exe files: 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.

**@⁠lixonik** on GitHub · 2026-11-26 18:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2225#pullrequestreview-6078731551) · **reviewed** Rechecked the current head on Windows 11. The synthetic PE test script passed. I also ran the checker against two locally built `gta6rt.exe` files: 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2225/head:github-bot/gh-2225'
git switch 'github-bot/gh-2225'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2225'
git switch 'github-bot/gh-2225'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2225'
git switch 'github-bot/gh-2225'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2225'
git switch 'main'
git merge --squash 'github-bot/gh-2225'
git switch 'main'
git merge --ff-only 'github-bot/gh-2225'
git switch 'main'
git merge 'github-bot/gh-2225'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.