Skip to content
Advertisement

gdb can’t cross-compile for arm-linux

The Linux already having both gcc & arm-gcc in the environment path:

[fit@localhost gdb-arm]$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=i386-redhat-linux
Thread model: posix
gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC) 


[fit@localhost gdb-arm]$ arm-none-linux-gnueabi-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/src/gcc-4.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --with-specs='%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}' --enable-languages=c,c++ --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2009q1-203' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203) 

So I configure the gdb 6.6:

$ ./configure --target=arm-none-linux-gnueabi --host=i386-redhat-linux -v

compiled without error, but looks like gdb used the wrong compiler.

file ./gdb-build/bin/arm-none-linux-gnueabi-gdb
./gdb-build/bin/arm-none-linux-gnueabi-gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

So How to indicate the correct CC for gdb?

I tried make CC=arm-none-linux-gnueabi-gcc, but will get the error:

arm-none-linux-gnueabi-gcc ../.././sim/arm/../common/gentmap.c -o gentmap -g -O -I. -I../.././sim/arm -I../common -I../.././sim/arm/../common -I../../include -I../.././sim/arm/../../include -I../../bfd -I../.././sim/arm/../../bfd -I../../opcodes -I../.././sim/arm/../../opcodes  
rm -f tmp-tvals.h tmp-tmap.c
./gentmap -h >tmp-tvals.h
/bin/sh: ./gentmap: cannot execute binary file

Advertisement

Answer

./configure --target=arm-none-linux-gnueabi --host=i386-redhat-linux -v

Don’t use --target. It means something else to Autotools.

Use --build and --host. Something like:

./configure --build=$(config.guess) --host=arm-none-linux-gnueabi

--build should specify the machine you are running Autotools on, and --host should specify the machine the package will run on.

Note there is some Autootols bug that requires you to specify both --build and --host. It is yet another Autotools problem that has never been fixed.

Also see 2.2.8, Cross-Compilation in the Autools manual.

You will still need to get the paths and sysroot right, but this should provide the proper configure command so things begin to fail as expected.


config.guess will return a triplet for the machine you are running Autotools on:

$ find /usr/share/ -name config.guess
/usr/share/libtool/build-aux/config.guess
...

$ /usr/share/libtool/build-aux/config.guess
x86_64-pc-linux-gnu

If you find the package has one but it is out of date you can update it with the following command. You usually need to do this for AIX and Solaris machines.

wget 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess' -O config.guess

And you can update config.sub the same way:

wget 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub' -O config.sub
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement