title: Segmentation Fault when Cross Compiling for Raspberry Pi the simplest program
body: <p>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.</p>
  <p>I know that this might be seen as &quot;duplicate&quot; of <a href="https://stackoverflow.com/questions/38616768/segmentation-fault-when-cross-compiling-for-raspberry-pi">Segmentation Fault when Cross Compiling for Raspberry Pi</a>
  Unfortunately there is no answer to that 5 year old question.</p>
  <p>Here is the code:</p>
  <pre><code>#include &lt;stdlib.h&gt;
  
  int main(void) 
  {
      return 0;   
  } /* END main() */
  </code></pre>
  <p>These are the compiler options I use</p>
  <pre><code>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
  </code></pre>
  <p>These are the linker options I use</p>
  <pre><code>arm-linux-gnueabihf-gcc -ggdb -Wl,--print-memory-usage -Wl,-Map=&quot;bin/test.map&quot; -Wl,--cref test.o -o bin/test
  </code></pre>
  <p>I transfer the binary with scp to the raspberry pi. When I try to execute it on the pi I immediatly get an &quot;Segmentation fault&quot; - Why? I don't see the problem, but guess it has something to do either my cross-toolchain or with an option I miss.</p>
  <p>Also I installed gdbserver on the pi. I can connect to it using gdb-multiarch on the local machine. As soon as I &quot;run&quot; I get the same result:</p>
  <pre><code>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 &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  Type &quot;show copying&quot; and &quot;show warranty&quot; for details.
  This GDB was configured as &quot;x86_64-linux-gnu&quot;.
  Type &quot;show configuration&quot; for configuration details.
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;.
  Find the GDB manual and other documentation resources online at:
  &lt;http://www.gnu.org/software/gdb/documentation/&gt;.
  
  For help, type &quot;help&quot;.
  Type &quot;apropos word&quot; to search for commands related to &quot;word&quot;.
  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 &quot;set sysroot&quot; 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 &lt;RET&gt; for more, q to quit, c to continue without paging--
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0044fcb6 in ?? ()
  (gdb) 
  </code></pre>
  <p>This is the version of the compiler I use:</p>
  <pre><code>$ arm-linux-gnueabihf-gcc --version
  arm-linux-gnueabihf-gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
  </code></pre>
  <p>I have no glue what is going on here.</p>
  <p>---- Edit ----</p>
  <p>@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.</p>
  <p>Output for the binary utilizing the apt-package (does SIGSEG):</p>
  <pre><code>$ 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,
  </code></pre>
  <p>Output for the binary utilizing the docker container (does run):</p>
  <pre><code>$ 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,
  </code></pre>
  <p>My guess is that glibc is to new for the one used on the pi - correct?</p>