BL-1: tests and docs for the /GA index-0 TLS stop that main already clears (no loader change) #947

Merged
QemmHD merged 5 commits from upstream-pr/947 into main 2026-11-24 20:30:59 +00:00
QemmHD commented 2026-11-24 15:33:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T15:33:50Z.


Claimed in the coordination issue as: BL-1 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135107734)

Conflicts with: #741, trivially. It adds row 4a directly under row 4 of docs/retail_boot_chain.md, which this PR edits. Keep both rows.

What and why

BL-1 asks for the executable's TLS to resolve at module index 0, because "the retail run on main ends in the stop-4 shape". That measurement was taken at main 867d922f. Main has carried a fix since b7a3fed28 and 4710549af, both of which landed after that measurement. load() rewrites a /GA executable's mov r64, gs:[58h] reads so they reach a per-thread view with the image's own block at [0], and every other mapped module with a TLS directory gets an index of its own. So this PR adds no loader code. It adds the tests the lead asks for and corrects the three documents, so nobody re-implements a fix main already has.

  • loader_tls: maps a /GA executable beside tiny_tls.dll. A new export, ga_tls_address(), reports where the fixture's code looks for its variable. With LEONIDA_TLS_GA_PATCH=0, that's the process EXE's block at index 0, which is stop 4, shown without touching another module's TLS. By default, it's the fixture's own block, on the loading thread and on a new thread, with the DLL's block at its own index and the process EXE's block still at index 0.
  • run_tiny_game_ga_tls: builds tiny_game.cpp with /GA and runs it through gta6rt --run, where index 0 is gta6rt.exe's.
  • Docs: docs/boot.md (triage step 3), docs/retail_boot_chain.md (row 4) and docs/boot_leads.md (a BL-1 Status entry) now say what main carries. The integration tree's #4313 (rt::reserve_tls_index0, still in #321/#64) is a second design for the same stop, not a missing fix.

Tested

Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, on main a28927849.

  • loader_tls_test: OK, 118 checks (95 before). With LEONIDA_TLS_GA_PATCH=0 set for the whole process, 8 checks fail, as they should (e.g. FAIL the loading thread reads the /GA fixture's template value 7).
  • run_tiny_game_ga_tls passes, 30 runs in a row. The same run with the rewrite off fails its thread_local check and exits 1. The non-/GA tiny_game passes either way, so the test tells the two shapes apart.
  • Full ctest: 305 of 307. The two failures are already on main (d3d12_execute_indirect_validation, d3d12_depth_resolve). Main alone is 304 of 306, and the per-test results differ only by the new test.
  • Repo-consistency set (test_cmake_*, test_shader_stage_resume, test_runtime_paths, test_docs_*, test_make_game_*, test_check_no_game_data*, test_run_semantic_tests): 566 passed, 5 skipped. test_ctest_registration passes.
  • Not tested: the retail executable. That confirmation needs game files, which were not used. What's left of BL-1 is a retail --run on current main by someone with their own copy. If it still stops at stop 4, the remaining work is whatever read shape the rewrite doesn't recognize. clang-cl and Wine were not run here.

GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 (full ctest; the new tests are CPU-only)

AI-assisted: yes

Possible follow-ups (not in this PR)

  • initialize_tls uses one process-wide TlsAlloc cell (static const DWORD ga_slot), although runtime/README.md says there is one per image. Two /GA executables mapped at once would share it.
  • The rewrite only recognizes the gs:[58h] form, not a read through gs:[30h] + 58h.

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 quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5475256803 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/947). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T15:33:50Z. --- Claimed in the coordination issue as: BL-1 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135107734) Conflicts with: #741, trivially. It adds row 4a directly under row 4 of `docs/retail_boot_chain.md`, which this PR edits. Keep both rows. ### What and why BL-1 asks for the executable's TLS to resolve at module index 0, because "the retail run on main ends in the stop-4 shape". That measurement was taken at main `867d922f`. Main has carried a fix since `b7a3fed28` and `4710549af`, both of which landed after that measurement. `load()` rewrites a `/GA` executable's `mov r64, gs:[58h]` reads so they reach a per-thread view with the image's own block at `[0]`, and every other mapped module with a TLS directory gets an index of its own. **So this PR adds no loader code.** It adds the tests the lead asks for and corrects the three documents, so nobody re-implements a fix main already has. - **`loader_tls`:** maps a `/GA` executable beside `tiny_tls.dll`. A new export, `ga_tls_address()`, reports where the fixture's code looks for its variable. With `LEONIDA_TLS_GA_PATCH=0`, that's the process EXE's block at index 0, which is stop 4, shown without touching another module's TLS. By default, it's the fixture's own block, on the loading thread and on a new thread, with the DLL's block at its own index and the process EXE's block still at index 0. - **`run_tiny_game_ga_tls`:** builds `tiny_game.cpp` with `/GA` and runs it through `gta6rt --run`, where index 0 is `gta6rt.exe`'s. - **Docs:** `docs/boot.md` (triage step 3), `docs/retail_boot_chain.md` (row 4) and `docs/boot_leads.md` (a BL-1 Status entry) now say what main carries. The integration tree's #4313 (`rt::reserve_tls_index0`, still in #321/#64) is a second design for the same stop, not a missing fix. ### Tested Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, on main a28927849. - `loader_tls_test`: OK, 118 checks (95 before). With `LEONIDA_TLS_GA_PATCH=0` set for the whole process, 8 checks fail, as they should (e.g. `FAIL the loading thread reads the /GA fixture's template value 7`). - `run_tiny_game_ga_tls` passes, 30 runs in a row. The same run with the rewrite off fails its thread_local check and exits 1. The non-`/GA` `tiny_game` passes either way, so the test tells the two shapes apart. - Full ctest: 305 of 307. The two failures are already on main (`d3d12_execute_indirect_validation`, `d3d12_depth_resolve`). Main alone is 304 of 306, and the per-test results differ only by the new test. - Repo-consistency set (`test_cmake_*`, `test_shader_stage_resume`, `test_runtime_paths`, `test_docs_*`, `test_make_game_*`, `test_check_no_game_data*`, `test_run_semantic_tests`): 566 passed, 5 skipped. `test_ctest_registration` passes. - **Not tested:** the retail executable. That confirmation needs game files, which were not used. What's left of BL-1 is a retail `--run` on current main by someone with their own copy. If it still stops at stop 4, the remaining work is whatever read shape the rewrite doesn't recognize. clang-cl and Wine were not run here. GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 (full ctest; the new tests are CPU-only) AI-assisted: yes ### Possible follow-ups (not in this PR) - `initialize_tls` uses one process-wide `TlsAlloc` cell (`static const DWORD ga_slot`), although `runtime/README.md` says there is one per image. Two `/GA` executables mapped at once would share it. - The rewrite only recognizes the `gs:[58h]` form, not a read through `gs:[30h]` + 58h. ### 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 quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
aslan2142 commented 2026-11-24 20:31:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T20:31:01Z.


