Skip to content

no_std issues with implementing panic_handler #3498

Closed
@Necromaticon

Description

@Necromaticon

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:

#![no_main]
#![no_std]

//insert individual panic methods here

use cortex_m_rt;

#[cortex_m_rt::entry]
fn main() -> ! {
   loop {}
}

First off, both use panic_halt as _; and use panic_abort as _; create the following issue:

error: unwinding panics are not supported without std
 |
 = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
 = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

That's something that seems to be an issue with cargo build in general and not just Miri specific. I don't quite understand why abort and halt wouldn't work for no_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 run cargo miri. If I run cargo run everything works without a hitch.
Error:

error[E0463]: can't find crate for `panic_semihosting`
 --> embeddedMiri/src/main.rs:4:5
  |
4 | use panic_semihosting as _;
  |     ^^^^^^^^^^^^^^^^^ can't find crate
  |
  = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `#[panic_handler]` function required, but not found

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions