robiwan
Posts: 13
Joined: Tue Apr 10, 2012 11:12 am

Problems cross-compiling for Zero with gcc

Sun Oct 28, 2018 3:56 pm

Hi,

I'm trying to use gcc 6.3.0 to cross-compile to the Pi Zero, however even a simple hello-world binary is not executable (SIGSEGV even before main is executed). Using gcc 6.3.0 to compile ON the Pi Zero works fine.

I'm cross-compiling with -marm -march=armv6 -mfpu=vfp -mfloat-abi=hard, and I can see that the same flags (less -marm) is used when compiling on the Pi Zero.

What have I missed ??

Regards
/R
Btw. Using the same toolchain for cross-compiling to a RPi 3 works just fine, it is only a problem with Zero.

jahboater
Posts: 3250
Joined: Wed Feb 04, 2015 6:38 pm

Re: Problems cross-compiling for Zero with gcc

Sun Oct 28, 2018 4:48 pm

Odd. I just tried it with "-mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard" and the executable fails with illegal instruction.

The only time I normally cross compile is building the compiler itself which takes over 2 days on a Pi Zero and about 4 hours on a Pi 3B+, so it is worth while. Smaller programs I don't bother.

robiwan
Posts: 13
Joined: Tue Apr 10, 2012 11:12 am

Re: Problems cross-compiling for Zero with gcc

Mon Oct 29, 2018 7:06 am

Mind you, I do use the toolchain from here: http://thebugfreeblog.blogspot.com/2017 ... chain.html as there is no official toolchain release more recent than 4.9.3, and it does state that it is built for armv7-a.

I'm trying crosstool-ng now to setup my own armv6 toolchain with gcc 6.4.0, see how that pans out.

robiwan
Posts: 13
Joined: Tue Apr 10, 2012 11:12 am

Re: Problems cross-compiling for Zero with gcc

Mon Oct 29, 2018 3:32 pm

Ok, starting with the armv6-rpi-linux-gnueabi sample, small changes I got it to work. However, I didn't get the opportunity to setup the exact version of glibc and gcc in crosstool-ng to 2.24 and 6.3.0 (which is that of debian stretch) with menuconfig...

robiwan
Posts: 13
Joined: Tue Apr 10, 2012 11:12 am

Re: Problems cross-compiling for Zero with gcc

Tue Oct 30, 2018 2:23 pm

I went back and setup a crosstool-ng project with:

[l.X] arm-unknown-linux-gnueabihf
OS : linux-4.9.128
Companion libs : gmp-6.1.2 mpfr-4.0.1 mpc-1.1.0 isl-0.20 cloog-0.18.4 expat-2.2.6 ncurses-6.1 libiconv-1.15 gettext-0.19.8.1
Binutils : binutils-2.31.1
Compiler : gcc-6.4.0
Languages : C,C++
C library : glibc-2.24
Debug tools : gdb-8.2
Companion tools : autoconf-2.69 automake-1.16.1

and gcc/g++ build with --with-cpu=arm1176jzf-s --with-fpu=vfp --with-float=hard, and lo and behold, it works perfectly. :D

plugwash
Forum Moderator
Forum Moderator
Posts: 3268
Joined: Wed Dec 28, 2011 11:45 pm

Re: Problems cross-compiling for Zero with gcc

Tue Nov 06, 2018 4:46 am

The problem is that when you pass flags on the compiler command line to change the minimum CPU requirements they change the minimum CPU requirements for the code generated by the compiler, but they don't change the minimum CPU requirements for the libraries/startup code supplied with the compiler.

Return to “C/C++”