fix(host): start a thread whose stack is under the static TLS block #2971

Merged
HumanBean merged 4 commits from omgitsgela/Longshot:fix/ab-thread-stack into main 2026-12-02 14:59:28 +00:00
Member

Summary

On Linux the host could not start a thread that asks for a small stack, on a build whose executable carries a large static
TLS block. host/hos_ab.c asks for 64 KiB for its A/B thread, and on a Steam Deck it never started:

ab: the A/B's thread did not start: no A/B in this run

The cause is in host/posix/win32_posix.c's CreateThread: it passed the requested size straight to
pthread_attr_setstacksize. glibc keeps the executable's static TLS block at the top of every thread's stack and refuses a
stack too small to hold that block plus a guard page and a rest stack, with EINVAL. The Deck's host binary's PT_TLS MemSiz is
0x00f1f0 = 61,936 bytes, so a 64 KiB stack is refused there while the same request starts in a small program (which is why
it reproduced in the game and not in a probe). Windows keeps TLS outside the thread stack and honors any explicit size, so
this never showed there.

This change reads the executable's PT_TLS once (dl_iterate_phdr, cached with pthread_once) and treats an explicit stack
request as a floor: below the block plus 64 KiB, the request is grown to fit. The executable's block is not the whole of
glibc's reservation (a startup library brings its own), so a creation glibc still refuses is retried larger, up to 64 MB. Sizes
are checked for overflow, and a request that cannot be a stack is refused rather than rounded into a small one. Asking for no
size still means the executable's 8 MB, unchanged, and guest threads' 64 MB is untouched.

To see the bug on main: on a Linux build whose binary carries a static TLS block, run with HOS_AB=<a wired switch>=<value>,<period>,<warm-up>. The log says "the A/B's thread did not start: no A/B in this run" and the frame trace's
ab_side column stays empty. With this change the run logs the alternation and scripts/perf.py ab reports its periods.

Read first: host/posix/win32_posix.c (static_tls_size, CreateThread), tests/test_create_thread_small_stack.py.

Testing

Tested: Steam Deck LCD (RADV VANGOGH, Mesa 26.2.0-devel, Linux 6.16), runtime built from this branch (base 87045899),
HOS_AB=HOS_COLLECT_WIDE=0,4,20, Hyrule Field route, 1280x800 at 50 % render. Before: "the A/B's thread did not start".
After: "ab: the warm-up is over: HOS_COLLECT_WIDE alternates now", 16 side 0 and 16 side 1 flips over the run, and
scripts/perf.py ab on the trace reports 31 periods (15 side 0, 16 side 1) with each side's means. The A/B is usable again on
this hardware.

Game-free test: tests/test_create_thread_small_stack.py fails on main (the 64 KiB CreateThread returns NULL when the
program carries a 61,936-byte __thread block) and passes here. It asserts the chosen size directly (stack_want: the floor
for a small request, the request unchanged above it, 8 MB for none, 0 for an impossible size), then reads back what each
thread actually got with pthread_getattr_np, so a glibc that refuses the small stack cannot hide a missing floor behind the
retry. tests/test_posix_cv_wake.py and
tests/test_thread_arg_self.py, which cut the same file, still pass. tests/test_host_alloc_wait.py cuts CreateThread
too: it now stubs the new static_tls_size (that fixture starts no thread and asks for no size), after which it passes.

tests/run_all.py --strict --changed: 22 passed, 6 failed on this machine (Linux, no Vulkan device). The six
(test_crash_record, test_image_reaper_threads, test_windows_on_linux, test_linux_audio_output, test_mods_list,
test_mods_sizes) fail the same way on a clean main checkout here; the full suite on clean main on this machine is 683
passed, 229 failed, so this environment cannot serve as the gate. CI should be read for that.

Still to test:

  • Windows: nothing to run, host/posix/win32_posix.c is not compiled there (host/win32/ is), so the Windows host is
    unaffected (by hand: nothing to run, no Test Farm run needed).
  • A Linux host whose static TLS block is larger than 64 KiB but which builds with a different compiler: run the new test,
    expecting it to pass (by hand; the test asserts the growth and the pass-through).

Measurements

Nothing to measure: this starts a thread that was not starting, changes no renderer path and no switch's default, and the A/B it restores is itself a measuring tool.

Risks

  • A thread that explicitly asks for a small stack now gets one large enough to hold the executable's static TLS block plus
    64 KiB. That costs address space, not committed memory, and only affects explicit small requests: the default (no size)
    and guest threads' 64 MB are unchanged, and a request already above the floor is passed through untouched.
  • A creation glibc refuses with EINVAL is retried at twice the size, at most five times before 64 MB, and only for explicit
    requests; a default-size thread is never retried.
  • If dl_iterate_phdr reports no PT_TLS for the executable, the size is left exactly as before: the change can only grow
    a request, never shrink one.
  • Nothing changes for players who do not use HOS_AB: no switch, no cache, no saved option.
  • A revert is enough to undo it.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named): --changed is 22 passed and 6 failed here,
    the six named in Testing all failing the same way on a clean main checkout on this machine.
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened: test_host_alloc_wait cuts CreateThread
    and now stubs the new helper, and test_create_thread_small_stack is added.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths: this file is POSIX-only, so the Windows build
    compiles exactly what it compiled before.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
## Summary On Linux the host could not start a thread that asks for a small stack, on a build whose executable carries a large static TLS block. `host/hos_ab.c` asks for 64 KiB for its A/B thread, and on a Steam Deck it never started: ``` ab: the A/B's thread did not start: no A/B in this run ``` The cause is in `host/posix/win32_posix.c`'s `CreateThread`: it passed the requested size straight to `pthread_attr_setstacksize`. glibc keeps the executable's static TLS block at the top of every thread's stack and refuses a stack too small to hold that block plus a guard page and a rest stack, with EINVAL. The Deck's host binary's `PT_TLS` MemSiz is `0x00f1f0` = 61,936 bytes, so a 64 KiB stack is refused there while the same request starts in a small program (which is why it reproduced in the game and not in a probe). Windows keeps TLS outside the thread stack and honors any explicit size, so this never showed there. This change reads the executable's `PT_TLS` once (`dl_iterate_phdr`, cached with `pthread_once`) and treats an explicit stack request as a floor: below the block plus 64 KiB, the request is grown to fit. The executable's block is not the whole of glibc's reservation (a startup library brings its own), so a creation glibc still refuses is retried larger, up to 64 MB. Sizes are checked for overflow, and a request that cannot be a stack is refused rather than rounded into a small one. Asking for no size still means the executable's 8 MB, unchanged, and guest threads' 64 MB is untouched. To see the bug on `main`: on a Linux build whose binary carries a static TLS block, run with `HOS_AB=<a wired switch>=<value>,<period>,<warm-up>`. The log says "the A/B's thread did not start: no A/B in this run" and the frame trace's `ab_side` column stays empty. With this change the run logs the alternation and `scripts/perf.py ab` reports its periods. Read first: `host/posix/win32_posix.c` (`static_tls_size`, `CreateThread`), `tests/test_create_thread_small_stack.py`. ## Testing **Tested:** Steam Deck LCD (RADV VANGOGH, Mesa 26.2.0-devel, Linux 6.16), runtime built from this branch (base `87045899`), `HOS_AB=HOS_COLLECT_WIDE=0,4,20`, Hyrule Field route, 1280x800 at 50 % render. Before: "the A/B's thread did not start". After: "ab: the warm-up is over: HOS_COLLECT_WIDE alternates now", 16 side 0 and 16 side 1 flips over the run, and `scripts/perf.py ab` on the trace reports 31 periods (15 side 0, 16 side 1) with each side's means. The A/B is usable again on this hardware. Game-free test: `tests/test_create_thread_small_stack.py` fails on `main` (the 64 KiB `CreateThread` returns NULL when the program carries a 61,936-byte `__thread` block) and passes here. It asserts the chosen size directly (`stack_want`: the floor for a small request, the request unchanged above it, 8 MB for none, 0 for an impossible size), then reads back what each thread actually got with `pthread_getattr_np`, so a glibc that refuses the small stack cannot hide a missing floor behind the retry. `tests/test_posix_cv_wake.py` and `tests/test_thread_arg_self.py`, which cut the same file, still pass. `tests/test_host_alloc_wait.py` cuts `CreateThread` too: it now stubs the new `static_tls_size` (that fixture starts no thread and asks for no size), after which it passes. `tests/run_all.py --strict --changed`: 22 passed, 6 failed on this machine (Linux, no Vulkan device). The six (`test_crash_record`, `test_image_reaper_threads`, `test_windows_on_linux`, `test_linux_audio_output`, `test_mods_list`, `test_mods_sizes`) fail the same way on a clean `main` checkout here; the full suite on clean `main` on this machine is 683 passed, 229 failed, so this environment cannot serve as the gate. CI should be read for that. **Still to test:** - Windows: nothing to run, `host/posix/win32_posix.c` is not compiled there (`host/win32/` is), so the Windows host is unaffected (by hand: nothing to run, no Test Farm run needed). - A Linux host whose static TLS block is larger than 64 KiB but which builds with a different compiler: run the new test, expecting it to pass (by hand; the test asserts the growth and the pass-through). ## Measurements Nothing to measure: this starts a thread that was not starting, changes no renderer path and no switch's default, and the A/B it restores is itself a measuring tool. ## Risks - A thread that explicitly asks for a small stack now gets one large enough to hold the executable's static TLS block plus 64 KiB. That costs address space, not committed memory, and only affects explicit small requests: the default (no size) and guest threads' 64 MB are unchanged, and a request already above the floor is passed through untouched. - A creation glibc refuses with EINVAL is retried at twice the size, at most five times before 64 MB, and only for explicit requests; a default-size thread is never retried. - If `dl_iterate_phdr` reports no `PT_TLS` for the executable, the size is left exactly as before: the change can only grow a request, never shrink one. - Nothing changes for players who do not use `HOS_AB`: no switch, no cache, no saved option. - A revert is enough to undo it. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named): `--changed` is 22 passed and 6 failed here, the six named in Testing all failing the same way on a clean `main` checkout on this machine. - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened: `test_host_alloc_wait` cuts `CreateThread` and now stubs the new helper, and `test_create_thread_small_stack` is added. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths: this file is POSIX-only, so the Windows build compiles exactly what it compiled before. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers.
fix(host): a CreateThread stack smaller than the executable's static TLS block starts
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
421f111670
glibc keeps the executable's static TLS block at the top of every thread's stack and refuses, with
EINVAL, a stack too small to hold that block plus a guard page and a rest stack. host/posix/win32_posix.c
passed the requested size straight through, so a host with a large block could not start a small thread:
HOS_AB asks for 64 KiB and the Deck's host binary's block is 61,936 bytes, so the A/B thread never
started there ('ab: the A/B's thread did not start'), while the same request starts in a small program.
Windows keeps TLS outside the stack and honors any explicit size, so an explicit request is now a floor:
below the block plus 64 KiB it is grown to fit, read from the executable's PT_TLS once.

Assisted-by: Hermes Agent (DeepSeek)
Author
Member

Tested in game: Steam Deck LCD, RADV VANGOGH, Mesa 26.2.0-devel, Linux 6.16. With HOS_AB=HOS_COLLECT_WIDE=0,4,20 in Hyrule Field the A/B thread now starts: the log says 'the warm-up is over ... alternates now', 16 side 0 and 16 side 1 flips in one run, and scripts/perf.py ab reports 31 periods (15/16) from the trace. On main the same launch logs 'the A/B's thread did not start: no A/B in this run'.

Tested in game: Steam Deck LCD, RADV VANGOGH, Mesa 26.2.0-devel, Linux 6.16. With HOS_AB=HOS_COLLECT_WIDE=0,4,20 in Hyrule Field the A/B thread now starts: the log says 'the warm-up is over ... alternates now', 16 side 0 and 16 side 1 flips in one run, and scripts/perf.py ab reports 31 periods (15/16) from the trace. On main the same launch logs 'the A/B's thread did not start: no A/B in this run'.
test(host): the out-of-memory fixture stubs the static TLS helper
Some checks failed
CI / What the change needs (pull_request) Successful in 7s
CI / Third-party parts and guide screenshots (pull_request) Failing after 10s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 17s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m16s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 1m57s
PR description / Title and description (pull_request_target) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
dd62e0eff5
tests/test_host_alloc_wait.py cuts CreateThread out of host/posix/win32_posix.c; the stack floor it now
computes needs static_tls_size, so the fixture stands it in as 0: it starts no thread and asks for no
size, so nothing there reads the executable's phdrs.

Assisted-by: Hermes Agent (DeepSeek)
Author
Member

Description filled in: the still-to-test line says who runs it, Measurements states why there is nothing to measure, and the checklist names the six tests that also fail on a clean main on this machine. The test that cuts CreateThread now stubs the new helper.

Description filled in: the still-to-test line says who runs it, Measurements states why there is nothing to measure, and the checklist names the six tests that also fail on a clean main on this machine. The test that cuts CreateThread now stubs the new helper.
Author
Member

One CI job is red: 'Third-party parts and guide screenshots' (fails after 10 s, before the compile jobs). Its first step is python3 -I scripts/check_third_party.py, which passes on this branch and on a clean main checkout here ('third_party: 17 parts as their notes say'), and this PR touches nothing under third_party/. Reporting it as an environment failure rather than a change failure; if it stays red on other PRs it needs its own look.

One CI job is red: 'Third-party parts and guide screenshots' (fails after 10 s, before the compile jobs). Its first step is `python3 -I scripts/check_third_party.py`, which passes on this branch and on a clean main checkout here ('third_party: 17 parts as their notes say'), and this PR touches nothing under `third_party/`. Reporting it as an environment failure rather than a change failure; if it stays red on other PRs it needs its own look.
omgitsgela changed title from WIP: fix(host): start a thread whose stack is under the static TLS block to fix(host): start a thread whose stack is under the static TLS block 2026-12-01 20:34:38 +00:00
BeanBot left a comment

Recommendation: Approve. The reported Steam Deck run shows that the A/B thread starts again. The new test has synchronization and compiler-selection problems, and CI and the stated different-compiler check are still pending. Nothing blocking is left. Recommend approval; not approved on the forge.

Linux grows an explicitly requested thread stack to accommodate the executable’s static TLS, restoring the A/B thread on the tested Deck. The calculation does not include static TLS from other startup modules, and the new test needs more reliable synchronization.

Should fix (3): not blocking, but worth doing before merging.

  • L1 host/posix/win32_posix.c:300: The floor counts only the executable’s TLS, although glibc also places startup libraries’ static TLS in each thread’s stack. (more on the line) Do: Account conservatively for the process’s complete static TLS allocation, or use a sufficiently safe stack size for small requests; add a fixture with a startup library carrying substantial TLS.
  • L2 tests/test_create_thread_small_stack.py:67: The fixture uses volatile variables for communication between threads, which does not synchronize C memory accesses. (more on the line) Do: Publish completion with a release atomic store and wait with an acquire load, or synchronize and join the worker before inspecting its result.
  • L3 tests/test_create_thread_small_stack.py:17: The test hard-codes cc, bypassing the runner’s CC selection. (more on the line) Do: Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too.

@fix can do L1, L2 and L3.

Checks: Failing on this head, which is behind its base, where they pass: CI / Third-party parts and guide screenshots (pull_request), CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request). @rebase (or @fix) brings it up to date and runs them again; not held against it. Still running: 7 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes: the author reports that the A/B thread failed to start on main and produced 16 flips on each side with this change on a Steam Deck. This is a functional fix, not a performance claim.

Other systems: Windows uses a different host implementation. Linux CreateThread calls with explicit sizes use the new floor; default-size threads retain their existing size. Startup libraries with large static TLS can still exhaust the calculated floor.

Switches: None.

Reviewed: dd62e0eff5 against 4908cc6dad: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, all three changed files and their diff, commit messages, the A/B caller, related source-cut tests, and relevant test-runner and loader code. Skimmed the remainder of win32_posix.c and the test runner. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).

Checked and fine:

  • pthread_once protects publication of the cached executable TLS size.
  • Both commits have AI-assistance trailers; no generated files, game files, switches, or renderer API versions are changed.
  • The reported in-game run exercises the affected A/B path on Steam Deck.

Testing: Read-only review; no code or tests were run. The author reports the new test passing and the Deck A/B run succeeding. Several CI jobs remain running, and the PR lists a different-compiler check as still to test.

Overlaps and merge order: Not checked; network access was unavailable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as omgitsgela took it out of WIP. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The reported Steam Deck run shows that the A/B thread starts again. The new test has synchronization and compiler-selection problems, and CI and the stated different-compiler check are still pending. Nothing blocking is left. Recommend approval; not approved on the forge. Linux grows an explicitly requested thread stack to accommodate the executable’s static TLS, restoring the A/B thread on the tested Deck. The calculation does not include static TLS from other startup modules, and the new test needs more reliable synchronization. **Should fix (3)**: not blocking, but worth doing before merging. - **L1** `host/posix/win32_posix.c:300`: The floor counts only the executable’s TLS, although glibc also places startup libraries’ static TLS in each thread’s stack. (more on the line) **Do:** Account conservatively for the process’s complete static TLS allocation, or use a sufficiently safe stack size for small requests; add a fixture with a startup library carrying substantial TLS. - **L2** `tests/test_create_thread_small_stack.py:67`: The fixture uses volatile variables for communication between threads, which does not synchronize C memory accesses. (more on the line) **Do:** Publish completion with a release atomic store and wait with an acquire load, or synchronize and join the worker before inspecting its result. - **L3** `tests/test_create_thread_small_stack.py:17`: The test hard-codes cc, bypassing the runner’s CC selection. (more on the line) **Do:** Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too. `@fix` can do L1, L2 and L3. **Checks:** Failing on this head, which is behind its base, where they pass: `CI / Third-party parts and guide screenshots (pull_request)`, `CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs them again; not held against it. Still running: 7 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes: the author reports that the A/B thread failed to start on main and produced 16 flips on each side with this change on a Steam Deck. This is a functional fix, not a performance claim. **Other systems:** Windows uses a different host implementation. Linux CreateThread calls with explicit sizes use the new floor; default-size threads retain their existing size. Startup libraries with large static TLS can still exhaust the calculated floor. **Switches:** None. **Reviewed:** dd62e0eff560 against 4908cc6dadff: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, all three changed files and their diff, commit messages, the A/B caller, related source-cut tests, and relevant test-runner and loader code. Skimmed the remainder of win32_posix.c and the test runner. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review). **Checked and fine:** - pthread_once protects publication of the cached executable TLS size. - Both commits have AI-assistance trailers; no generated files, game files, switches, or renderer API versions are changed. - The reported in-game run exercises the affected A/B path on Steam Deck. **Testing:** Read-only review; no code or tests were run. The author reports the new test passing and the Deck A/B run succeeding. Several CI jobs remain running, and the PR lists a different-compiler check as still to test. **Overlaps and merge order:** Not checked; network access was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as omgitsgela took it out of WIP. Nothing was run; a maintainer decides.</sub>
@ -293,0 +297,4 @@
glibc that takes it, leaves a few KiB of usable stack. Read from the phdrs rather than guessed, once. */
static int tls_of_main(struct dl_phdr_info *info, size_t size, void *data) {
(void)size;
if (info->dlpi_name && info->dlpi_name[0]) return 0; /* (a library's, not the executable's) */
Member

L1 (should fix): The floor counts only the executable’s TLS, although glibc also places startup libraries’ static TLS in each thread’s stack.

When: If a Linux process starts with a preloaded library containing a sufficiently large static TLS block, the 64 KiB A/B request is grown using only the executable’s block. The combined TLS can still exceed that stack, so pthread_create fails and A/B remains disabled.

Do: Account conservatively for the process’s complete static TLS allocation, or use a sufficiently safe stack size for small requests; add a fixture with a startup library carrying substantial TLS.

**L1** (should fix): The floor counts only the executable’s TLS, although glibc also places startup libraries’ static TLS in each thread’s stack. *When:* If a Linux process starts with a preloaded library containing a sufficiently large static TLS block, the 64 KiB A/B request is grown using only the executable’s block. The combined TLS can still exceed that stack, so pthread_create fails and A/B remains disabled. **Do:** Account conservatively for the process’s complete static TLS allocation, or use a sufficiently safe stack size for small requests; add a fixture with a startup library carrying substantial TLS.
@ -0,0 +14,4 @@
import sys
import tempfile
RUN_ALL_ARGS = ["--cc", "cc"]
Member

L3 (should fix): The test hard-codes cc, bypassing the runner’s CC selection.

When: With CC set to clang, the suite still invokes cc for this test; on a system with the selected compiler but no cc alias, the check is skipped or fails even though a compiler is available.

Do: Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too.

**L3** (should fix): The test hard-codes cc, bypassing the runner’s CC selection. *When:* With CC set to clang, the suite still invokes cc for this test; on a system with the selected compiler but no cc alias, the check is skipped or fails even though a compiler is available. **Do:** Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too.
@ -0,0 +64,4 @@
}
"""
cases = r"""
static volatile int body_ran;
Member

L2 (should fix): The fixture uses volatile variables for communication between threads, which does not synchronize C memory accesses.

When: The worker writes body_ran and seen_stack while the main thread reads them without a happens-before relationship. The test has undefined behavior and can miss completion or read a stale stack size under optimization.

Do: Publish completion with a release atomic store and wait with an acquire load, or synchronize and join the worker before inspecting its result.

**L2** (should fix): The fixture uses volatile variables for communication between threads, which does not synchronize C memory accesses. *When:* The worker writes body_ran and seen_stack while the main thread reads them without a happens-before relationship. The test has undefined behavior and can miss completion or read a stale stack size under optimization. **Do:** Publish completion with a release atomic store and wait with an acquire load, or synchronize and join the worker before inspecting its result.
fix(host): check the stack size it chooses, and retry past a library's static TLS
Some checks failed
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Successful in 6s
CI / Third-party parts and guide screenshots (pull_request) Failing after 9s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 23s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m1s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Successful in 3m49s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
a0c4bc5be4
Review of the first cut: the executable's PT_TLS alone is not glibc's whole reservation (a startup
library brings its own block), the rounding could wrap for a near-SIZE_MAX request, and pthread_attr_-
setstacksize's answer was ignored. So the choice moves into stack_want (0 for a size that cannot exist,
8 MB for none, the request when it is above the block plus 64 KiB, that floor otherwise), and a refused
creation (EINVAL) is retried larger up to 64 MB, which covers blocks the phdrs cannot see.

The test now asserts stack_want's arithmetic directly, so a glibc that refuses the small stack cannot
hide a missing floor behind the retry, and it checks what each thread actually got (8 MB for none, 64 MB
and 1 MB unchanged, and a size that cannot exist refused). The body communicates through C11 atomics
instead of volatile, the TLS block is escaped to a volatile sink as well as written, and the wait no
longer spins on a fixed yield count.

Assisted-by: Hermes Agent (DeepSeek)
test(host): drop the fixture's now-unused static TLS stub
Some checks failed
CI / What the change needs (pull_request) Successful in 7s
CI / Third-party parts and guide screenshots (pull_request) Failing after 11s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 19s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m5s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Successful in 4m2s
CI / Website build and checks (pull_request) Failing after 33s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 7m18s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 6m33s
PR description / Title and description (pull_request_target) Successful in 6s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 26m33s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 40m21s
4de0ebbdf0
The out-of-memory fixture stubs stack_want, so nothing in it calls static_tls_size any more, and
-Werror=unused-function refuses it.

Assisted-by: Hermes Agent (DeepSeek)
Author
Member

Review answered, head 4de0ebbd. The executable's PT_TLS is not glibc's whole reservation, so the chosen size is now stack_want (0 for an impossible size, 8 MB for none, the request above the block plus 64 KiB, that floor otherwise) and a refused creation is retried larger, up to 64 MB. Rounding and the floor addition are overflow-checked, pthread_attr_setstacksize's answer is no longer ignored, and an unrepresentable request is refused instead of rounded into a small thread. The test asserts stack_want's arithmetic directly (a glibc that refuses the small stack would otherwise hide a missing floor behind the retry), reads back what each thread got, uses C11 atomics instead of volatile, escapes the TLS block as well as writing it, and no longer spins on a fixed yield count. The fixture that cuts CreateThread stubs the two helpers; the changed subset is 22 passed, 6 failed, the six being the ones that also fail on clean main here.

Review answered, head 4de0ebbd. The executable's PT_TLS is not glibc's whole reservation, so the chosen size is now stack_want (0 for an impossible size, 8 MB for none, the request above the block plus 64 KiB, that floor otherwise) and a refused creation is retried larger, up to 64 MB. Rounding and the floor addition are overflow-checked, pthread_attr_setstacksize's answer is no longer ignored, and an unrepresentable request is refused instead of rounded into a small thread. The test asserts stack_want's arithmetic directly (a glibc that refuses the small stack would otherwise hide a missing floor behind the retry), reads back what each thread got, uses C11 atomics instead of volatile, escapes the TLS block as well as writing it, and no longer spins on a fixed yield count. The fixture that cuts CreateThread stubs the two helpers; the changed subset is 22 passed, 6 failed, the six being the ones that also fail on clean main here.
Author
Member

Second red job on head 4de0ebbd: 'Website build and checks', failing after 33 s, also in its setup steps (main's tree restored from the cache, then checkout) rather than in the site build. Both red jobs fail before they reach anything this PR touches, and the third-party script passes locally on this branch and on clean main.

Second red job on head 4de0ebbd: 'Website build and checks', failing after 33 s, also in its setup steps (main's tree restored from the cache, then checkout) rather than in the site build. Both red jobs fail before they reach anything this PR touches, and the third-party script passes locally on this branch and on clean main.
Member
@review
BeanBot left a comment

Recommendation: Approve. The reported A/B thread now starts on the Steam Deck, and the remaining ledger items are minor. Startup-library TLS can still reduce the usable stack, and the test runner still bypasses its selected C compiler. Recommend approval; not approved on the forge.

The POSIX thread shim grows small explicit stack requests and retries creation when glibc rejects the size. This restores the A/B tool on the reported system at the cost of larger stack reservations.

Should fix (2): not blocking, but worth doing before merging.

  • L1 host/posix/win32_posix.c:300: The retry accounts for library TLS only when thread creation fails; a successful creation can still leave less usable stack than the floor intends. When: If startup libraries consume much of the space above the executable's TLS but glibc still accepts the chosen size, the thread starts without retrying and has less than 64 KiB of remaining stack. Do: Account for the complete static TLS reservation when choosing the floor, including startup libraries, and cover the accepted-but-small case.
  • L3 tests/test_create_thread_small_stack.py:17: The test hard-codes cc, bypassing the runner’s CC selection. When: With CC set to clang, the suite still invokes cc for this test; on a system with the selected compiler but no cc alias, the check is skipped or fails even though a compiler is available. Do: Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too.

@fix can do L1 and L3.

Since the last review (on dd62e0eff5)
Resolved: L2 (The fixture uses volatile variables for communication between threads, which does not sync…)
Still open: L1 (The retry accounts for library TLS only when thread creation fails; a successful creation…); L3 (The test hard-codes cc, bypassing the runner’s CC selection.)

Checks: Failing on this head, which is behind its base, where they pass: CI / Third-party parts and guide screenshots (pull_request), CI / Website build and checks (pull_request), CI / Game-free checks (run_all.py, part 1/2) (pull_request), CI / Game-free checks (run_all.py, part 2/2) (pull_request). @rebase (or @fix) brings it up to date and runs them again; not held against it.

More: does it help, other systems, switches, what was read

Does it help: Yes. The author reports that the A/B thread failed to start on main but alternated 16 times per side on the Steam Deck with this change; the resulting trace contained 31 periods. This is a functional fix, not a performance claim.

Other systems: The POSIX shim is also built into the Linux Vulkan backend, so its explicit thread requests can be affected. Windows uses a separate implementation; default-size requests and the tested 64 MiB request retain their sizes. No separate Linux compiler run is reported.

Switches: None added, changed or removed.

Reviewed: 4de0ebbdf0 against 4908cc6dad: Read the PR diff, changed test and fixture, thread creation code, A/B caller, runner compiler selection, repository rules, PR template, comments and CI summary. The full POSIX source output was truncated; unrelated portions were skimmed. The referenced review checklist was absent.; nothing run (a code review).

Checked and fine:

  • Overflowing explicit stack requests are rejected before thread creation.
  • The default stack request is not retried or resized.
  • The reported game run demonstrates the original A/B failure and its restoration.

Testing: No commands that build or run code were executed. The author reports the new game-free test passing, a successful Steam Deck game run, and six changed-suite failures also seen on main. The listed CI failures are attributed to the branch being behind its base.

Overlaps and merge order: Not established from the supplied information.


Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The reported A/B thread now starts on the Steam Deck, and the remaining ledger items are minor. Startup-library TLS can still reduce the usable stack, and the test runner still bypasses its selected C compiler. Recommend approval; not approved on the forge. The POSIX thread shim grows small explicit stack requests and retries creation when glibc rejects the size. This restores the A/B tool on the reported system at the cost of larger stack reservations. **Should fix (2)**: not blocking, but worth doing before merging. - **L1** `host/posix/win32_posix.c:300`: The retry accounts for library TLS only when thread creation fails; a successful creation can still leave less usable stack than the floor intends. *When:* If startup libraries consume much of the space above the executable's TLS but glibc still accepts the chosen size, the thread starts without retrying and has less than 64 KiB of remaining stack. **Do:** Account for the complete static TLS reservation when choosing the floor, including startup libraries, and cover the accepted-but-small case. - **L3** `tests/test_create_thread_small_stack.py:17`: The test hard-codes cc, bypassing the runner’s CC selection. *When:* With CC set to clang, the suite still invokes cc for this test; on a system with the selected compiler but no cc alias, the check is skipped or fails even though a compiler is available. **Do:** Use the runner’s {cc} placeholder and support its compiler command, including any configured arguments, for direct invocation too. `@fix` can do L1 and L3. **Since the last review** (on dd62e0eff560) Resolved: L2 (The fixture uses volatile variables for communication between threads, which does not sync…) Still open: L1 (The retry accounts for library TLS only when thread creation fails; a successful creation…); L3 (The test hard-codes cc, bypassing the runner’s CC selection.) **Checks:** Failing on this head, which is behind its base, where they pass: `CI / Third-party parts and guide screenshots (pull_request)`, `CI / Website build and checks (pull_request)`, `CI / Game-free checks (run_all.py, part 1/2) (pull_request)`, `CI / Game-free checks (run_all.py, part 2/2) (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs them again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes. The author reports that the A/B thread failed to start on main but alternated 16 times per side on the Steam Deck with this change; the resulting trace contained 31 periods. This is a functional fix, not a performance claim. **Other systems:** The POSIX shim is also built into the Linux Vulkan backend, so its explicit thread requests can be affected. Windows uses a separate implementation; default-size requests and the tested 64 MiB request retain their sizes. No separate Linux compiler run is reported. **Switches:** None added, changed or removed. **Reviewed:** 4de0ebbdf011 against 4908cc6dadff: Read the PR diff, changed test and fixture, thread creation code, A/B caller, runner compiler selection, repository rules, PR template, comments and CI summary. The full POSIX source output was truncated; unrelated portions were skimmed. The referenced review checklist was absent.; nothing run (a code review). **Checked and fine:** - Overflowing explicit stack requests are rejected before thread creation. - The default stack request is not retried or resized. - The reported game run demonstrates the original A/B failure and its restoration. **Testing:** No commands that build or run code were executed. The author reports the new game-free test passing, a successful Steam Deck game run, and six changed-suite failures also seen on main. The listed CI failures are attributed to the branch being behind its base. **Overlaps and merge order:** Not established from the supplied information. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/ab-thread-stack 2026-12-02 14:59:28 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2971
No description provided.