Segfault Running Pre-Compiled Binary
dstutman opened this issue · 2 comments
Hi, I cross compiled a rust binary for arm-unknown with hardware floating point. I copy it into the docker container, but when I run it, it segfaults. Is this a known problem or am I targeting the wrong architecture? The target device is a first generation Raspi.
Cross-compilation for Rpi 1 (ARMv6) is trickier than Rpi 2 & 3 and I personally encountered similar segfaults. The problem is not with Rust, but the debian cross-compilation toolchain linker that does not support ARMv6. You can check the binary with readelf -a <binary>
or file <binary>
and most probably you will find that it is linked as ARMv7 binary.
The correct Rust target for Rpi 1 (ARMv6) is arm-unknown-linux-gnueabi
.
Most probably you can get positive results using this cross-compilation Rust toolchain: https://github.com/japaric/cross
For my use case (WiFi Connect) I could not use the above toolchain, so I had to go with a custom solution. I managed to successfully compile using a Raspbian fork of the debian toolchain that supports ARMv6. You can look at this Dockerfile for how I achieved that: https://github.com/resin-io/resin-wifi-connect/blob/master/scripts/docker/arm-unknown-linux-gnueabihf/Dockerfile
Thanks for the help. I managed to fix this with cross as you suggested.
There was one thing that had to be done in addition to simply using the toolchain:
For the benefit of people seeing this in the future, link /lib/arm-linux-gnueabihf/ld-linux.so.3
to /lib/ld-linux.so.3
if using Debian as the base image.
Thanks,
Dan