-
Notifications
You must be signed in to change notification settings - Fork 85
[RFC] [breaking-change] don't depend on GCC by default #91
Comments
Sounds great! |
I think this is a good compromise. |
Seems reasonable to me. |
This will also affect #77. Will it possible to grab the Some quick experimenting suggests this does work, but I worry about how fragile it might be. |
@adamgreig I believe that if we implement that in Rust it would not be reliable. If it's all in Rust then the compiler can inline UserHardFault into HardFault which can cause the a function prelude to be generated and the prelude would modify SP before it's read. We could mark UserHardFault as
#77 seems complex enough that a Rust implementation would very likely not work properly when unoptimized. In that mode the compiler makes more use of the stack which would modify SP before it's read. |
It's a shame rust-lang/rust/issues/32408 isn't stabalised yet or we could just use Anyway, I think your suggestion of I guess we can investigate after resolving the issue here. |
I've disabled #[no_mangle]
pub unsafe extern "C" fn HardFault() -> ! {
extern "C" { fn UserHardFault(eh: &ExceptionFrame) -> !; }
let ef: &ExceptionFrame = &*(cortex_m::register::msp::read() as *const _);
UserHardFault(ef);
}
exception!(HardFault, hf);
#[inline(always)]
fn hf(ef: &ExceptionFrame) -> ! {
if ef.pc == 0x0700_0000 {
loop { unsafe { core::ptr::read_volatile(0x0000_1234 as *const u32); } }
} else {
loop { unsafe { core::ptr::read_volatile(0x0000_1238 as *const u32); } }
}
} I marked I can then trigger a HardFault with: fn crasher() {
let x: extern "C" fn() = unsafe { core::mem::transmute(0x07000000 as *const u32) };
x();
} The generated code in release is identical to the current external assembly solution except for the trailing UDF in HardFault:
and in debug, we branch to read MSR but without touching the stack:
It seems to work as required. Even with a bunch of silliness I can't get it to try and touch the stack in the UserHardFault prologue, but anyway since that method is That all said I have discovered that in debug mode my gdb crashes during a HardFault unless the debugger is set to intercept it, both on current master and with this change. Fine on release. Maybe a gdb bug, who knows... |
I have proposed an alternative that doesn't require a breaking change or adding a new Cargo feature in RFC #95. |
95: [RFC] remove build dependency on arm-none-eabi-gcc (binary blob alternative) r=japaric a=japaric Before this commit we used gcc to assemble external assembly files into object files that we linked into our Rust program. This commit drops the dependency on gcc by shipping the already assembled object files with this crate source code. --- This is an alternative to RFC #91 that doesn't require a breaking change or adding a new Cargo feature and can be implemented right now. See #91 for the rationale of dropping the dependency on gcc. This approach can be applied to other Cortex-M crates like cortex-m-semihosting and cortex-m (would subsume RFC rust-embedded/cortex-m#107). This seems like an overall better approach to me, but before I go opening more PRs I want to hear your thoughts, @rust-embedded/cortex-m closes #91 Co-authored-by: Jorge Aparicio <jorge@japaric.io>
It's very likely that the thumb targets will soon switch to rust-lld as their default linker (see
rust-embedded/wg#160). If we want to achieve the goal of not depending on GCC, by default, to
build Cortex-M applications then we also have to make core crates like this one not depend on GCC by
default. This RFC is exactly about that.
I propose that in the next minor (breaking) release, v0.6.0, we add an opt-in Cargo feature named
"exception-frame" that changes the signature of the HardFault handler as it's shown below:
The rationale for this change is that providing
ExceptionFrame
information to the handler requiresan external assembly file and that
makes this crate depend on GCC. By making this information opt-in this crate would, by default, work
w/o GCC being present. If the user wants the
ExceptionFrame
information they'll need to have GCCinstalled.
cc @rust-embedded/cortex-m @hannobraun @crawford
The text was updated successfully, but these errors were encountered: