cpu_native_tls_value fails with MSVC 19.42: expected 8 KiB pattern missing from cpu_tls_value.dll TLS template #1458

Closed
opened 2026-11-24 11:59:25 +00:00 by trick-ye · 3 comments
trick-ye commented 2026-11-24 11:59:25 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by trick-ye on 2026-11-24T11:59:25Z.


Commit or build

e84829ded9ca2dff3710b879d37d28986b717cb6 (main when pulled at about 11:44 UTC on 2026-11-24; upstream main may have advanced since), clean tree, existing build directory, dev preset (Debug). The captured incremental build log contains no FAILED: entry. That build did not relink cpu_tls_value.dll, so I deleted the DLL and its object file and rebuilt the target at this commit (cmake --build --preset dev --target cpu_tls_value); the runs and the measurement below use that fresh DLL. I also recorded the same failure once at 59eb781 in https://github.com/R0Y00/Xbox2Windows/issues/1094#issuecomment-7121524592.

This is the failure described for MSVC 19.42 in https://github.com/R0Y00/Xbox2Windows/pull/1119#issuecomment-7119734544. I found no dedicated issue or pull request tracking a fix (searched issues and pull requests for cpu_native_tls_value, tls_value and "TLS template"), so this report gives it one. The README's "First build" note, added in #1178, also says that cpu_native_tls_value fails with Visual Studio 2019 Build Tools (MSVC 14.29), but it does not give the diagnostic or mention MSVC 19.42. This is separate from #1094: the four checks of that issue pass here at this commit in all three runs, on its five targets as linked at 59eb781 (this build did not relink them).

Reproduction

From the checkout root, in a Visual Studio 2022 x64 developer environment with MSVC 19.42, with out/pe-env created from requirements-dev.txt:

cmake --preset dev
cmake --build --preset dev -- -k 0
cmake --build --preset dev --target cpu_tls_value   # after deleting cpu_tls_value.dll and tls_value.cpp.obj
ctest --preset dev --no-tests=error -j 1 -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V

The filter selects five tests: cpu_native_tls_value and the four cpu_native_exe_tls* checks from #1094 as a control.

Expected behavior

cpu_native_tls_value passes: the 8 KiB array g_span of tests/cpu/tls_value.cpp is in the TLS data template of cpu_tls_value.dll.

Observed behavior

cpu_native_tls_value fails in 3 of 3 runs; the four control tests pass in all three. Each run reports 80% tests passed, 1 tests failed out of 5.

554: control: empty-template TLS fixture loads under Windows and pe_map
554: Traceback (most recent call last):
554:   File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 405, in <module>
554:     check(args.value, args.control, args.sink, args.mapper)
554:   File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 354, in check
554:     info = layout(value_image)
554:   File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 88, in layout
554:     raise AssertionError(f"{Path(image).name}: the 8 KiB array is not in the TLS template")
554: AssertionError: cpu_tls_value.dll: the 8 KiB array is not in the TLS template
1/5 Test #554: cpu_native_tls_value ...............***Failed    0.62 sec
2/5 Test #567: cpu_native_exe_tls .................   Passed    1.24 sec
3/5 Test #568: cpu_native_exe_tls_slot0_windows ...   Passed    0.13 sec
4/5 Test #569: cpu_native_exe_tls_slot0 ...........   Passed    0.19 sec
5/5 Test #570: cpu_native_exe_tls_slot0_enroll ....   Passed    0.17 sec

(Fresh run 1 excerpt: the test 554 diagnostic and traceback, minus the traceback marker line, followed by the five result lines. CTest's repeated failure output and the other tests' verbose output are omitted. Three earlier runs with the DLL from the existing build directory produced the same pass/fail results.)

What was measured and what is a hypothesis:

  • Measured: the test stops in layout() at the first check, before any thread or pe_map comparison of the value fixture runs.
  • Measured, with a read-only pefile script over the built DLL (same method as template_of() in the check): the TLS data template of cpu_tls_value.dll is 8225 bytes long and contains one nonzero byte (value 7 at offset 16). The 8192-byte pattern that the check computes from span_word() occurs neither in the template nor anywhere else in the file, and neither do its first 16 bytes.
  • Measured: at this commit tests/cpu/tls_value.cpp line 49 is __declspec(thread) Span g_span = make_span();, with make_span() a constexpr function.
  • Reported by another contributor, not measured here: the linked #1119 comment reports dynamic initialization of g_span on MSVC 19.42, placement in the TLS template on 19.44, and a passing brace-list workaround on 19.42.
  • Hypothesis: dynamic initialization is a possible explanation for my result. The PE measurement shows that the initialized pattern is absent from the file, not how g_span is initialized. I did not inspect the object code, test another compiler version, or try a fixture change.

