cargo-zigbuild icon indicating copy to clipboard operation
cargo-zigbuild copied to clipboard

fatal runtime error: failed to initiate panic, error 5

Open rcitsz opened this issue 1 year ago • 4 comments

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!

rcitsz avatar Jan 09 '25 04:01 rcitsz

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

messense avatar Jan 09 '25 04:01 messense

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

rcitsz avatar Jan 09 '25 08:01 rcitsz

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

messense avatar Jan 09 '25 08:01 messense

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!

rcitsz avatar Jan 09 '25 23:01 rcitsz