newbieCoder
Posts: 1
Joined: Tue Oct 15, 2019 2:01 pm

Segmentation Fault On Pi Zero when trying to run executable which is compiled in raspberry 4.

Tue Oct 15, 2019 2:04 pm

I have a sd card that work fine on raspberry pi 4. Raspbian Buster(Version: September 2019 ) was installed into the SD card and i did a project which is including boost,opencv,raspi-cam libraries.

After that, I took output of executable to throw in raspberry pi zero.Btw,executable works fine in raspberry 4.

Whenever I transfer it to the raspberry pi zero . I get segmentation fault when trying to run executable. I also successed on running projects in rpi zero which compiled on rpi4 using boost and opencv.

hippy
Posts: 6068
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Segmentation Fault On Pi Zero when trying to run executable which is compiled in raspberry 4.

Tue Oct 15, 2019 3:06 pm

The Zero uses an ARMv6 instruction set device and, in my experience, can throw segmentation errors when running code which needs a later device - which may be the case for something compiled on a Pi 4B.

Some binaries will report that the device doesn't have the right ISA to run the code but most of the time, in my experience, something which needs something which isn't supported runs but then crashes.

Binaries seem to have all kind of flags and markers indicating what they are and were compiled for so it's unfortunate there's no automatic "You can't run that on this" reports when one tries to.

User avatar
Paeryn
Posts: 2698
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Segmentation Fault On Pi Zero when trying to run executable which is compiled in raspberry 4.

Tue Oct 15, 2019 8:07 pm

If the program was compiled on the RPi4 specifically for armv7 then the program would likely fail in the RPi0 with a SIGILL the moment it tries executing an instruction that armv6 doesn't have, and usually that happens very early as gcc uses MOVT a lot in armv7 which the RPi0's armv6 doesn't understand. So I'd not suspect this as your problem without ruling out anything else.

I'd suggest that you aren't checking a return value somewhere, especially if a function is returning a pointer and it would return NULL if it failed to acquire a resource. If you happen to assume it succeeded (when it doesn't on the RPi0) and go on to try dereferencing that pointer you'll get an immediate SIGSEGV.

A good time to learn gdb, if you compiled your program with debugging info (gcc/g++'s -g option) gdb can usually tell you exactly where the the error happened.
She who travels light — forgot something.

Return to “Troubleshooting”