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

Add internal RUSTC_INTERNAL_FORCE_PANIC_ABORT env var for libpanic_abort #66311

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ fn main() {
// other crate intentionally as this is the only crate for now that we
// ship with panic=abort.
//
// FIXME: Remove the special case for "panic_abort"
// once https://github.com/rust-lang/rust/pull/60026
// rides the release train into the bootstrap compiler.
Aaron1011 marked this conversation as resolved.
Show resolved Hide resolved
// `cfg(bootstrap)`: (added to make this easier to grep for)
//
// This... is a bit of a hack how we detect this. Ideally this
// information should be encoded in the crate I guess? Would likely
// require an RFC amendment to RFC 1513, however.
Expand Down
7 changes: 7 additions & 0 deletions src/libpanic_abort/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
// Hack to force this crate to be compiled with the `abort`
// panic strategy, regardless of what strategy Cargo
// passes to the compiler.
// See `rustc::session::Session::panic_strategy` for more details
println!("cargo:rustc-env=RUSTC_INTERNAL_FORCE_PANIC_ABORT=1");
}
12 changes: 12 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,18 @@ impl Session {
/// Returns the panic strategy for this compile session. If the user explicitly selected one
/// using '-C panic', use that, otherwise use the panic strategy defined by the target.
pub fn panic_strategy(&self) -> PanicStrategy {
// This is a hack to support `libpanic_abort`. We require `libpanic_abort`
// to always be built with `PanicStrategy::Abort`, regardless of what panic
// strategy is suppplied to the compiler. Ideally, this would be an intenral
// attribute in `libpanic_abort` - howevver, emscripten needs to access
// the panic strategy before we even start parsing the crate:
// https://github.com/rust-lang/rust/blob/3fc30d8/src/librustc_codegen_llvm/llvm_util.rs#L77
//
// As a result, we need to use a special environment variable, which is set from
// the `build.rs` of `libpanic_abort`
if env::var("RUSTC_INTERNAL_FORCE_PANIC_ABORT").is_ok() {
return PanicStrategy::Abort;
}
self.opts
.cg
.panic
Expand Down