Repository navigation
Conversation
Debug builds of openlogi-desktop and openlogi-overlay died with STATUS_STACK_OVERFLOW on Windows before showing anything. Under cdb both overflow in the same frame: `_RUST_I18N_BACKEND::closure$0`, the initializer `rust_i18n::i18n!` generates, whose prologue asks `__chkstk` for 0x1352C0 bytes (1.21 MiB) on the 1 MiB stack Windows gives the main thread. Unoptimized, the closure keeps every entry of all 24 catalogs on the stack until the HashMap takes it; release inlines the closure and has no such frame. The macro's `backend =` argument only extends the generated backend, so the literal cannot be avoided from this side. Each build script now passes the linker a 2 MiB stack reserve for its own binary, in the debug profile on Windows only. 2 MiB is what std gives a spawned thread, which is why the agent, translating from the tray's own thread, and the test harnesses never hit this. The value lives in the build scripts because CI's RUSTFLAGS would override `.cargo/config.toml`.
[Medium impact] This PR appears safe to merge. SummaryGives Windows debug builds of
Reviews (1) · Last reviewed commit: "fix(gui,overlay): give Windows debug bui..." · Reviewed by Greptile |
|
Tested on Windows 11 (MSVC), this commit merged onto One thing to consider: the frame has grown with the catalogs, from With 200 extra keys the overlay and desktop tests overflow as well, since test threads get 2 MiB. I only measured that on Windows, but it means CI could hit this independently of this PR. Edit: I missed that |
Summary
Debug builds of
openlogi-desktopandopenlogi-overlaydie withSTATUS_STACK_OVERFLOWon Windows before they show anything. The frame that overflows is the initializerrust_i18n::i18n!generates, and only an unoptimized build has it. This gives those two binaries, in the debug profile only, the 2 MiB main-thread stack Rust already gives every other thread. Release binaries are untouched.Split out of #1904 as asked there, with the frame named.
The frame
Under
cdbon a 1 MiB stack, both binaries overflow at the same place:The prologue of
_RUST_I18N_BACKEND::closure$0isin both the desktop and the overlay debug binaries. The rest of the stack at that point is about 26 KiB, so no other frame matters: this one asks for 1.21 MiB on a 1 MiB thread.
rust-i18n-macro4.2.1 (generate_code) expands every catalog underopenlogi-ui/localesinto oneHashMapliteral each, inside theLazyLockclosure. Unoptimized, everyCowpair of all 24 catalogs sits in the closure's frame untiladd_translationstakes it. The release build inlines the closure and has no such frame:dumpbinof the release binaries shows neither the symbol nor a large__chkstkrequest.The macro offers no way around this: its
backend =argument only extends the generated backend, the literal is emitted regardless.Why only these two binaries
openlogi-agentalso expandsi18n!but translates only from the tray's own win32 thread, which Rust gives 2 MiB. It never hit this.cargo test -p openlogi-overlay the_shared_catalog_is_wired_uppasses as is and overflows withRUST_MIN_STACK=1048576, which is the same frame; CI never saw the problem because CI never runs the binaries.Changes
crates/openlogi-desktop/build.rs,crates/openlogi-overlay/build.rs:reserve_debug_main_stack, which emitscargo:rustc-link-arg-bin=<binary>=/STACK:2097152(--stackfor GNU) whenCARGO_CFG_TARGET_OSiswindowsandPROFILEisdebug. It is a linker argument in the build script rather thanrustflagsin.cargo/config.tomlbecause CI'sRUSTFLAGSwould override the latter.2 MiB is the smallest round size that fits: the frame is 1.21 MiB plus a few KiB of callers. It is also what
stdreserves for a spawned thread, so it is not a new number in the project.Testing
cargo build -p openlogi-desktop -p openlogi-overlay # debug cargo build -p openlogi-desktop -p openlogi-overlay --release cargo clippy -p openlogi-desktop -p openlogi-overlay --all-targets -- -D warningsOn Windows 11, MSVC, stable 1.99:
dumpbin /headerson the debug binaries:200000 size of stack reserve(2 MiB); on the release binaries:100000(1 MiB, unchanged).Not run on macOS or Linux; the function returns early there, so the build scripts are unchanged for those targets.