Page 1 of 1

GCC cross-compiler experts help needed please ?

Posted: Sun Aug 01, 2010 3:38 pm
by gerryg400
Hi,

I'm trying to configure gcc to be able to cross-compile both 32 and 64 bit code. Currently I do this

Code: Select all

export SYSROOT=/Users/gerryg/artix/
export PREFIX=$SYSROOT/usr/
export TARGET=x86_64-artix

rm -rf $PREFIX
mkdir -p $PREFIX 

rm -rf binutils-build
mkdir binutils-build
cd binutils-build
../binutils-2.20.1/configure --disable-werror --target=$TARGET --prefix=$PREFIX --with-sysroot=$PREFIX
make all
make install
cd ..

rm -rf gcc-build
mkdir gcc-build
cd gcc-build
../gcc-4.5.0/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --with-newlib --enable-multilib
make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc
cd ..
This works okay for both 32 and 64 bit building, except that it only installs a single 64 bit version of libgcc.a. I could build and install 2 versions of gcc but I feel sure it should be possible to build a toolchain that does both. I've tried various targets including x86_64-pc-linux and x86_64-pc-elf. And I've even tried to make my own target.

I've been trying the --enable-multilib option but I feel I still need to do something else.

Can anyone tell me how to get both the 32 bit and 64 bit versions of libgcc.a built and installed ? Perhaps someone with a 64bit Linux machine ?

Thanks in advance.

Re: GCC cross-compiler experts help needed please ?

Posted: Sun Aug 01, 2010 5:52 pm
by pcmattman
You'll only get a libgcc for the target you originally compile. x86_64's libgcc won't have any i[1-8]86 code, and to my knowledge it isn't possible to compile one libgcc for two targets. This is the main reason we use two cross-compilers to distinguish x86_64 and i686 - with the added bonus that our build system just has to inspect the name of the cross-compiler to determine which target to build for.

We can also add i686-specific stuff to the GCC's "specs" file such as library selection, crtbegin/crtend generation, and even "default" compile options such as "-fPIC". These differ quite a bit in our system at least and the easiest way to solve that is having two cross-compilers.

Re: GCC cross-compiler experts help needed please ?

Posted: Sun Aug 01, 2010 6:02 pm
by gerryg400
Thanks. Yep I may have to go that way. Although I noticed just now when I build an x86_64-pc-linux target it does create a directory under libgcc called 32 (or something). This seems to contain the libgcc 32bit routines. However it doesn't seem to install. I'll have a bit of a look.

Also I used to have a 64 bit ubuntu machine and it could build both 32 and 64 bit apps. Not sure how it did that tho.

Re: GCC cross-compiler experts help needed please ?

Posted: Sun Aug 01, 2010 6:04 pm
by gerryg400
BTW, pcmattman, do you have your own TARGET defined or do you use one of the default (like x86_64-pc-elf) ones ?
We can also add i686-specific stuff to the GCC's "specs" file
Where is the specs file ?

Re: GCC cross-compiler experts help needed please ?

Posted: Sun Aug 01, 2010 6:37 pm
by pcmattman
BTW, pcmattman, do you have your own TARGET defined or do you use one of the default (like x86_64-pc-elf) ones ?
We define an [arch]-pedigree target for x86_64 and i686 (effectively following the OS Specific Toolchain stuff). Other architectures don't yet have an OS-specific cross-compiler.

The specs are usually built into the compiler, and are created from the "gcc/config/myos.h" file you create in the OS Specific Toolchain tutorial. The tutorial shows a very basic file but if you look at Linux's example you can significantly tweak the compiler to your heart's content.
Although I noticed just now when I build an x86_64-pc-linux target it does create a directory under libgcc called 32 (or something).
A quick inspection of the "config.host" file in libgcc shows stuff such as this:

Code: Select all

case ${host} in
i[34567]86-*-linux* | x86_64-*-linux*)
	# Provide backward binary compatibility for 64bit Linux/x86.
	if test "${host_address}" = 64; then
		tmake_file="${tmake_file} i386/${host_address}/t-softfp-compat"
	fi
	;;
esac
EDIT: Removed the "rawr" above, that was a placeholder for an answer and I forgot it was there :)

You may be able to get something that works for both yet, with a combination of host-specific configuration and the --enable-multilib flag. When in doubt, it never hurts to look around the build system.