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

fatal runtime error: failed to initiate panic, error 5 #304

Open
rcitsz opened this issue Jan 9, 2025 · 4 comments
Open

fatal runtime error: failed to initiate panic, error 5 #304

rcitsz opened this issue Jan 9, 2025 · 4 comments

Comments

@rcitsz
Copy link

rcitsz commented Jan 9, 2025

The following command successfully compiles the result:

RUSTFLAGS='-C target-feature=+crt-static' cargo zigbuild --release --target aarch64-apple-darwin

However, at runtime, a panic in the program causes the process to exit. error: fatal runtime error: failed to initiate panic, error 5

If I compile directly on macOS without using zigbuild, it runs normally and a panic does not cause the process to exit:

RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target aarch64-apple-darwin

Why does the same code exhibit different panic behavior when compiled with cargo build versus cargo zigbuild?

The same issue occurs with x86_64-apple-darwin, where a panic causes the process to terminate:

RUSTFLAGS='-C target-feature=+crt-static' cargo zigbuild --release --target x86_64-apple-darwin

However, x86_64-pc-windows-gnu does not have this problem.

Thanks!

@messense
Copy link
Member

messense commented Jan 9, 2025

No idea, why use static crt? It’s not common to do that on macOS.

@rcitsz
Copy link
Author

rcitsz commented Jan 9, 2025

No idea, why use static crt? It’s not common to do that on macOS.

Whether it is dynamic linking or static linking, debug or release, I tried the following compilation commands and encountered the same issue: fatal runtime error: failed to initiate panic, error 5

cargo zigbuild --release --target aarch64-apple-darwin
cargo zigbuild --target aarch64-apple-darwin
cargo zigbuild --release --target x86_64-apple-darwin
cargo zigbuild --target x86_64-apple-darwin

@messense
Copy link
Member

messense commented Jan 9, 2025

Nothing I can do here unless you can provide a minimal reproducible example.

@rcitsz
Copy link
Author

rcitsz commented Jan 9, 2025

Nothing I can do here unless you can provide a minimal reproducible example.

fn main() {
    std::thread::spawn(|| {
        std::thread::sleep(std::time::Duration::from_secs(1));
        panic!("panic xxx");
    });

    loop {
        std::thread::sleep(std::time::Duration::from_secs(1));
        println!("continue...");
    }
}

compile using the docker image ghcr.io/rust-cross/cargo-zigbuild:latest:
cargo zigbuild --release --target aarch64-apple-darwin

And then run the bin on my MacBook M1 Pro.
Host info is:
Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64

But the Process terminated beacuse the panic. error: fatal runtime error: failed to initiate panic, error 5

If I compile directly on macOS without using zigbuild, it runs normally and a panic does not cause the process to exit:
cargo build --release --target aarch64-apple-darwin

I need your help, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants