runtime: accept initializer-only CRT TLS callback (RUNTIME-TLS-CHECK-VS17-12) #2754

Closed
leonida/mandy
j-weiner wants to merge 0 commits from fix/runtime-tls-check-vs1712 into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

j-weiner commented 2026-11-30 15:46:59 +00:00

Claimed in the coordination issue as: RUNTIME-TLS-CHECK-VS17-12

Depends on: none

Fixes: none

What and why

gta6rt_no_tls_callbacks previously rejected every __dyn_tls_init/tlsdyn.obj callback. VS 2022 17.12 can emit the CRT initializer without a destructor callback; that initializer-only shape does not register the UCRT thread-local-exit path guarded by this check. The checker now allows the initializer only when no CRT destructor is present, while retaining rejection of the destructor, the normal initializer+destructor pair, and unknown callbacks. The test suite adds a synthetic initializer-only PE/map case and keeps the existing dangerous-pair cases.

Tested

  • python -I tests/test_check_pe_tls_callbacks.py — passed, including the new initializer-only case and existing synthetic PE/map cases.
  • python -m compileall -q runtime/test/check_pe_tls_callbacks.py tests/test_check_pe_tls_callbacks.py — passed.
  • python -I runtime/test/check_pe_tls_callbacks.py runtime/build/gta6rt.exe — passed; the existing executable has no TLS callbacks.
  • python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/test/check_pe_tls_callbacks.py tests/test_check_pe_tls_callbacks.py — passed.
  • git diff --check — passed.
  • ctest was unavailable on PATH in this environment, so no CTest result is claimed.

GPUs tested: n/a; synthetic PE/map inputs only, no game files.

AI-assisted: yes.

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports.
  • No translator rule.
