Skip to content

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

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

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

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.
  • Whole workspace (rerun 25 Nov): cargo xwin test --workspace --release --locked --target x86_64-pc-windows-msvc --no-run, then each of the 15 test binaries from its package folder under Wine (GE-Proton11-14, Mesa 26.3.1, DXC 1.9.2609.5, Rust 1.100.0, static CRT) with --test-threads=4; no filters, 0 SKIPPED lines on the head, 0 on the base:
    • this PR (4a1f727): 670 passed, 7 failed, 41 ignored;
    • its base on main (a6f5f7a): 669 passed, 7 failed, 41 ignored.
    • The same failures on both, all from the Wine / vkd3d-proton / RADV host: disk_free_space_ex_reports_pls_quota, gpu::recomp::tests::gpu_f64_math_random, gpu::recomp::tests::gpu_f64_roots, gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction, hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime, set_predication_buffer_state_and_kickoff, test_title_runs_and_game_folder_is_untouched.
  • 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 (GNU build).

Regression run

Both blocks are the output of each commit's own unmodified scripts/smoke.ps1, written to a file by PowerShell and pasted as is. It ran in Windows PowerShell 7.7.0 (pwsh.exe) under Wine (GE-Proton11-14, Linux), not on native Windows, with MinGit 2.56.1 for git; host workarounds outside the script: a pseudo-terminal, DOTNET_SYSTEM_GLOBALIZATION_USENLS=1, and importing PowerShell's Utility and Management modules first. xcl.exe is an MSVC release build (cargo xwin, static CRT), where this change is compiled out, so this is only a regression check; main is this PR's base commit.

The title is flaky on this host with either commit, so here is every run (alternating, in this order); the pasted pair is run 2, the first where both finished cleanly:

  • run 1, main: exit 0x0, frames 16 (PresentX 16), device removals 0, crashes 0
  • run 1, head: exit 0x887a0005, frames none logged (the run did not reach its end), device removals 1, crashes 2
  • run 2, main: exit 0x0, frames 9 (PresentX 9), device removals 0, crashes 0
  • run 2, head: exit 0x0, frames 10 (PresentX 10), device removals 0, crashes 0
  • run 3, main: exit 0x0, frames 7 (PresentX 7), device removals 0, crashes 0
  • run 3, head: exit 0x0, frames 4 (PresentX 5), device removals 0, crashes 0
  • run 4, main: exit 0x887a0005, frames none logged (the run did not reach its end), device removals 1, crashes 1
  • run 4, head: exit 0x0, frames 3 (PresentX 4), device removals 0, crashes 0

The GNU/lld build, which this PR fixes, was run earlier with the bash script from #257 (not smoke.ps1): main faulted before its first frame and this head presented frames and exited 0.

main:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
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): 1 1 1
device removals: 0
crashes: 0
peak commit: 0 MB

This PR's head:

xcl-smoke v1
commit: 4a1f72721adb4e9040b3390220f44d3f386d50f5
gpu: AMD Radeon RX 9070 XT (RADV GFX1201)
title: Build
seconds: 60
exit: 0x0
frames shown: 10 (PresentX 10)
presents per 2 s (last 3): 1 1 1
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • Native Windows. MSVC builds were only run under Wine (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 on the GNU target: the whole-workspace run above is MSVC; on GNU 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.
  • Claude Code (Claude Sonnet 5.5): on 25 Nov ran the whole-workspace tests and the smoke.ps1 runs and updated those two parts of this description.

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.

@JoaoPauluu

Copy link
Copy Markdown

Test report: #464 with GNU ld (mingw-w64-gcc) on NVIDIA

This complements the PR's llvm-mingw / lld run on AMD with the other common MinGW toolchain: mingw-w64-gcc with GNU ld (binutils), on an NVIDIA GPU. With GNU ld the bug doesn't occur, and the PR changes nothing there: same test results apart from its new test, same TLS layout, same game run.

Setup

  • CachyOS, kernel 7.3.3-1-cachyos, Intel i5-10400F, 16 GB RAM, NVIDIA GeForce RTX 3060 12 GB, driver 620.70.06
  • Rust 1.100.0, target x86_64-pc-windows-gnu; mingw-w64-gcc 16.2.0 (posix), GNU ld 2.47 (CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc)
  • Proton Experimental experimental-11.0-20261112 (wine-11.0); 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; DXVK from Proton; DXC 1.9.2609; DXVK_CONFIG="dxgi.hideNvidiaGpu = False"
  • Commits: this PR's head 4a1f727 and its base, main a6f5f7a

TLS directory (llvm-readobj --coff-tls-directory xcl.exe)

  • Both commits, release and debug: present (e.g. release AddressOfIndex: 0x1406D09EC on both). GNU ld keeps _tls_used without the reference.

Tests (debug build, lib test binary under Wine)

Regression run (GTA VI 1.0.2.1, my own dump; scripts/linux/smoke.sh from #257 under Wine, release builds of both commits)

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 894 (PresentX 895)
presents per 2 s (last 3): 29 2 0
device removals: 0
crashes: 0
peak commit: 0 MB
xcl-smoke v1
commit: 4a1f72721adb4e9040b3390220f44d3f386d50f5
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 875 (PresentX 875)
presents per 2 s (last 3): 33 31 1
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • llvm-mingw / lld (the case the PR fixes; covered by the PR's own run), MSVC, Windows, AMD

AI use: Claude Code (Claude Opus 5.5) built both commits, ran every command above on the machine above and wrote this report. The counts and blocks are pasted from those runs. I reviewed the report before posting.

@ClosetPie107

Copy link
Copy Markdown

Linux / MinGW (x86_64-pc-windows-gnu) + AMD RDNA4 (RADV) test report for head 4a1f727 merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile (MinGW-w64 gcc)

Tested (debug test binary under Wine, --test-threads=1 --nocapture)

  • tls::tests: 5 passed, 0 failed, 1 ignored (carrier_variants_probe), 0 skipped (0.01 s), including the_executable_has_a_tls_directory.

Not tested: full workspace suite, llvm-mingw / lld linker specifically, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

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.

4 participants