Merged on local results, since CI has been queued for hours. The Windows tests were run on a merge of main 6293c1c4f + 8f8b34896: clang-cl / lld-link 23.1.5 with the xwin MSVC CRT and Windows SDK 10.0.26100, RelWithDebInfo, under Wine 11.22, headless, with no game files.

  • Build: clean, with no new warnings in the changed files.
  • loader_tls: 10/10 passed, OK (118 checks) each time. main has 95, so this adds 23 checks.
  • ctest -R loader: 5/5 passed (loader, pe_loader, pe_loader_bounds, pe_loader_fuzz, loader_tls).
  • run_tiny_game_ga_tls: 10/10 passed under gta6rt.
  • The test guards the fix: with the gs:[58h] rewrite left out, 9 checks in the new section fail. Putting the EXE's block over index 0 of the real TLS array also fails the new section.
  • Small note: clang-cl already emits index-0 reads for the plain tiny_game.exe, so with this toolchain run_tiny_game_ga_tls covers the same path as run_tiny_game_tls. MSVC builds should differ.
  • The claim is valid and first, and the doc edits match the commits they cite.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143665842 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/947#issuecomment-7143665842). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T20:31:01Z. --- Merged on local results, since CI has been queued for hours. The Windows tests were run on a merge of `main` `6293c1c4f` + `8f8b34896`: clang-cl / lld-link 23.1.5 with the xwin MSVC CRT and Windows SDK 10.0.26100, RelWithDebInfo, under Wine 11.22, headless, with no game files. - **Build:** clean, with no new warnings in the changed files. - **`loader_tls`:** 10/10 passed, `OK (118 checks)` each time. `main` has 95, so this adds 23 checks. - **`ctest -R loader`:** 5/5 passed (`loader`, `pe_loader`, `pe_loader_bounds`, `pe_loader_fuzz`, `loader_tls`). - **`run_tiny_game_ga_tls`:** 10/10 passed under `gta6rt`. - **The test guards the fix:** with the `gs:[58h]` rewrite left out, 9 checks in the new section fail. Putting the EXE's block over index 0 of the real TLS array also fails the new section. - **Small note:** clang-cl already emits index-0 reads for the plain `tiny_game.exe`, so with this toolchain `run_tiny_game_ga_tls` covers the same path as `run_tiny_game_tls`. MSVC builds should differ. - The claim is valid and first, and the doc edits match the commits they cite. AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).
QemmHD commented 2026-11-24 20:37:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T20:37:46Z.


Thanks for the independent run, @aslan2142, and especially for the negative check that puts the EXE's block over real index 0.

On your note about clang-cl: with MSVC 19.44 (VS 2022) here, the two tests do take different paths. Under gta6rt --run with LEONIDA_TLS_GA_PATCH=0, the /GA build (tiny_game_ga) fails its thread_local check and exits 1, while the plain tiny_game still passes with the rewrite off. So on MSVC, only run_tiny_game_ga_tls exercises the rewrite end to end, and it fails as expected when the rewrite is off. Under clang-cl, where the plain build already emits index-0 reads, the two cover the same path, as you said.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143840416 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/947#issuecomment-7143840416). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T20:37:46Z. --- Thanks for the independent run, @aslan2142, and especially for the negative check that puts the EXE's block over real index 0. On your note about clang-cl: with MSVC 19.44 (VS 2022) here, the two tests do take different paths. Under `gta6rt --run` with `LEONIDA_TLS_GA_PATCH=0`, the `/GA` build (`tiny_game_ga`) fails its thread_local check and exits 1, while the plain `tiny_game` still passes with the rewrite off. So on MSVC, only `run_tiny_game_ga_tls` exercises the rewrite end to end, and it fails as expected when the rewrite is off. Under clang-cl, where the plain build already emits index-0 reads, the two cover the same path, as you said. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!947
No description provided.