-
Notifications
You must be signed in to change notification settings - Fork 225
Interrupt handlers from app macro don't appear to work in debug mode #39
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
Comments
Ok, I worked out what was going on. Although I've worked out the issue, I still think it's a bug that different optimisations result in different behaviour. I can see that LTO is required for the weak symbols to be resolved. Changing the way that the vector table is defined so that it's pure rust rather than using weak symbols and extern c functions sounds great to me (if possible). Alternatively there could be a build.rs that checks the rustflags for the current profile that fails if required options aren't set correctly. Let me know what you think, I'm pretty new to rust to feel free to shoot me down ;) |
That's interesting. I wonder if linker is not overriding the weak symbol properly. LTO should not be required for this to work. |
My hypothesis (I haven't looked at anything yet) is that the linker is dropping the TIM7 symbol defined in the application. It's likely doing that because of how Rust objects are being passed to it (the order matters) in the command line; you don't see this because in LTO there's only one object file passed to the linker in that case. Will take a look. |
Thanks, let me know if there is anything I can do to help. |
This .weak FOO
FOO = BAR which cortex-m-rt and device crates are using doesn't produce any symbol; neither clang or rustc produce symbols for it. It seems that the symbol resolution for that code is entirely tracked in LLVM. For this reason there's e.g. no undefined How to deal with this:
|
How did you test for that? For example, #![feature(global_asm)]
#![feature(linkage)]
#[no_mangle]
#[linkage = "weak"]
pub extern "C" fn BAR() {
}
global_asm!(r#"
.weak FOO
FOO = BAR
"#); Compiling:
Both symbols are present in the object file:
|
@japaric clang will emit a compilation error for such case:
|
Add an extra function as a possible solution for https://github.com/japaric/cortex-m-rtfm/issues/39
Fixed in svd2rust v0.11.3. Note that you'll have to regenerate device crates that were created using svd2rust v0.11.2 using the latest svd2rust version to fix this problem in your application. |
Can confirm it's fixed it for me. Thanks for the quick fix! |
I've converted a project I'm tinkering with to v2 but a basic example of a timer interrupt doesn't work in debug mode.
In release mode it works as expected, never hits the default_handler and a counter the timer interrupt is incrementing goes up every 10 seconds as expected.
In debug mode it goes straight to the default handler. The exception is 55, which is the correct interrupt.
I've double checked the "rt" feature flag stuff is getting generated in my device crate and the
xargo expand
output contains what looks like an override for the weak symbol defined in the device support crate:I'm a bit hazy on the details of how linking/weak symbols/etc works so please let me know if there are any commands i can run on the ELF files to get more info. This seemed relevant:
I've updated my arm and rust toolchains and double checked the various xargo and cargo config files for all projects and everything seems to be in line with your blue-pill repo.
Thanks
The text was updated successfully, but these errors were encountered: