Xudong-Huang / generator-rs

rust stackful generator library
Apache License 2.0
286 stars 35 forks source link

Bus error when running in debug mode with thread_rng() on Apple M1 #47

Open Tassle opened 9 months ago

Tassle commented 9 months ago

When running the following program in debug mode, I get a bus error.

use generator::{Generator, Gn, done};
use rand::{thread_rng, Rng};

fn simple_generator<'a>() -> Generator<'a, (), i32>{
    Gn::new_scoped(move |mut s| {
        let v: i32 = thread_rng().gen();
        s.yield_(v);
        done!();
    })
}

fn main() {
    for v in simple_generator(){
        println!("{}", v);
    }
}

It runs fine in release mode, or when there is no thread_rng involved.

I'm on an M1 Mac, Ventura 13.0.1. Stable Rust (1.72.0).

Xudong-Huang commented 9 months ago

I don't have a M1 Mac env now. It's likely the debug version stack alignment issue. E.g.

https://github.com/Xudong-Huang/generator-rs/blob/ea54d2f38bc1fbdbf6d9d45fee303f3185980e39/src/detail/asm/asm_x86_64_sysv_elf_gas.S#L14-L18

LaoLittle commented 9 months ago

I don't have a M1 Mac env now. It's likely the debug version stack alignment issue. E.g.

https://github.com/Xudong-Huang/generator-rs/blob/ea54d2f38bc1fbdbf6d9d45fee303f3185980e39/src/detail/asm/asm_x86_64_sysv_elf_gas.S#L14-L18

it might be a stack overflow error

Xudong-Huang commented 8 months ago

@Tassle could please test the master in your env again?

LaoLittle commented 2 months ago

@Tassle could please test the master in your env again?

works fine on my Mac.


use generator::{Generator, Gn, done};
use rand::{thread_rng, Rng};

fn simple_generator<'a>() -> Generator<'a, (), i32>{
    Gn::new_scoped(move |mut s| {
        let v: i32 = thread_rng().gen();
        s.yield_(v);
        done!();
    })
}

fn main() {
    assert!(catch_unwind(|| {
        for v in simple_generator(){
            println!("{}", v);
        }
    }).is_err());
}
coroutine in thread 'main' has overflowed its stack

Process finished with exit code 0
sysctl -n machdep.cpu.brand_string
Apple M3 Pro