Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2070: stable mechanism to specify the behavior of panic! in no-std applications #44489
Comments
aturon
added
B-RFC-approved
T-libs
labels
Sep 11, 2017
aturon
referenced this issue
Sep 11, 2017
Merged
stable mechanism to specify the behavior of panic! in no-std applications #2070
This comment has been minimized.
This comment has been minimized.
As someone with a working unwinding implementation in a no_std environment (not with a Rust personality function though), I can answer this if someone summarizes the feature for me. I kind of lost track and I don't have time to get into every minor detail at the moment. |
This comment has been minimized.
This comment has been minimized.
Sorry to bring this off topic so soon, but could you explain this? I was under the impression that unless you wanted to implement unwinding in an ad-hoc way (e.g. doing unwinding during panic by explicitly calling some function) you had to implement the |
This comment has been minimized.
This comment has been minimized.
I use unwinding in a language runtime. The language has exceptions (and so unwinding), however Rust frames are never unwound, and so there's no need for the personality function. |
TimNN
added
the
C-tracking-issue
label
Sep 17, 2017
This comment has been minimized.
This comment has been minimized.
|
I would like the |
This comment has been minimized.
This comment has been minimized.
|
We should also support no location information at all, and abstract location information (for example just an identifying number which can be used to find the relevant information in some external source). |
This comment has been minimized.
This comment has been minimized.
|
I did not notice that |
This comment has been minimized.
This comment has been minimized.
|
I'm really not a fan of using the same API for payloads and messages. I'd rather |
This comment has been minimized.
This comment has been minimized.
|
I kind of prefer a One problem with mixing the payload and the message is that we can't strip panic messages from the binary without changing the meaning of programs relying on payloads. |
SimonSapin
referenced this issue
Jan 23, 2018
Merged
RFC 2070 part 1: PanicInfo and Location API changes #47687
This comment has been minimized.
This comment has been minimized.
|
#47687 does part of the implementation. I think after that what’s needed is:
Note however that CC @japaric |
This comment has been minimized.
This comment has been minimized.
|
@Zoxc We can still propose changing RFC 2070, but a
|
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin We could just pass a |
bors
added a commit
that referenced
this issue
Feb 16, 2018
bors
added a commit
that referenced
this issue
Feb 18, 2018
This comment has been minimized.
This comment has been minimized.
|
From what I can tell, the RFC still does not address removal of unnecessary panic information directly, however it is an extremely easy thing to do that does not require much extra design past what was already accepted. Consider for example this scenario: #[panic_implementation]
fn my_panic_impl(pi: &PanicInfo) -> ! {
abort()
}This is a case, where it is entirely within the power of compiler to not keep any strings, line numbers, etc. pertaining to panic locations. However as soon as the panic implementation uses any information: #[panic_implementation]
fn my_panic_impl(pi: &PanicInfo) -> ! {
abort_with_line(pi.location(),map(|l| l.line()));
}the compiler is forced to keep all the panic information, despite the fact that only the line numbers are of any interest for that particular implementation of panicking. I want to propose a following change (benefits of which are laid out at the end of this comment): struct AnyConcreteTypeMayGoHere { line: Option<u64> }
impl ::core::panic::PanicInfoCtr for AnyConcreteTypeMayGoHere {
const fn new_v1(message: Option<&fmt::Arguments>, location: Option<Location>, ...etc) -> Self {
AnyConcreteTypeMayGoHere { line: location.map(|l| l.line()) }
}
}
#[panic_implementation]
fn my_panic_impl(pi: &AnyConcreteTypeMayGoHere) -> ! { abort_with_line(pi.line) }and at the location of panic rust would generate code similar to this (with static PANIC_INFO: _ = <_ as ::core::panic::PanicInfoCtr>::new_v1(args, loc, ...);
my_panic_impl(&PANIC_INFO);Benefits of this approach are:
¹: there were a few issues about this, but I can’t find them anymore. |
This was referenced Feb 21, 2018
nagisa
referenced this issue
Mar 5, 2018
Closed
Expose `core::intrinsics::abort` as `std::process::abort` #1363
This comment has been minimized.
This comment has been minimized.
|
Status update: I realised above cannot work without being very unwieldy. Namely, the proposal above would require the |
This comment has been minimized.
This comment has been minimized.
|
There is an issue that IMHO, a stable mechanism for panic! in no-std applications should take into account: for at least two reasons, you can only set the panic handler in leaf crates. One of them is issue #48661, where the linker simply removes the panic handler if it's in its own crate. The second of them is that the
and there is no way for such a crate to be built differently for |
glandium
referenced this issue
Mar 15, 2018
Closed
It's impossible to write a panic crate for no_std #48661
This comment has been minimized.
This comment has been minimized.
This may be a problem short term but custom test framework will become available this year and with those it will be possible to write test runners than don't rely on unwinding (e.g. unit tests return Err to indicate failure) which will make it possible to test targets (e.g. thumbv7m-none-eabi) that don't have a panic implementation that unwinds.
This is probably a bad idea but would it be possible to store all panic!s in MIR format and defer the actual generation of the static variable (and the llvm-ir) until the user defined PanicInfo struct is known? |
This comment has been minimized.
This comment has been minimized.
|
Yeah, without overthinking the idea too much, I think that would be possible, however it has a hard prerequisite on MIR-only (r)libs. |
This comment has been minimized.
This comment has been minimized.
|
@japaric: there are other reasons than unwinding to want to use std for tests on otherwise no_std crates. If your panic function is in a crate that contains nothing else, maybe a |
This comment has been minimized.
This comment has been minimized.
|
A summary from the All Hands /wrt panic size problem. We did discuss various approaches to handling the issue of panic size, and figured out that we’d love to have something that works in all scenarios such as non-lto builds and even debug builds. We didn’t arrive at any particular design, but we managed to reject a number of designs that wouldn’t work and also realised that the only real way to properly implement any design would rely on MIR-only rlibs. With that in mind, this design seems to be as good as any other and, as long as we stabilise I’m willing to mentor implementation of the RFC. The instructions written down by @SimonSapin are part-way right; I’ll write up some new and more detailed instructions over the week or two. |
guanqun
referenced this issue
Aug 29, 2018
Merged
rename to panic_handler as panic_implementation is deprecated in nightly #626
niklasad1
referenced this issue
Sep 2, 2018
Merged
no_std `panic_implementation` -> `panic_handler` #57
This comment has been minimized.
This comment has been minimized.
|
Can @rust-lang/lang assign someone or update us on the current state here? Was this intended to be stabilized in RC? If so we need a stabilization PR ASAP. |
PG-MANA
added a commit
to PG-MANA/Methylenix
that referenced
this issue
Sep 7, 2018
This comment has been minimized.
This comment has been minimized.
Yes, it would be ideal to have this in RC1 (1.30-beta). If it doesn't make the beta cutoff, could we backport it?
Updating / finishing them up right now. |
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Sep 7, 2018
rfcbot
added
the
finished-final-comment-period
label
Sep 7, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Sep 7, 2018
|
The final comment period, with a disposition to merge, as per the review above, is now complete. |
rfcbot
removed
the
final-comment-period
label
Sep 7, 2018
bors
added a commit
that referenced
this issue
Sep 8, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Sep 8, 2018
bors
added a commit
that referenced
this issue
Sep 8, 2018
bors
closed this
in
#51366
Sep 8, 2018
josephlr
added a commit
to josephlr/bootloader
that referenced
this issue
Sep 11, 2018
jaypatelani
referenced this issue
Sep 20, 2018
Open
Comments for "https://os.phil-opp.com/freestanding-rust-binary/" #386
TuringDisciple
referenced this issue
Sep 23, 2018
Closed
Rename panic_implementation attribute to panic_handler #465
phil-opp
added a commit
to rust-osdev/bootloader
that referenced
this issue
Sep 30, 2018
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Oct 19, 2018
|
@Centril: Can you please update the OP with the current status (stabilization etc.)? |
sanmai-NL
referenced this issue
Oct 19, 2018
Closed
Should the usage of {Option, Result}::expect be avoided to safe memory? #42
This comment has been minimized.
This comment has been minimized.
|
@sanmai-NL I will defer this to @japaric since they are most up to date as to the status. |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Oct 19, 2018
•
|
@Centril: I saw at the end of this thread a very clear status indication, so I considered it a management thing requiring no involvement in the effort. |
This comment has been minimized.
This comment has been minimized.
|
@sanmai-NL ok, I ticked some boxes which seemed fulfilled; but I don't have the time to do a more in-depth review right now. :) |
rybot666
added a commit
to NuclearOS/NuclearOS
that referenced
this issue
Nov 19, 2018
kryo4096
pushed a commit
to kryo4096/RostOS
that referenced
this issue
Dec 17, 2018
Nickforall
added a commit
to Nickforall/bootloader
that referenced
this issue
Dec 17, 2018
This comment has been minimized.
This comment has been minimized.
andreeaflorescu
commented
Jan 11, 2019
|
Hey, I got to this issue because it is linked to the Is there another recommended way to get the panic information? I was also thinking about replacing the panic_hook with catch_unwind but we might get into problems if the external crates that we are using are implementing panic with abort. |
aturon commentedSep 11, 2017
•
edited by Centril
Update(2018-08-28)
This is a tracking issue for the RFC "stable mechanism to specify the behavior of panic! in no-std applications " (rust-lang/rfcs#2070).
Steps:
rust_begin_panicUnresolved questions:
fmt::DisplayShould the
DisplayofPanicInfoformat the panic information as"panicked at 'reason', src/main.rs:27:4", as"'reason', src/main.rs:27:4", or simply as"reason".Unwinding in no-std
Is this design compatible, or can it be extended to work, with unwinding
implementations for no-std environments?
Issues to solve before stabilization
rust_begin_unwindnot emitted when crate-type = bin #51671