-
I just added to my project some code trying to use a function returning some floats (on atmega32u4), and I seem to be getting a linker error:
Am I doing something wrong? Am I missing something? My project is generally at: https://github.com/akavel/chordite-rust; I'm trying to call Any ideas what I could try? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
In meantime, I found the EDIT: Whoops, too happy too early: micromath seems waaaay too humongous for my case: trying to use it gave me some +80KB to hex file size - this doesn't seem sustainable... :( |
Beta Was this translation helpful? Give feedback.
-
f32 operations (aka intrinsics) are provided by avr-gcc and so depending on your avr-gcc's version you might or might not have them on your machine (newer avr-gcc = better, in general). But going over rust-lang/compiler-builtins#711 I've realized that we should be actually able to pull those intrinsics from compiler-builtins, which is a Rust crate that implements those operations bypassing the need for avr-gcc to provide them - in particular, the function that you're missing is there: ... but over rust-lang/compiler-builtins#527 I've disabled those floating-point intrisics, since they seemed not to work - initially I assumed it was an ABI mismatch (as in rust-lang/compiler-builtins#462 (comment)), but since floating-point intrinsics don't require special ABI (as I've noticed just now), it must be actually a codegen bug. tl;dr floating-point operations should work (and shouldn't even be prohibitively heavy), but it's somewhat of a gray area at the moment - in particular, there's something wrong in the codegen, because if you do: #[inline(never)]
fn out() -> bool {
f32::from_bits(black_box(2143289344)).is_nan()
}
#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
ufmt::uwrite!(serial, "out={}\n", out());
loop {
//
}
} ... then as-is (using avr-gcc's intrinsics) it will correctly print tl;dr tl;dr it should work, is broken, will report back when I have a solution 🙂 |
Beta Was this translation helpful? Give feedback.
-
Hah, it might be an ABI mismatch, after all 😄 -- it seems that compiler-builtins assumes that some intrinsics, like this one, return i32: ... while in reality they should return |
Beta Was this translation helpful? Give feedback.
-
Ok, got something tangible! rust-lang/compiler-builtins#791 If you want, @akavel, you can test it locally by adding |
Beta Was this translation helpful? Give feedback.
Ok, got something tangible!
rust-lang/compiler-builtins#791
If you want, @akavel, you can test it locally by adding
compiler_builtins_ex = { package = "compiler_builtins", git = "https://github.com/Patryk27/compiler-builtins", branch = "avr-skip-no-more" }
toCargo.toml
andextern crate compiler_builtins_ex;
tomain.rs
; having done so, floating-point operations should work.