Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug build on M1 CPU: large arrays on stack fail with fatal runtime error: stack overflow #89908

Closed
smoothdeveloper opened this issue Oct 15, 2021 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@smoothdeveloper
Copy link

I tried this code:

    #[test]
    pub fn notpass() {
        let t = [0f32;526398];
        for i in 1 .. 20 {
            println!("{}", t[i]);
        }
    }

It crashes with

thread 'checkptrcast::tests::notpass' has overflowed its stack
fatal runtime error: stack overflow

when testing without the --release flag.

I'm running on Mac M1 and not tried yet on x64 architecture.

I'm looking to allocate much larger multidimensional array in the actual code and not sure how to proceed to make it work in debug builds.

Not sure if this is related: #40862 and if something could be done to help users troubleshooting this if the limitation in the compiler can't be fixed; maybe it could warn that the stack size is going to blow on the target arch?

warning: a stack allocated array of size X is defined here but it may panic at runtime on the Y target architecture.

or maybe not even compile and provide the user with approaches to replace usage of stack allocated array.

@smoothdeveloper smoothdeveloper added the C-bug Category: This is a bug. label Oct 15, 2021
@smoothdeveloper
Copy link
Author

Context: I was trying to convert C++ code which deals with a pointer to a class instance member being such large array, although in that code, the array isn't allocated on the stack (class is "newed").

I've been pointed at bytemuck and cast_vec for working around the issue I'm dealing with in the code.

Is it worth it/possible for the compiler to emit a warning?

@shepmaster shepmaster added O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-macos Operating system: macOS labels Oct 15, 2021
@hkratz
Copy link
Contributor

hkratz commented Nov 10, 2021

@smoothdeveloper You are explicitly creating the array on the stack. The testing framework creates threads for multi-threaded testing and the default stack size for threads created from within Rust is 2 MiB. So this will predictably fail on all architectures.

@rustbot label -O-ARM -O-macos

@rustbot rustbot removed O-macos Operating system: macOS O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state labels Nov 10, 2021
@Enselic
Copy link
Member

Enselic commented Jul 8, 2024

Triage: Thanks for reporting. No matter what stack size is default, it will always be too small for someone. In this case it should work to make it bigger with RUST_MIN_SIZE. Let's close this.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants