Repository navigation
TLS: xcl.exe built with MinGW and lld keeps its TLS directory - #464
pablogonz12 wants to merge 1 commit into
Conversation
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.
db04128 to
4a1f727
Compare
towiice
left a comment
There was a problem hiding this comment.
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 (includingtls::tests::the_executable_has_a_tls_directoryandpe::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.
Test report: #464 with GNU ld (mingw-w64-gcc) on NVIDIAThis 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
TLS directory (
Tests (debug build, lib test binary under Wine)
Regression run (GTA VI 1.0.2.1, my own dump;
Not tested
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. |
XCL's TLS callback (
.CRT$XLYinmain.rs) and the title's slot 0 needxcl.exe's TLS directory. MSVC's linker always emits one. With MinGW the directory is_tls_usedin the CRT'stlssup.o, which LLVM's lld (llvm-mingw) leaves out when nothing refers to it. Anx86_64-pc-windows-gnubuild linked that way had no TLS directory (llvm-readobj --coff-tls-directoryprinted nothing), the log saidTLS: <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 testpe::tests::parses_own_test_binary_tlsfails onmainthe 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: ontarget_env = "gnu",own_tls_index()refers to_tls_used, which keeps the directory. MSVC builds are unchanged (the code iscfg'd out).tls::tests::the_executable_has_a_tls_directory.Tested
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:4a1f727): 633 passed, 4 failed, 21 ignored;main(a6f5f7a): 631 passed, 5 failed, 21 ignored. The fifth ispe::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._tls_usedreference removed: FAILED; with it: ok.XCL_RUN_SECONDSwith exit code 0 (blocks below).Regression run
Made with
scripts/linux/smoke.shfrom #257 under Wine (notsmoke.ps1), GNU builds of both commits. Themainblock 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 -euinstead ofset -euo pipefail; thedata:fallback as anif): onmainthis build crashes before its first frame.Not tested
tlssup.oalready; there this is a no-op).cargo test --workspace: only thexcllibrary tests were run.AI use