-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Stabilize intrinsics::abort
in core
#2512
Comments
I've also found it strange that this doesn't exist in core; big 👍 from me. |
I'm all for it, but I'm wary about |
@glandium |
I'm not a big fan of the way Then again, this is a lot of work for something that is very rarely used (compared to normal panics). It might not be worth the trouble. |
Sorry for the delay in getting to this @japaric, but FWIW I'd personally be ok with a PR to add this to an unstable (eventually to-be-stable) location in libstd and then later have a stabilization PR. This doesn't seem like it's RFC-grade to me |
@Amanieu this proposal is about stabilizing a way to generate a trap / abort instruction. Your comment seems to be about a user customizable @alexcrichton sounds good! The main question here is where in |
@japaric I'd put it in
So suppose we would put it in |
It's already in intrinsics: Yeah, I'm not sure stuff in
This was a typo, i think. I probably meant a stable wrapper around the
If that's OK then, yeah, we don't need anything else in |
And as a data point: for these architectures For MSP430 and RISCV32 AFAIK, there's no precedent for a stable API in core that can produce linker |
Do clang and GCC export these somehow? I've used a We could re-export it in cc @eddyb @sunfishcode does Cretonne have a |
Libs team hat on: I’d rather not stabilize the In the past, when stabilizing an intrinsic, we’ve added a re-export or wrapper in another (stable) module. That |
First, lowering into Additionally, there is a function attribute called
Think of |
Are you suggesting that we "polyfill" Also, with this approach we would have to take care not only of MSP430 but also of every new architecture that we add in the future and that has this problem (possibly, AVR). |
I don't personally have a lot of thoughts about where this should go or what to name it, but I agree with @SimonSapin that we should avoid the |
It has As for where to place this, definitely not |
Re: msp430 and Therefore I'd prefer that we'd not have a stable trap API on |
Oh, using |
@gnzlbg given the last comments, do you think we could move forward with |
Yes, this looks fine to me. Will you send a PR for adding it to the architecture-specific submodules in stdsimd? Does anyone feel strongly about this intrinsic needing an RFC to stabilize or would an FCP be enough to stabilize it for some of the archs at least? |
Perhaps if it's going in |
Since I expect this functionality (independent of the name) to be provided at least for the current architectures that So I checked out the instructions generated by
And things are IMO looking good. All architectures that we support (one exception) have a native trap instruction sequence that The only exception appears to be |
@gnzlbg on arm it generates an undefined instruction which your disassembler may shown like |
@parched indeed, on arm the assembly contains an |
Done in rust-lang/stdarch#571 |
Heads up: I've merged @japaric 's implementation of the platform specific "abort" intrinsics to Note that this does not mean that these are in the path towards stabilization. This issue is about a portable way to abort, which had some unresolved questions that made the discussion derail a bit. These questions are:
I think these questions are worth resolving, and once we have consensus on these, I can submit a PR implementing a portable/semi-portable way to trap. In the meantime, what has been merged into nightly is intrinsics for platform-specific trap instructions. These should be usable from It is still unclear at this point whether we only want to stabilize a portable way to trap, or whether we want to stabilize both, but I think it is worth holding the stabilization of the platform-specific trap instructions (which would need an RFC) until the unresolved questions about the portable trap intrinsic are resolved. Afterwards, I would welcome a PR to At that point, we will probably have two ways to trap in nightly, a platform-specific way, and a portable/semi-portable way, and will have hopefully gathered enough experience with both that the next step would be to write a small RFC about whatever solution "feels right". |
IMO we should just always call the |
That’s what this issue is about. I don’t know how to provide that implementation without a libc and without messing with architecture-specific instructions though, could you give an example? |
I meant that we should just leave this symbol undefined and let the user define it (somewhat like |
Could you give an example of how you expect a "typical" embedded application to define this symbol? Especially the divergence part. Do we want to recommend Do you mean that defining this symbol would be mandatory for applications that do not link to |
An alternative would be to do something like this: #[unwind(aborts)]
pub fn abort() -> ! {
panic!("abort")
} This reuses the panic mechanism to print an abort message, and forces an abort during unwinding. |
Today, "panic=abort" means that When So adding "per-function panic=abort" doesn’t help with the fact that no_std applications need a way to diverge in their panic handler. |
@jhpratt How is this related to |
Any updates here? I have a use for this in a |
Why would panic be UB? If you're using |
i think they mean that unwinding as a result of panic would be the UB. |
I added an emphasis on library :) |
I would like to see
intrinsics::abort
stabilized in some form as it's useful in some cases to havepanicking behavior (and alloc_error) = abort (minimizes code size and the abort exception / signal
can be handled elsewhere or in a upper abstraction layer).
As
intrinsics::abort
lowers to a trap instruction on most architectures (*) I propose we add asafe wrapper around it in
core::arch::$ARCH
for the architectures where it does.(*) On most but not on all. For example, On MSP430 it lowers to a call to the
abort
functionwhich results in a linker error unless that symbol is defined somewhere in the dependency graph.
(Related: There's
std::process::abort
which claims to be a safe wrapper aroundintrinsics::abort
but if you at its implementation it is, in fact, not just a wrapper around
intrinsics::abort
butsomething completely different.)
@rust-lang/libs what would be needed to move this forward? An full RFC, or just a PR + FCP?
cc @Amanieu @glandium
The text was updated successfully, but these errors were encountered: