-
Notifications
You must be signed in to change notification settings - Fork 349
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
no_std
issues with implementing panic_handler
#3498
Comments
The error says you should set I doubt that cortex_m_rt supports unwinding, so panic=abort is likely what you want. |
First off thank you for the incredibly quick reply!
to
And running both with and without the extra |
-Zbuild-std is known to confuse Miri, so maybe that is part of the problem here. (Cc #2705)
Does
Strange... looks like Miri asks for the lang item in a case where rustc does not. Is there a small example we could check out to reproduce the issue? |
I tried that just now and found the following behavior:
With To which I found #2962 and edited my
But execution returns the same error regarding missing a main function.
Here is the project I've been using. I am able to execute it using |
If you use |
That did the trick for
If I build without miri it's still throwing errors for not having a main, but that's just playing around with conditional compilation to add The issue with |
So I guess the issue with the start function is that cortex_m_rt has its own start function that Miri doesn't know about. @Necromaticon I assume that
With the entry point issue resolved, what exactly is the issue with these panic crates? What even is |
That is using a crate on crates.io called panic-abort, which contains a |
It seems to create an |
I don't think that'd be necessary either. Since there is already a way to define the entry function in Miri using The setup I'm using now requires limited editing to the files under test:
Only important note here is that the
Then that makes sense why it would require the As for the missing crates issue I found out that |
I filed rust-lang/rust#124581 for the confusion around For the panic crates, I tried your example. I adds 3 panic runtimes as dependency, which makes little sense to me? Even
So it is entirely expected that So I reduced it to 1:
Now I can do So, currently I can't reproduce any unexpected behavior here. Strangely, if I make that program panic it seems to use the default panic handler from std. I don't know where this comes from. But |
I guess there is a feature request here for having Miri support the "entry point" for cortex-m-rt. Currently we only support entry points that Rust "knows", i.e. the usual main function (to be invoked by the standard library, i.e. this only works for with-std binaries) and the However, I assume every embedded platform has its own idiosyncratic ways to define and find the start function; I don't think I want Miri to become a collection of all of those mechanisms. One approach I could consider is to say that if no main or start function is defined, Miri goes looking for a symbol named If there's interest in pursuing that from the cortex-m folks, then someone please file a separate Miri issue for that so it can be tracked properly. |
Ah, lol, figured it out...
That crate is empty when built for any other target. Which means it does not have the no_std attribute. Which means it pulls in std, and therefore the std panic handler. |
That also explains why you got a "missing crate" error, @Necromaticon: by setting MIRI_NO_STD=1, i.e. by building your host's Miri sysroot (which usually has std!) without std, you got a partial sysroot, but panic_semihosting actually requires std on all targets that do not satisfy MIRI_NO_STD should not usually be used; these days Miri generally recognizes no-std targets by itself (though that is somewhat heuristic, so we keep the env var for cases where the heuristic fails). So, I'll close this issue, as there is no Miri bug: you added a crate as dependency that depends on std, and built a sysroot without std, and then that fails to build. No surprise here. |
Filed #3529 for the poor diagnostic when MIRI_NO_STD is used and a crate actually requires |
Add `miri_start` support This PR uses a function with the exported symbol `miri_start` as a drop-in alternative to `#[start]`. So the signature stays the same as suggested in [this comment](#3498 (comment)). <del>I’ve also removed Miri’s restriction to only work on bin crates as I don’t think this is necessary anymore.</del> Closes #3758
Add `miri_start` support This PR uses a function with the exported symbol `miri_start` as a drop-in alternative to `#[start]`. So the signature stays the same as suggested in [this comment](rust-lang/miri#3498 (comment)). <del>I’ve also removed Miri’s restriction to only work on bin crates as I don’t think this is necessary anymore.</del> Closes rust-lang#3758
Add `miri_start` support This PR uses a function with the exported symbol `miri_start` as a drop-in alternative to `#[start]`. So the signature stays the same as suggested in [this comment](rust-lang/miri#3498 (comment)). <del>I’ve also removed Miri’s restriction to only work on bin crates as I don’t think this is necessary anymore.</del> Closes rust-lang#3758
I'm trying to interpet a very simple
no_std
example before going for any bigger problems.Problem appears to be that none of the
panic_handler
crates are working with Miri.The command I'm using to run the code is:
MIRI_NO_STD=1 cargo miri run
Code:
First off, both
use panic_halt as _;
anduse panic_abort as _;
create the following issue:That's something that seems to be an issue with
cargo build
in general and not just Miri specific. I don't quite understand whyabort
andhalt
wouldn't work forno_std
environments though considering these panic handlers were made for this express purpose.So I tried going for
use panic_semihosting as _;
and encountered an even weirder problem where the crates aren't recognized on build but only when I runcargo miri
. If I runcargo run
everything works without a hitch.Error:
It seems that Miri fails to somehow link the cargo crates when building. I've also tried building with
extern crate
but then the problem of the panic handler being missing consists and all examples of panic handlers using the#[panic_handler]
flag I found invoke the unwinding panics error.Thank you in advance for the help!
The text was updated successfully, but these errors were encountered: