On an embedded project with Rust, I'm currently facing the following issue when I try to implement my own panic handler.
To give you some context, I'm currently building my project with rust nightly version. The code is here :
#![no_std] //Disable standard lib
#![no_main]
#![feature(lang_items)]
#[lang = "panic_fmt"]
#[lang = "eh_personality"] extern fn eh_personality() {}
#[no_mangle]
pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("\n\nPANIC in {} at line {}:", file, line);
println!(" {}", fmt);
loop{}
}
Here is partialy my Cargo.toml :
[lib]
crate-type = ["staticlib"]
[dependencies]
multiboot2 = { version = "0.19", default-features = false }
rlibc = "1.0.0"
spin = "0.9.8"
volatile = "0.2.7"
x86_64 = "0.14.11"
[dependencies.lazy_static]
version = "1.4.0"
features = ["spin_no_std"]
and my target :
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float"
}
When compiling, I got the following error :
panic_fmt lead to found duplicate lang item panic_fmt
the lang item is first defined in crate core
I can't figure out why
I tried to take a look on some issues from Rust official repository but nothing is really similar to my case.