rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

[need verification on a statement]: panic does segfault (Aborted core dumped) by default cuz its not yet supported #1336

Closed alexzanderr closed 1 year ago

alexzanderr commented 1 year ago

hello

im getting a panic inside my project from the crates that im using.

by running in terminal this happened:

i've saw this in the readme

Unwinding on panics (https://github.com/bytecodealliance/wasmtime/issues/1677, -Cpanic=abort is enabled by default)

and also saw that cleanup is requested as an open issue and its still open so no cleanup right now.

so my guess is that cranelift compiles code with panic=abort by default both in debug and release mode. right?

and when the rust program panics with panic=abort it will create a segfault. right? (this is what i saw in the past when running a release binary with panic=abort)

this is expected to happen right? im assuming, but i need your confirmation.

thanks in advance.

bjorn3 commented 1 year ago

Yes, panics do indeed abort (SIGABRT) due to -Cpanic=abort being the only mode supported by cg_clif. Note that this is not a segfault (SIGSEGV), but a controlled abort() call. Both do indeed write core dumps by default on some distros. Depending on the amount of memory the process used, this can take a while. If you want to disable core dumping, you should be able to run ulimit -c 0 in the terminal from which you run the compiled program. This will only apply to processes spawned from this specific terminal and won't persist once you close it.

alexzanderr commented 1 year ago

wow, very nice guide. thanks a lot.

bjorn3 commented 1 year ago

I believe I answered your question. If not, feel free ask more though.

alexzanderr commented 1 year ago

so i the way i need to run is like this? :

> ulimit -c 0 && cargo run # (panic abort project)

or

> ulimit -c 0
# then after, being a separate command
> cargo run
alexzanderr commented 1 year ago

ok, i can confirm that both ways are achieving the same result.

and indeed, i can confirm that is working (ulimit -c 0), the program is not writing core-dumps anymore into the system, so right now the process closes immediately.

thanks a lot for the response!

bjorn3 commented 1 year ago

The second one definitively works. The first one may or may not work. ulimit is a command built into your shell which changes the "resource limits" of the shell itself, any processes started by the shell then inherit these "resource limits".

alexzanderr commented 1 year ago

yeah. indeed.