Skip to content

Make rustc implicitly use panic=abort for the panic_abort crate #140254

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Apr 24, 2025

The panic_abort crate must be compiled with panic=abort, but cargo doesn't allow setting the panic strategy for a single crate. Bootstrap handles this in its rustc wrapper, but for example the build systems of cg_clif and cg_gcc don't use a rustc wrapper, so they would either need to add one or be unable to build a sysroot suitable for both panic=abort and panic=unwind (as is currently the case).

There is a crate called panic_abort on crates.io that would also be affected by this change. This crate uses unstable features and has last been updated in 2019 however and seems to be meant to be used when you want panic=abort behavior anyway.

Required for rust-lang/rustc_codegen_cranelift#1567

The panic_abort crate must be compiled with panic=abort, but cargo
doesn't allow setting the panic strategy for a single crate. Bootstrap
handles this in its rustc wrapper, but for example the build systems of
cg_clif and cg_gcc don't use a rustc wrapper, so they would either need
to add one or be unable to build a sysroot suitable for both panic=abort
and panic=unwind (as is currently the case).
@rustbot
Copy link
Collaborator

rustbot commented Apr 24, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 24, 2025
@petrochenkov
Copy link
Contributor

It's less of a practical concern, but shouldn't panic_unwind also implicitly use panic=unwind?

I guess the proper solution would be to move fn panic_strategy from sess to tcx so it can use tcx.is_panic_runtime(), and extend the #![panic_runtime] attribute to #![panic_runtime = "abort|unwind"] to avoid relying on the crate name.
What do you think?

@petrochenkov
Copy link
Contributor

Ah, crate loader still searches for panic_(unwind,abort) by crate name, but we can at least sanity check that the crate found that way is indeed #![panic_runtime = "unwind" or "abort"] respectively.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 25, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Apr 25, 2025

It's less of a practical concern, but shouldn't panic_unwind also implicitly use panic=unwind?

If panic=abort was used while compiling the standard library, panic_unwind won't be used anyway as any panic=abort dependency will force panic=abort to be used and thus panic_unwind doesn't get linked in.

I guess the proper solution would be to move fn panic_strategy from sess to tcx so it can use tcx.is_panic_runtime(), and extend the #![panic_runtime] attribute to #![panic_runtime = "abort|unwind"] to avoid relying on the crate name.
What do you think?

The LLVM backend needs to know if the current crate uses panic=unwind or panic=abort before any source code gets parsed:

&& sess.panic_strategy() == PanicStrategy::Unwind

Ah, crate loader still searches for panic_(unwind,abort) by crate name, but we can at least sanity check that the crate found that way is indeed #![panic_runtime = "unwind" or "abort"] respectively.

There already is a sanity check that the found crate is a panic runtime:

if !data.is_panic_runtime() {
self.dcx().emit_err(errors::CrateNotPanicRuntime { crate_name: name });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants