'Segmentation Fault when Cross Compiling for Raspberry Pi the simplest program
I'm experimenting with the most simplest program I can came up with, to check out cross-compiling and remote debugging on a raspberry pi 1b.
I know that this might be seen as "duplicate" of Segmentation Fault when Cross Compiling for Raspberry Pi Unfortunately there is no answer to that 5 year old question.
Here is the code:
#include <stdlib.h>
int main(void)
{
return 0;
} /* END main() */
These are the compiler options I use
arm-linux-gnueabihf-gcc -pedantic -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Werror -ggdb -std=gnu99 -fpic -marm -mfloat-abi=hard -mfpu=vfp -c -o test.o
These are the linker options I use
arm-linux-gnueabihf-gcc -ggdb -Wl,--print-memory-usage -Wl,-Map="bin/test.map" -Wl,--cref test.o -o bin/test
I transfer the binary with scp to the raspberry pi. When I try to execute it on the pi I immediatly get an "Segmentation fault" - Why? I don't see the problem, but guess it has something to do either my cross-toolchain or with an option I miss.
Also I installed gdbserver on the pi. I can connect to it using gdb-multiarch on the local machine. As soon as I "run" I get the same result:
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0xc08: file
/home/dev/src/main.c, line 3.
Reading /lib/ld-linux-armhf.so.3 from remote target...
Warning: File transfers from remote targets can be slow. Use "set sysroot" to access
files locally instead.
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading /lib/69cc7c8461969efd3718272bbf9f5284465419.debug from remote target...
Reading /lib/.debug/69cc7c8461969efd3718272bbf9f5284465419.debug from remote
target...
Reading /usr/lib/debug//lib/69cc7c8461969efd3718272bbf9f5284465419.debug from remote
target...
Reading /usr/lib/debug/lib//69cc7c8461969efd3718272bbf9f5284465419.debug from remote
target...
Reading target:/usr/lib/debug/lib//69cc7c8461969efd3718272bbf9f5284465419.debug from
remote target...
Reading /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so from remote target...
Reading /lib/arm-linux-gnueabihf/libc.so.6 from remote target...
Reading /usr/lib/arm-linux-gnueabihf/4720c484c733362ad0713e1328e88f42334bed.debug
from remote target...
Reading /usr/lib/arm-linux-
gnueabihf/.debug/4720c484c733362ad0713e1328e88f42334bed.debug from remote target...
Reading /usr/lib/debug//usr/lib/arm-linux-
gnueabihf/4720c484c733362ad0713e1328e88f42334bed.debug from remote target...
Reading /usr/lib/debug/usr/lib/arm-linux-
gnueabihf//4720c484c733362ad0713e1328e88f42334bed.debug from remote target...
Reading target:/usr/lib/debug/usr/lib/arm-linux-
gnueabihf//4720c484c733362ad0713e1328e88f42334bed.debug from remote target...
Reading /lib/arm-linux-gnueabihf/193a3bab8dcbe8499da5b220f646fc717d6032.debug from
remote target...
Reading /lib/arm-linux-gnueabihf/.debug/193a3bab8dcbe8499da5b220f646fc717d6032.debug
from remote target...
Reading /usr/lib/debug//lib/arm-linux-
gnueabihf/193a3bab8dcbe8499da5b220f646fc717d6032.debug from remote target...
Reading /usr/lib/debug/lib/arm-linux-
gnueabihf//193a3bab8dcbe8499da5b220f646fc717d6032.debug from remote target...
Reading target:/usr/lib/debug/lib/arm-linux-
gnueabihf//193a3bab8dcbe8499da5b220f646fc717d6032.debug from remote target...
--Type <RET> for more, q to quit, c to continue without paging--
Program received signal SIGSEGV, Segmentation fault.
0x0044fcb6 in ?? ()
(gdb)
This is the version of the compiler I use:
$ arm-linux-gnueabihf-gcc --version
arm-linux-gnueabihf-gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
I have no glue what is going on here.
---- Edit ----
@Frant the options doesn't change anything. However I downloaded a docker container to compile for the pi. I noticed a difference in using file on each of the binaries.
Output for the binary utilizing the apt-package (does SIGSEG):
$ file bin/hello
ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0,
Output for the binary utilizing the docker container (does run):
$ file bin/hello
ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.26,
My guess is that glibc is to new for the one used on the pi - correct?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
