Skip to content

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

Merged
aslan2142 merged 5 commits into
mainfrom
claude/bl1-tls-index0
Nov 24, 2026
Merged

aslan2142 merged 5 commits into
mainfrom
claude/bl1-tls-index0

Conversation

@QemmHD

@QemmHD QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: BL-1 (#14 (comment))

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 [draft, integration] retail boot to the frame loop on current main (RT-BOOT-INTEGRATION) #321/Retail boot v35 #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 a289278.

  • 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

QemmHD and others added 3 commits November 24, 2026 10:24
…ng thread and on a new one (BL-1)

BL-1 (docs/boot_leads.md) says code built with /GA reads its TLS at module index 0 and that main stops there.
main already carries a fix (b7a3fed and 4710549: load() rewrites the executable's gs:[58h] reads to a
per-thread view with the image's block at [0]), but no test maps a /GA executable and a second TLS module at
the same time, and no test shows that the fixture's code really has the index-0 shape: the CRT objects linked
into it read gs:[58h] through _tls_index, so "some reads were rewritten" holds for a non-/GA build too.

tiny_ga_tls gets ga_tls_address(), which returns where its code looks for its variable without touching it.
The new case uses it three ways. With LEONIDA_TLS_GA_PATCH=0 the address lies in this test EXE's own block at
index 0: the stop-4 shape, shown without reading or writing another module's TLS. By default it lies in the
fixture's own block, on the loading thread and on a thread started after load(), while tiny_tls.dll mapped
beside it keeps a block at its own index, gets its thread attach and detach, and this EXE's block and value
stay at index 0 of each thread's real TLS array. ~Loader takes the view out again.

No loader change: the case passes on main as it is, which is the finding. pe_loader.cpp and tls_host.cpp are
untouched.

Tested on Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, at main 8f05e09:
loader_tls_test OK (118 checks, 95 before), 40 runs in a row; with LEONIDA_TLS_GA_PATCH=0 set for the whole
process, 8 checks fail, as they should (7 existing ones and "by default load() rewrites the EXE's index-0
TLS reads"). MSVC emits the index-0 read for ga_tls_address at /Od and at /O2 (checked in the listing). Full
ctest: 304 of 306, the same two failures as main (d3d12_execute_indirect_validation, d3d12_depth_resolve).
Not run on the retail executable: that needs game files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
…tls)

loader_tls checks the /GA rewrite inside a test EXE that links pe_loader.cpp. The stop BL-1 describes is in
gta6rt itself: there module TLS index 0 holds gta6rt.exe's own TLS, which the runtime uses on every thread,
and the title's entry point runs on a thread gta6rt starts. Nothing ran a /GA image through that path.

tiny_game_ga is tiny_game.cpp built with /GA (and /INCLUDE:_tls_used, as tiny_ga_tls has, because /GA can
drop the last _tls_index reference). run_tiny_game_ga_tls runs its `tls` mode through gta6rt --run:
thread_local on the entry thread and on a thread the game starts.

It passes on main as it is; no loader change. With LEONIDA_TLS_GA_PATCH=0 the same run fails its thread_local
check and exits 1, while the non-/GA tiny_game still passes with the rewrite off, so the test separates the
two shapes. That run writes into gta6rt's own TLS, so it is not registered as a test.

Tested on Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, NVIDIA RTX 4070 SUPER driver
621.24: run_tiny_game_ga_tls passes, 30 runs in a row; ctest -R run_tiny_game 11 of 11; full ctest 305 of
307, the two failures main has (d3d12_execute_indirect_validation, d3d12_depth_resolve), and the per-test
results differ from main's only by the new test. tests/test_ctest_registration.py passes. Not run on the
retail executable: that needs game files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
… stop table say what it carries

docs/boot_leads.md sends a reader to implement BL-1 because "the retail run on main ends in the stop-4 shape".
That line comes from retail_boot_intel_host.md, measured at main 867d922. b7a3fed (the loader rewrites a
/GA executable's index-0 TLS reads) landed on main after that, and 4710549 after it, so the lead as written
describes a main that no longer exists. The integration tree's #4313 is a second design for the same stop
(the runtime's own EXE gives up index 0 at process start), not a fix main is missing.

- boot.md, triage step 3: what the stop looks like, what load() does about it, the log line that counts the
  rewritten reads, the switch that turns the rewrite off, and the two tests.
- retail_boot_chain.md, row 4: #4313 is what the measured tree had; main carries b7a3fed and 4710549.
- boot_leads.md, BL-1: a Status entry with the same, and what is left of the lead.

Nothing was run on the retail executable for this (it needs game files), and all three places say so.

Tested at main a289278: tests/test_docs_*.py, 47 pass; the repository-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 pass and 5 skip. scripts/check_no_game_data.py on the three files: clean.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
QemmHD and others added 2 commits November 24, 2026 10:37
… answered on main and pending retail

The Where entry still said the integration tree "carries a fix for stop 4 that main does not", which reads as a
missing fix. It now names the commit the retail measurement was taken at (867d922) and says the integration
tree clears stop 4 with #4313. Status opens with "answered on main by b7a3fed and 4710549 ... the retail
confirmation is still pending", and names #4313 (carried by #321 and #64) as an alternative design.

Tested: tests/test_docs_*.py, 47 passed (test_docs_links green); the repo-consistency set, 566 passed, 5 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
…ew row 4a

#741 added row 4a (the Wine-only gameinput.dll ordinal 1 stop) directly under row 4 of
docs/retail_boot_chain.md, which this branch edits. Both rows are kept unchanged.
tests/test_docs_*.py: 47 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
@aslan2142
aslan2142 merged commit dbc4327 into main Nov 24, 2026
6 of 13 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

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

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

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).

@aslan2142
aslan2142 deleted the claude/bl1-tls-index0 branch November 24, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants