tests: constant-initialize the TLS value template on MSVC 19.42 #1498

Merged
SimSalabimse merged 1 commit from upstream-pr/1505 into main 2026-11-24 13:27:48 +00:00
SimSalabimse commented 2026-11-24 13:16:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T13:16:00Z.


Change

On MSVC 19.42, g_span in cpu_tls_value.dll is constant-initialized from a brace list of plain constant expressions. The list is the same 8 KiB span_word() pattern the existing check expects, so those bytes are in the TLS template. A function-call initializer, including constexpr make_span(), stays dynamic on this compiler and leaves the pattern out of the template. The check in tests/cpu/native_tls_value_check.py is unchanged: a template that does not contain the pattern is still a fixture failure. The CRT-free EXE TLS fixtures are unchanged.

Refs #1465

Verification

Commit 04d78f3d on x2w-tls-value-msvc1942, base 3e23ce2c. Windows 11 build 26200, MSVC 19.42.34435 (toolset 14.42.34433). cpu_tls_value was compiled from a new object in a new build directory.

cmake --preset dev exited 0. cmake --build --preset dev of the TLS fixture targets (cpu_tls_value, cpu_tls_original, cpu_tls_sink, pe_map, and the cpu_exe_tls* targets) exited 0.

cmake --preset release exited 0. The same Release build exited 0.

ctest --preset dev --no-tests=error -R '^cpu_native_tls_value$' -V

Exit code 0. cpu_native_tls_value passed (1.95 s).

ctest --preset release --no-tests=error -R '^cpu_native_tls_value$' -V

Exit code 0. cpu_native_tls_value passed (1.36 s).

ctest --preset dev --no-tests=error -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V

Exit code 0. Five tests passed (3.66 s): cpu_native_tls_value, cpu_native_exe_tls, cpu_native_exe_tls_slot0_windows, cpu_native_exe_tls_slot0, cpu_native_exe_tls_slot0_enroll. No test named cpu_mapped_tls_value is registered.

ctest --preset release --no-tests=error -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V

Exit code 0. The same five tests passed (3.11 s).

The check's own template comparison found the 8 KiB array in both 19.42 DLLs (Debug template RVA 0x6f8d0, 8224 bytes; Release template RVA 0x18290, 8224 bytes) and reported that it crosses a page boundary. A separate pefile read of each DLL found the same 8192-byte pattern at offset 32 of the TLS template.

MSVC 14.29 was not run. The README sentence about that toolset was left unchanged.

Evidence and follow-up

The brace list is source in tests/cpu/tls_value.cpp. A static_assert checks it word for word against span_word(). The existing test is the negative control: swapping the callback table and zeroing the template from its first page boundary are still rejected.

Assumption: MSVC 19.42 puts a thread-local aggregate in the TLS template when the initializer is a brace list of constant expressions, and not when that initializer calls a function. That is the comparison recorded on #1119. This change does not retarget the five CRT-free EXE fixtures from #1094.