Claimed in the coordination issue as: RUNTIME-TLS-CHECK-VS17-12 Depends on: none Fixes: none ### What and why `gta6rt_no_tls_callbacks` previously rejected every `__dyn_tls_init`/`tlsdyn.obj` callback. VS 2022 17.12 can emit the CRT initializer without a destructor callback; that initializer-only shape does not register the UCRT thread-local-exit path guarded by this check. The checker now allows the initializer only when no CRT destructor is present, while retaining rejection of the destructor, the normal initializer+destructor pair, and unknown callbacks. The test suite adds a synthetic initializer-only PE/map case and keeps the existing dangerous-pair cases. ### Tested - `python -I tests/test_check_pe_tls_callbacks.py` — passed, including the new initializer-only case and existing synthetic PE/map cases. - `python -m compileall -q runtime/test/check_pe_tls_callbacks.py tests/test_check_pe_tls_callbacks.py` — passed. - `python -I runtime/test/check_pe_tls_callbacks.py runtime/build/gta6rt.exe` — passed; the existing executable has no TLS callbacks. - `python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/test/check_pe_tls_callbacks.py tests/test_check_pe_tls_callbacks.py` — passed. - `git diff --check` — passed. - `ctest` was unavailable on PATH in this environment, so no CTest result is claimed. GPUs tested: n/a; synthetic PE/map inputs only, no game files. AI-assisted: yes. ### Checklist - [x] Based on current `main` and merges cleanly. - [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. - [x] No translator rule.
OreoFR commented 2026-11-30 15:48:03 +00:00

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main be7690805, head 41f050cb7.

  • MEASURED, red (main + only this PR's test): tests/test_check_pe_tls_callbacks.py: 1 failed, 3 passed (the new "initializer alone" case: main rejects it).
  • MEASURED, green (main + this PR, merged): 5 passed.
  • READ IN CODE: judge allows __dyn_tls_init / tlsdyn.obj only when no callback of the image names __dyn_tls_dtor / tlsdtor.obj; a destructor, the pair, an unknown or an unnamed callback still fail. _is_crt_* match the map's lib:object form the same way classify already does (obj.lower().endswith(...)). The test keeps "pair → 1" and adds "initializer alone → 0".
  • ASSUMED, not checked here: that an image with the initializer alone does not register _register_thread_local_exe_atexit_callback. That matches the CRT's startup as I know it (it registers only a non-null destructor callback), but I have not read the 17.12 CRT source or run a 17.12 link.
  • Not covered: the CMake/ctest registration on Windows (CI). Verdict: green on Mac 5/5.

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, `main` `be7690805`, head `41f050cb7`. - MEASURED, red (`main` + only this PR's test): `tests/test_check_pe_tls_callbacks.py`: 1 failed, 3 passed (the new "initializer alone" case: `main` rejects it). - MEASURED, green (`main` + this PR, merged): 5 passed. - READ IN CODE: `judge` allows `__dyn_tls_init` / `tlsdyn.obj` only when no callback of the image names `__dyn_tls_dtor` / `tlsdtor.obj`; a destructor, the pair, an unknown or an unnamed callback still fail. `_is_crt_*` match the map's `lib:object` form the same way `classify` already does (`obj.lower().endswith(...)`). The test keeps "pair → 1" and adds "initializer alone → 0". - ASSUMED, not checked here: that an image with the initializer alone does not register `_register_thread_local_exe_atexit_callback`. That matches the CRT's startup as I know it (it registers only a non-null destructor callback), but I have not read the 17.12 CRT source or run a 17.12 link. - Not covered: the CMake/`ctest` registration on Windows (CI). Verdict: green on Mac 5/5. AI-assisted: Claude Code
OreoFR commented 2026-11-30 16:02:58 +00:00

The red check job is not this PR: tests/test_launcher_serve.py (FetchTests.test_kept_by_what_came_back) hit PermissionError: [WinError 32] on a temporary art.jpg still open (run 46454293779, 1 of 627 files failed), the same intermittent failure seen on #2724 and #2734. test_check_pe_tls_callbacks passed there. A rerun should clear it.

AI-assisted: Claude Code

The red `check` job is not this PR: `tests/test_launcher_serve.py` (`FetchTests.test_kept_by_what_came_back`) hit `PermissionError: [WinError 32]` on a temporary `art.jpg` still open (run 46454293779, 1 of 627 files failed), the same intermittent failure seen on #2724 and #2734. `test_check_pe_tls_callbacks` passed there. A rerun should clear it. AI-assisted: Claude Code
KelboLive commented 2026-11-30 16:29:30 +00:00

Independent check on Windows (not the author), at 41f050cb7.

  • python -I tests/test_check_pe_tls_callbacks.py: exit 0 (ok), covering no callbacks, one/two allowed callbacks, and the initializer-only case this PR adds.
  • This is the Python side of the check; I did not run the CMake check_pe_tls_callbacks target against a real PE from the title.

Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10.

AI-assisted: yes (opencode).

Independent check on Windows (not the author), at `41f050cb7`. - `python -I tests/test_check_pe_tls_callbacks.py`: **exit 0** (`ok`), covering no callbacks, one/two allowed callbacks, and the initializer-only case this PR adds. - This is the Python side of the check; I did not run the CMake `check_pe_tls_callbacks` target against a real PE from the title. Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10. AI-assisted: yes (opencode).
j-weiner commented 2026-11-30 16:58:28 +00:00

The current check run (46454293779) failed in an unchanged, unrelated test: ests/test_launcher_serve.py::FetchTests.test_kept_by_what_came_back. The failure is PermissionError [WinError 32] while TemporaryDirectory cleanup removes rt.jpg, reported as held by another process. The TLS-checker tests are not the failing test; other checks on this run passed. I made no code change for this unrelated runner failure. AI-assisted.

The current check run (46454293779) failed in an unchanged, unrelated test: ests/test_launcher_serve.py::FetchTests.test_kept_by_what_came_back. The failure is PermissionError [WinError 32] while TemporaryDirectory cleanup removes rt.jpg, reported as held by another process. The TLS-checker tests are not the failing test; other checks on this run passed. I made no code change for this unrelated runner failure. AI-assisted.
KelboLive reviewed 2026-12-01 05:25:15 +00:00
KelboLive left a comment
No description provided.
The rule is right: `judge` allows the initializer only while no destructor is named anywhere (`check_pe_tls_callbacks.py:191`, `:197`), and everything else stays as it was. I checked the negative matrix by hand with the test's own PE/map builders — init + an unknown callback, init + an unnamed callback, init's RVA named only as an unknown symbol, init + no map, init + dtor aliased at one RVA, and dtor alone all return 1; init through a thunk returns 0. The array walk stops at the terminator and a malformed image fails rather than passing silently, and the built `gta6rt.exe` still has no TLS callbacks, so the new path is exercised only synthetically (as the PR says). Two things worth adding: 1. **The premise needs its citation.** The docstring and the body say an initializer-only CRT does not register the exit path, but neither cites the UCRT call site nor shows a boot of an init-only image. The link-level argument is right there — `runtime/shims/process.cpp:338-350` records that the startup passes `__dyn_tls_dtor`, so no destructor object means no registration — please put that reasoning in the docstring (or the toolset that emits that shape and what its image imports). A wrong guess here is exactly the boot fast-fail this checker exists to prevent. 2. **Harden the destructor search.** `has_crt_destructor` scans only the *callback entries'* names; scanning the map for `__dyn_tls_dtor` / `tlsdtor.obj` anywhere cannot false-reject a genuinely init-only image (its destructor is not linked) and would catch a destructor that is registered but somehow absent from the array. Minor: the rule also lets **two** initializer entries pass (tried it) — harmless in a real image (one CRT per exe), but the docstring should say "the initializer", not "any initializer"; an "init + one unknown callback" case in the committed suite would pin the per-entry rule, which is the part a future edit is most likely to get wrong; and the callback walk (`:87`) has no bound, so a malformed image depends on `struct.error` at EOF rather than failing cleanly.
aslan2142 commented 2026-12-01 17:26:34 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.