Not measured: the release preset, and any other compiler version.

Environment

  • Windows 11 Pro, build 26200.9974
  • Visual Studio 2022 Community, MSVC 19.42.34436 (toolset 14.42.34433)
  • Windows SDK 10.0.26100.0, CMake and Ninja from Visual Studio, Python 3.13.0
  • No graphics adapter is involved in this failure.

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6581254064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1465). Originally posted by [trick-ye](https://github.com/trick-ye) on 2026-11-24T11:59:25Z. --- ### Commit or build `e84829ded9ca2dff3710b879d37d28986b717cb6` (`main` when pulled at about 11:44 UTC on 2026-11-24; upstream `main` may have advanced since), clean tree, existing build directory, `dev` preset (Debug). The captured incremental build log contains no `FAILED:` entry. That build did not relink `cpu_tls_value.dll`, so I deleted the DLL and its object file and rebuilt the target at this commit (`cmake --build --preset dev --target cpu_tls_value`); the runs and the measurement below use that fresh DLL. I also recorded the same failure once at `59eb781` in https://github.com/R0Y00/Xbox2Windows/issues/1094#issuecomment-7121524592. This is the failure described for MSVC 19.42 in https://github.com/R0Y00/Xbox2Windows/pull/1119#issuecomment-7119734544. I found no dedicated issue or pull request tracking a fix (searched issues and pull requests for `cpu_native_tls_value`, `tls_value` and "TLS template"), so this report gives it one. The README's "First build" note, added in #1178, also says that `cpu_native_tls_value` fails with Visual Studio 2019 Build Tools (MSVC 14.29), but it does not give the diagnostic or mention MSVC 19.42. This is separate from #1094: the four checks of that issue pass here at this commit in all three runs, on its five targets as linked at `59eb781` (this build did not relink them). ### Reproduction From the checkout root, in a Visual Studio 2022 x64 developer environment with MSVC 19.42, with `out/pe-env` created from `requirements-dev.txt`: ```powershell cmake --preset dev cmake --build --preset dev -- -k 0 cmake --build --preset dev --target cpu_tls_value # after deleting cpu_tls_value.dll and tls_value.cpp.obj ctest --preset dev --no-tests=error -j 1 -R '^cpu_(native|mapped)_tls_value|^cpu_native_exe_tls' -V ``` The filter selects five tests: `cpu_native_tls_value` and the four `cpu_native_exe_tls*` checks from #1094 as a control. ### Expected behavior `cpu_native_tls_value` passes: the 8 KiB array `g_span` of `tests/cpu/tls_value.cpp` is in the TLS data template of `cpu_tls_value.dll`. ### Observed behavior `cpu_native_tls_value` fails in 3 of 3 runs; the four control tests pass in all three. Each run reports `80% tests passed, 1 tests failed out of 5`. ```text 554: control: empty-template TLS fixture loads under Windows and pe_map 554: Traceback (most recent call last): 554: File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 405, in <module> 554: check(args.value, args.control, args.sink, args.mapper) 554: File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 354, in check 554: info = layout(value_image) 554: File "C:\src\x2w\tests\cpu\native_tls_value_check.py", line 88, in layout 554: raise AssertionError(f"{Path(image).name}: the 8 KiB array is not in the TLS template") 554: AssertionError: cpu_tls_value.dll: the 8 KiB array is not in the TLS template 1/5 Test #554: cpu_native_tls_value ...............***Failed 0.62 sec 2/5 Test #567: cpu_native_exe_tls ................. Passed 1.24 sec 3/5 Test #568: cpu_native_exe_tls_slot0_windows ... Passed 0.13 sec 4/5 Test #569: cpu_native_exe_tls_slot0 ........... Passed 0.19 sec 5/5 Test #570: cpu_native_exe_tls_slot0_enroll .... Passed 0.17 sec ``` (Fresh run 1 excerpt: the test 554 diagnostic and traceback, minus the traceback marker line, followed by the five result lines. CTest's repeated failure output and the other tests' verbose output are omitted. Three earlier runs with the DLL from the existing build directory produced the same pass/fail results.) What was measured and what is a hypothesis: - Measured: the test stops in `layout()` at the first check, before any thread or `pe_map` comparison of the value fixture runs. - Measured, with a read-only `pefile` script over the built DLL (same method as `template_of()` in the check): the TLS data template of `cpu_tls_value.dll` is 8225 bytes long and contains one nonzero byte (value 7 at offset 16). The 8192-byte pattern that the check computes from `span_word()` occurs neither in the template nor anywhere else in the file, and neither do its first 16 bytes. - Measured: at this commit `tests/cpu/tls_value.cpp` line 49 is `__declspec(thread) Span g_span = make_span();`, with `make_span()` a `constexpr` function. - Reported by another contributor, not measured here: the linked #1119 comment reports dynamic initialization of `g_span` on MSVC 19.42, placement in the TLS template on 19.44, and a passing brace-list workaround on 19.42. - Hypothesis: dynamic initialization is a possible explanation for my result. The PE measurement shows that the initialized pattern is absent from the file, not how `g_span` is initialized. I did not inspect the object code, test another compiler version, or try a fixture change. Not measured: the `release` preset, and any other compiler version. ### Environment - Windows 11 Pro, build 26200.9974 - Visual Studio 2022 Community, MSVC 19.42.34436 (toolset 14.42.34433) - Windows SDK 10.0.26100.0, CMake and Ninja from Visual Studio, Python 3.13.0 - No graphics adapter is involved in this failure. ### Checklist - [x] I reproduced this on a source-built input. - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 13:00:52 +00:00 (Migrated from github.com)
Author
Contributor

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


Thanks for checking the freshly linked DLL. The failure is in the source-built TLS template check before either loader runs. Please use the brace-initializer workaround from #1119 as the first comparison. Keep the same 8 KiB pattern and the existing test, then compare template bytes and run cpu_native_tls_value on 19.42 and a current toolset. A template that still differs should remain a clear fixture failure.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131082072 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1465#issuecomment-7131082072). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:11:01Z. --- Thanks for checking the freshly linked DLL. The failure is in the source-built TLS template check before either loader runs. Please use the brace-initializer workaround from #1119 as the first comparison. Keep the same 8 KiB pattern and the existing test, then compare template bytes and run cpu_native_tls_value on 19.42 and a current toolset. A template that still differs should remain a clear fixture failure.
SimSalabimse commented 2026-11-24 14:03:23 +00:00 (Migrated from github.com)
Author
Contributor

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


Claiming this. Plan: switch g_span in tests/cpu/tls_value.cpp to the brace-initializer workaround from #1119 so the same 8 KiB pattern lands in the TLS template on MSVC 19.42, and keep the existing cpu_native_tls_value check. I'll compare template bytes and run the test in Debug and Release on 19.42. A template that still differs stays a fixture failure.

AI-assisted (Grok Build)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132385892 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1465#issuecomment-7132385892). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T13:07:38Z. --- Claiming this. Plan: switch `g_span` in `tests/cpu/tls_value.cpp` to the brace-initializer workaround from #1119 so the same 8 KiB pattern lands in the TLS template on MSVC 19.42, and keep the existing `cpu_native_tls_value` check. I'll compare template bytes and run the test in Debug and Release on 19.42. A template that still differs stays a fixture failure. AI-assisted (Grok Build)
R0Y00 commented 2026-11-24 14:03:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:27:57Z.


Fixed in #1505. The same 8 KiB TLS template pattern and its existing byte check remain. The contributor verified MSVC 19.42 in Debug and Release, and I independently reproduced a passing cpu_native_tls_value on current MSVC 19.51 in Release.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132868086 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1465#issuecomment-7132868086). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:27:57Z. --- Fixed in #1505. The same 8 KiB TLS template pattern and its existing byte check remain. The contributor verified MSVC 19.42 in Debug and Release, and I independently reproduced a passing cpu_native_tls_value on current MSVC 19.51 in Release.
Sign in to join this conversation.
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#1458
No description provided.