Open
Description
I have the following signature for my HardFault
handler:
#[exception(trampoline = false)]
#[naked]
unsafe fn HardFault() -> ! {
...
This triggers the compiler warning
warning: Rust ABI is unsupported in naked functions
note:#[warn(undefined_naked_function_abi)]
on by default
Which could be avoided by modifying the signature to be:
#[exception(trampoline = false)]
#[naked]
unsafe extern "C" fn HardFault() -> ! {
...
But this is not accepted by the macro:
HardFault
handler must have signatureunsafe fn() -> !
Is there any reason for the macro to not allow specifying the ABI?
Also, could someone point me as to why does the following not produce the same warning?
#[pre_init]
#[naked]
unsafe fn pre_init() {
...
Activity
adamgreig commentedon Jan 22, 2025
Do you still get this error on the latest nightly? I can compile the following OK:
I don't think there's any reason to prohibit
extern "C"
functions here, but because the macro already generates the actual ISR and makes itextern "C"
as appropriate, I don't think we should need to change the user interface. We addednaked
to the list of allowed attributes a while ago and what it means has changed as it moves towards stabilisation, so we should probably just make sure that the attribute does what's expected in this context.You might find using
cargo expand
illuminating, for example the above expands to:in cortex-m-rt, there's a
bl __pre_init
which is how the pre-init function gets called, whileHardFault
is referred to from asextern "C" fn HardFault();
and placed into the vector table so will be called directly by hardware. The_HardFault
is empty and just for diagnostics. It looks like this should all work as expected with naked functions.SCingolani commentedon Feb 6, 2025
Strange, with an empty project containing just the code from your test and
rustc 1.86.0-nightly (a9730c3b5 2025-02-05)
I still get: