Open prateekmedia opened 1 year ago
See also #4516 and #3524.
Drat, this being only on Windows makes it even worse.
The compiler is doing something very unexpected with stack allocations that we need to dig into and figure out.
This seems only to be a issue in debug mode, in release mode it seems to be fine.
Sharing my insight here as I hit this issue as well. The default stack size on windows is 1MB (8MB elsewhere, usually) so setting it to 8MB manually in the build process fixed this issue. This can be done by adding a build.rs file that sets the stack size on the linker on windows to 8MB.
fn main() {
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or("".to_owned());
if target_env == "msvc" {
println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024);
}
}
However, to debug the issue while working on an osx machine, I found that setting a stack size of 512KB also triggered the issue for me. This can be done using build.rs:
fn main() {
println!("cargo:rustc-link-arg=-Wl,-stack_size,{:#x}", 512 * 1024);
}
With this, running the program through rust-lldb shows the places where the stack overflows, which (I hope) will help track down a fix. For me, it was in the macro generated code, but I suspect a couple judicious uses of Box to move local objects from the stack to the heap could fix this and the related issues.
Please complete the following tasks
Rust Version
rustc 1.72.0 (5680fa18f 2023-08-23)
Clap Version
4.4.4
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run
Actual Behaviour
error: process didn't exit successfully:
target\debug\rust_mini.exe
(exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)Expected Behaviour
It should print a nice help dialog
Additional Context
Example repository: https://github.com/prateekmedia/ccerrorrustexample
This only happens in Debug mode. This is a part of parameters for ccextractor and related to CCExtractor/ccextractor#1547 Also these parameters are only almost 3/4 of what I have in that file, so do note that.
Debug Output
thread 'main' has overflowed its stack error: process didn't exit successfully:
target\debug\rust_mini.exe
(exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)