Closed jiayihu closed 4 years ago
Currently math symbols are gated by target, not by feature, although that could change!
Otherwise symbols like free/calloc are not to be implemented by this crate but must be implemented by your runtime. Symbols like fpclassifyf may be coming from C code? In general if you're compiling for a *-none-*
target you're largely on your own. Everyone's use case there is a little different so things generally don't work by default.
Yes, in the end I implemented most of the floating point operations using libm
directly, free/alloc based on the heap used in alloc-cortex-m
and so on. __fpclassifyf, __fpclassifyd, __aeabi_d2f
came from clang however, whereas the rest were in the C code.
Thanks for the help!
I'm trying to build wasm3-rs to target
thumbv7em-none-eabi
and the last days have been really daunting. I think I've almost managed to do it, but I have some errors likerust-lld: error: undefined symbol: truncf
left. The full list of missing symbols is:So my question is how should I dealt with these intrinsics.
ceil, ceilf, floor, floorf, trunc, truncf
are already available in compiler-builtins (https://github.com/rust-lang/compiler-builtins/blob/master/src/math.rs#L82), just not enabled for my target.I've also cloned compiler-rt and tried to compile from C, but it gives the following error:
I guess it's because I have to pass the flag
--sysroot=/usr/local/opt/gcc-arm-none-eabi/arm-none-eabi
to the compiler but build.rs doesn't support any way to do it AFAIK. I had a similar issue withbindgen
, solved by using the env variableBINDGEN_EXTRA_CLANG_ARGS
. Nevertheless, I didn't went further with compiler-rt because it seemed to miss several intrinsics anyway. I checked incompiler-rt/lib/builtins
looking for files with the same name of the missing symbols.The other option was compiling libc provided by
gcc-arm-none-eabi
, as documented here: https://github.com/rust-embedded/book/issues/255. This in turns requires providing some lib stubs and some symbols likerintf
are still missing, although almost all math intrinsics are provided and optimized for the hardware, taking advantage of the FPU or SIMD for instance. Memory functionscalloc/free/realloc
are also implemented, although I wonder how they work since I'm currently using alloc-cortex-m and the heap is currently only needed to runwasm3-rs
wrapper and not by design. I'd like to go back heapless in future.My favourite choice so far is to cargo patch this repo and enable
ceil, ceilf, floor, floorf, trunc, truncf
for my target. Then I implement myself the other functions, depending also on whether I actually need them for my case andcalloc, realloc, free
onalloc-cortex-m
.This is my first real-world project with Rust and embedded, everything like clang, bindgen, cross-compilation is new to me and I've been learning a lot these last days "thanks" to the compile errors. I hope my ideas make sense. What would be the best direction to fix the missing symbols and hopefully end this journey?