tests: keep CRT-free EXE templates in static TLS #1112

Merged
R0Y00 merged 1 commit from upstream-pr/1119 into main 2026-11-24 02:07:12 +00:00
R0Y00 commented 2026-11-24 01:20:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T01:20:34Z.


Refs #1094.

Place both page-spanning initialized arrays in the static PE TLS template with MASM. Disable MSVC's on-demand TLS guards for these CRT-free fixture sources, which have no dynamic TLS initializer. Keep /GA for the slot-zero variants, the original byte patterns, and the differential and negative controls.

On Windows x64 using MSVC 19.51.36244, both Debug and Release linked all five fixture targets. The following test selection passed 4/4 in each preset, including the swapped-callback and zeroed-second-page controls.

ctest --preset dev --no-tests=error -R '^cpu_native_exe_tls($|_slot0)' -V
ctest --preset release --no-tests=error -R '^cpu_native_exe_tls($|_slot0)' -V

MSVC 19.42 still needs independent confirmation on the reporter's host.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572425326 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1119). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T01:20:34Z. --- Refs #1094. Place both page-spanning initialized arrays in the static PE TLS template with MASM. Disable MSVC's on-demand TLS guards for these CRT-free fixture sources, which have no dynamic TLS initializer. Keep /GA for the slot-zero variants, the original byte patterns, and the differential and negative controls. On Windows x64 using MSVC 19.51.36244, both Debug and Release linked all five fixture targets. The following test selection passed 4/4 in each preset, including the swapped-callback and zeroed-second-page controls. ```powershell ctest --preset dev --no-tests=error -R '^cpu_native_exe_tls($|_slot0)' -V ctest --preset release --no-tests=error -R '^cpu_native_exe_tls($|_slot0)' -V ``` MSVC 19.42 still needs independent confirmation on the reporter's host.
tedin7 commented 2026-11-24 02:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:03:01Z.

Review: COMMENTED


Reviewed at c3a14857be5087490f3180fe6ca2efdf12ae63dc (CMakeLists.txt, tests/cpu/exe_tls.cpp, tests/cpu/exe_tls_slot0.cpp, tests/cpu/exe_tls_template.asm).

  • Moving g_span and t_array into .tls$X SEGMENT ALIGN(4) 'DATA' in MASM with /Zc:tlsGuards- on the CRT-free C++ sources avoids MSVC dynamic TLS guard emission while preserving the exact 0x1400 0xFF bytes (t_array) and 32-bit masked (0A5000000h XOR (word_index * 09E3779B1h)) AND 0FFFFFFFFh pattern (g_span).
  • Scope is clean and title-neutral, and all 4 CI checks (including Debug and Release Windows builds/tests) passed on this commit.
  • Linux checks run in a detached worktree: python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py, python3 -B tests/gpu_report_format_check.py, python3 -B tests/xgameruntime_table_check.py — all passed; Windows MSVC/MASM verification relies on CI.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6032526785 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1119#pullrequestreview-6032526785). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T02:03:01Z. **Review:** COMMENTED --- Reviewed at `c3a14857be5087490f3180fe6ca2efdf12ae63dc` (`CMakeLists.txt`, `tests/cpu/exe_tls.cpp`, `tests/cpu/exe_tls_slot0.cpp`, `tests/cpu/exe_tls_template.asm`). - Moving `g_span` and `t_array` into `.tls$X SEGMENT ALIGN(4) 'DATA'` in MASM with `/Zc:tlsGuards-` on the CRT-free C++ sources avoids MSVC dynamic TLS guard emission while preserving the exact `0x1400` `0xFF` bytes (`t_array`) and 32-bit masked `(0A5000000h XOR (word_index * 09E3779B1h)) AND 0FFFFFFFFh` pattern (`g_span`). - Scope is clean and title-neutral, and all 4 CI checks (including Debug and Release Windows builds/tests) passed on this commit. - Linux checks run in a detached worktree: `python3 -B tests/docs_links_check.py`, `python3 -B tests/bidi_controls_check.py`, `python3 -B tests/gpu_report_format_check.py`, `python3 -B tests/xgameruntime_table_check.py` — all passed; Windows MSVC/MASM verification relies on CI.
upstream-sync closed this pull request 2026-11-24 06:46:25 +00:00
SimSalabimse commented 2026-11-24 06:50:04 +00:00 (Migrated from github.com)

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


Tested PR #1119 at c3a14857be on MSVC 19.42 (VS 2022 17.12.3, cl 19.42.34435.0), Windows 26200.

Debug: cpu_exe_tls, cpu_exe_tls_early, cpu_exe_tls_slot0, cpu_exe_tls_slot0_enroll, and cpu_exe_tls_slot0_pause all linked. ctest: 4 passed, 0 failed (cpu_native_exe_tls, cpu_native_exe_tls_slot0_windows, cpu_native_exe_tls_slot0, cpu_native_exe_tls_slot0_enroll).

Release: the same 5 targets linked. ctest: 4 passed, 0 failed (same four tests).

These are the same five targets that failed to link on this toolset before (#1094).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119277781 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1119#issuecomment-7119277781). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T01:37:00Z. --- Tested PR #1119 at c3a14857be5087490f3180fe6ca2efdf12ae63dc on MSVC 19.42 (VS 2022 17.12.3, cl 19.42.34435.0), Windows 26200. Debug: `cpu_exe_tls`, `cpu_exe_tls_early`, `cpu_exe_tls_slot0`, `cpu_exe_tls_slot0_enroll`, and `cpu_exe_tls_slot0_pause` all linked. ctest: 4 passed, 0 failed (`cpu_native_exe_tls`, `cpu_native_exe_tls_slot0_windows`, `cpu_native_exe_tls_slot0`, `cpu_native_exe_tls_slot0_enroll`). Release: the same 5 targets linked. ctest: 4 passed, 0 failed (same four tests). These are the same five targets that failed to link on this toolset before (#1094).
roansystemlabs commented 2026-11-24 06:50:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-24T02:04:51Z.


Ran #1119 at c3a14857 with MSVC 19.42.34444 (toolset 14.42.34433), Windows 11 build 26200.9974, alongside the confirmation above. The five targets link in Debug and Release here too, and the four native/mapped checks plus cpu_package_main_image pass, three Debug runs.

One more test fails on 19.42 for the same reason, on main and with this PR: cpu_native_tls_value (tests/cpu/tls_value.cpp uses the same __declspec(thread) Span g_span = make_span();). That DLL links the static CRT, so it builds, but 19.42 initializes g_span dynamically and the check stops at cpu_tls_value.dll: the 8 KiB array is not in the TLS template. 19.44 places it in the template.

What I measured on 19.42 by compiling the initializer forms by hand: a thread-local aggregate whose initializer calls any function, constexpr or not, gets a dynamic initializer (also with /O2, /std:c++20, /permissive- and a raised /constexpr:steps; constinit with /std:c++20 gives C2127), while a brace list of plain constant expressions is constant-initialized. Writing the template as such a brace list makes cpu_native_tls_value pass on 19.42 here; the MASM template from this PR should work for tls_value.cpp too, but I have not tried it. For reference only, the brace-list version is on roansystemlabs:build/1094-tls-on-demand (1ddfc063); it also rewrites the two EXE templates this PR covers, so it is not meant to be merged as is. I can open a small follow-up for tls_value.cpp after this lands, if useful.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119734544 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1119#issuecomment-7119734544). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-24T02:04:51Z. --- Ran #1119 at `c3a14857` with MSVC 19.42.34444 (toolset 14.42.34433), Windows 11 build 26200.9974, alongside the confirmation above. The five targets link in Debug and Release here too, and the four native/mapped checks plus `cpu_package_main_image` pass, three Debug runs. One more test fails on 19.42 for the same reason, on `main` and with this PR: `cpu_native_tls_value` (`tests/cpu/tls_value.cpp` uses the same `__declspec(thread) Span g_span = make_span();`). That DLL links the static CRT, so it builds, but 19.42 initializes `g_span` dynamically and the check stops at `cpu_tls_value.dll: the 8 KiB array is not in the TLS template`. 19.44 places it in the template. What I measured on 19.42 by compiling the initializer forms by hand: a thread-local aggregate whose initializer calls any function, constexpr or not, gets a dynamic initializer (also with /O2, /std:c++20, /permissive- and a raised /constexpr:steps; `constinit` with /std:c++20 gives C2127), while a brace list of plain constant expressions is constant-initialized. Writing the template as such a brace list makes `cpu_native_tls_value` pass on 19.42 here; the MASM template from this PR should work for `tls_value.cpp` too, but I have not tried it. For reference only, the brace-list version is on `roansystemlabs:build/1094-tls-on-demand` (`1ddfc063`); it also rewrites the two EXE templates this PR covers, so it is not meant to be merged as is. I can open a small follow-up for `tls_value.cpp` after this lands, if useful. AI-assisted.
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!1112
No description provided.