No game files, dumps, or distribution links.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Grok Build).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582637570 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1505). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T13:16:00Z. --- ## Change On MSVC 19.42, `g_span` in `cpu_tls_value.dll` is constant-initialized from a brace list of plain constant expressions. The list is the same 8 KiB `span_word()` pattern the existing check expects, so those bytes are in the TLS template. A function-call initializer, including `constexpr make_span()`, stays dynamic on this compiler and leaves the pattern out of the template. The check in `tests/cpu/native_tls_value_check.py` is unchanged: a template that does not contain the pattern is still a fixture failure. The CRT-free EXE TLS fixtures are unchanged. Refs #1465 ## Verification Commit `04d78f3d` on `x2w-tls-value-msvc1942`, base `3e23ce2c`. Windows 11 build 26200, MSVC 19.42.34435 (toolset 14.42.34433). `cpu_tls_value` was compiled from a new object in a new build directory. `cmake --preset dev` exited 0. `cmake --build --preset dev` of the TLS fixture targets (`cpu_tls_value`, `cpu_tls_original`, `cpu_tls_sink`, `pe_map`, and the `cpu_exe_tls*` targets) exited 0. `cmake --preset release` exited 0. The same Release build exited 0. `ctest --preset dev --no-tests=error -R '^cpu_native_tls_value$' -V` Exit code 0. `cpu_native_tls_value` passed (1.95 s). `ctest --preset release --no-tests=error -R '^cpu_native_tls_value$' -V` Exit code 0. `cpu_native_tls_value` passed (1.36 s). `ctest --preset dev --no-tests=error -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V` Exit code 0. Five tests passed (3.66 s): `cpu_native_tls_value`, `cpu_native_exe_tls`, `cpu_native_exe_tls_slot0_windows`, `cpu_native_exe_tls_slot0`, `cpu_native_exe_tls_slot0_enroll`. No test named `cpu_mapped_tls_value` is registered. `ctest --preset release --no-tests=error -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V` Exit code 0. The same five tests passed (3.11 s). The check's own template comparison found the 8 KiB array in both 19.42 DLLs (Debug template RVA `0x6f8d0`, 8224 bytes; Release template RVA `0x18290`, 8224 bytes) and reported that it crosses a page boundary. A separate `pefile` read of each DLL found the same 8192-byte pattern at offset 32 of the TLS template. MSVC 14.29 was not run. The README sentence about that toolset was left unchanged. ## Evidence and follow-up The brace list is source in `tests/cpu/tls_value.cpp`. A `static_assert` checks it word for word against `span_word()`. The existing test is the negative control: swapping the callback table and zeroing the template from its first page boundary are still rejected. Assumption: MSVC 19.42 puts a thread-local aggregate in the TLS template when the initializer is a brace list of constant expressions, and not when that initializer calls a function. That is the comparison recorded on #1119. This change does not retarget the five CRT-free EXE fixtures from #1094. No game files, dumps, or distribution links. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Grok Build).
upstream-sync closed this pull request 2026-11-24 14:03:00 +00:00
tedin7 commented 2026-11-24 14:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:31:28Z.

Review: COMMENTED


Reviewed 04d78f3d93adf5e61a446766565be7a3861289df:

  • Change: tests/cpu/tls_value.cpp replaces the constexpr Span make_span() call initializer on __declspec(thread) Span g_span with a macro-expanded brace list of constant expressions (SPAN_TEMPLATE), plus a static_assert(span_template_matches(), ...) verifying word-for-word equivalence with span_word(). The existing template/callback negative controls in tests/cpu/native_tls_value_check.py remain intact.
  • Linux checks: git diff --check origin/main..HEAD, python3 tests/docs_links_check.py (338 links across 16 files), and python3 tests/bidi_controls_check.py (1228 files) all passed.
  • Win2025 verification (Windows Server 2025 Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): cpu_tls_value built (3.78s); ctest --preset dev -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' --parallel 4 --no-tests=error --output-on-failure — 5/5 passed (2.60s).
    • Release /O2 (--preset release): cpu_tls_value built (1.05s); same CTest filter — 5/5 passed (1.58s).

Looks good to me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040077202 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1505#pullrequestreview-6040077202). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:31:28Z. **Review:** COMMENTED --- Reviewed `04d78f3d93adf5e61a446766565be7a3861289df`: - **Change**: `tests/cpu/tls_value.cpp` replaces the `constexpr Span make_span()` call initializer on `__declspec(thread) Span g_span` with a macro-expanded brace list of constant expressions (`SPAN_TEMPLATE`), plus a `static_assert(span_template_matches(), ...)` verifying word-for-word equivalence with `span_word()`. The existing template/callback negative controls in `tests/cpu/native_tls_value_check.py` remain intact. - **Linux checks**: `git diff --check origin/main..HEAD`, `python3 tests/docs_links_check.py` (338 links across 16 files), and `python3 tests/bidi_controls_check.py` (1228 files) all passed. - **Win2025 verification** (Windows Server 2025 Build 26100, MSVC 14.44.35207): - **Debug (`--preset dev`)**: `cpu_tls_value` built (`3.78s`); `ctest --preset dev -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' --parallel 4 --no-tests=error --output-on-failure` — **5/5 passed** (`2.60s`). - **Release `/O2` (`--preset release`)**: `cpu_tls_value` built (`1.05s`); same CTest filter — **5/5 passed** (`1.58s`). Looks good to me.
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
R0Y00/Xbox2Windows!1498
No description provided.