Skip to content

TLS: xcl.exe built with MinGW and lld keeps its TLS directory - #464

Open
pablogonz12 wants to merge 1 commit into
ivall:mainfrom
pablogonz12:gnu-tls-directory
Open

pablogonz12 wants to merge 1 commit into
ivall:mainfrom
pablogonz12:gnu-tls-directory

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 24, 2026 •

Copy link
Copy Markdown

XCL's TLS callback (.CRT$XLY in main.rs) and the title's slot 0 need xcl.exe's TLS directory. MSVC's linker always emits one. With MinGW the directory is _tls_used in the CRT's tlssup.o, which LLVM's lld (llvm-mingw) leaves out when nothing refers to it. An x86_64-pc-windows-gnu build linked that way had no TLS directory (llvm-readobj --coff-tls-directory printed nothing), the log said TLS: <title>.exe keeps slot 4 (xcl.exe has no TLS directory) – code built with /GA reads slot 0, and a retail title faulted on its second thread about 0.7 s in. The existing test pe::tests::parses_own_test_binary_tls fails on main the same way.

Related: #257 (Linux docs and scripts, which build for x86_64-pc-windows-gnu).

What is in it

  • crates/xcl/src/tls.rs: on target_env = "gnu", own_tls_index() refers to _tls_used, which keeps the directory. MSVC builds are unchanged (the code is cfg'd out).
  • Test tls::tests::the_executable_has_a_tls_directory.

Tested

  • AMD Radeon RX 9070 XT (RADV GFX1201, Mesa), AMD Ryzen 9 9900X, CachyOS (Linux 7.3), Wine 11.0 (Proton CachyOS) with vkd3d-proton v3.1 + the patch from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, Rust stable, llvm-mingw 20261117 (clang 23.1.6, lld), release, target x86_64-pc-windows-gnu, run under Wine.
  • cargo test -p xcl --lib --release --target x86_64-pc-windows-gnu, test binary run under Wine with --test-threads=4:
    • this PR (4a1f727): 633 passed, 4 failed, 21 ignored;
    • main (a6f5f7a): 631 passed, 5 failed, 21 ignored. The fifth is pe::tests::parses_own_test_binary_tls, which this PR fixes; the other four fail the same way on both (gpu_f64_roots, gpu_f64_math_random, gpu_nonfused_mad_and_mac_prevent_fma_contraction, xma2_source_voice_decodes_and_manages_lifetime) and are not touched here.
  • The new test with the _tls_used reference removed: FAILED; with it: ok.
  • Retail title: before, a fault at 0.7 s; after, it reaches its first presented frames and ends at XCL_RUN_SECONDS with exit code 0 (blocks below).

Regression run

Made with scripts/linux/smoke.sh from #257 under Wine (not smoke.ps1), GNU builds of both commits. The main block was made with a local copy of the script with two lines changed so that a run which does not reach its end still prints its block (set -eu instead of set -euo pipefail; the data: fallback as an if): on main this build crashes before its first frame.

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 9070 XT (RADV GFX1201)
title: Build
seconds: 60
exit: 0x5
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0
device removals: 0
crashes: 3
peak commit: 0 MB
xcl-smoke v1
commit: 4a1f72721adb4e9040b3390220f44d3f386d50f5
gpu: AMD Radeon RX 9070 XT (RADV GFX1201)
title: Build
seconds: 60
exit: 0x0
frames shown: 9 (PresentX 9)
presents per 2 s (last 3): 0 1 0
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • Windows, and MSVC builds (the change is compiled out there).
  • MinGW-w64 gcc with GNU ld (it may keep tlssup.o already; there this is a no-op).
  • cargo test --workspace: only the xcl library tests were run.

AI use

  • Claude Code (Claude Opus 5.5): found the cause, wrote the change, the test and this description, and ran the commands above on the machine described.

XCL's TLS callback (.CRT$XLY in main.rs) and the title's slot 0 need xcl.exe's TLS directory. MSVC's linker always emits one; with MinGW it is _tls_used in the CRT's tlssup.o, which lld (llvm-mingw) leaves out when nothing refers to it. The x86_64-pc-windows-gnu build then had no TLS directory: the title kept slot 4 while its /GA code reads slot 0 and faulted on its second thread. own_tls_index() now refers to _tls_used on target_env = "gnu", which keeps the directory; a unit test checks the executable has one.

@towiice towiice left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested PR head 4a1f727 with Rust 1.100.0 (stable-x86_64-pc-windows-gnullvm, llvm-mingw 23.1.6 UCRT + lld) on Windows 11 build 10.0.26300 (26H2), NVIDIA GeForce GTX 1650 SUPER (driver 610.88), DXC v1.9.2609:

  • cargo build --workspace: succeeded.
  • cargo test -p xcl --lib tls -- --test-threads=4: 7 passed, 0 failed, 1 ignored (including tls::tests::the_executable_has_a_tls_directory and pe::tests::parses_own_test_binary_tls).
  • cargo test -p xcl --test e2e: 3 passed, 0 failed (30.79 s).

Builds and passes cleanly under llvm-mingw + lld.

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