www.digitalmars.com         C & C++   DMDScript  

D.gnu - Building PowerPC cross compilers on X86 Linux

reply Matt Brandt <justmattb walkingdog.net> writes:
I've been checking out D for quite a while now and I would really like to use
it for some embedded stuff I do. We compile for powerpc-linux on x86-linux
boxen and so I've been trying to generate a cross compiler. I did the obvious
hack of using crosstool and repacking the gcc tarball with the D patches
applied and then trying to run that. It gets a long way (all the way to trying
to compile the Phobos libs) but then fails with:

checking If /home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6
build-gcc/./gcc/gdc -B/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.
.6/build-gcc/./gcc/ -B/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerp
-603-linux-gnu/bin/ -B/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerp
-603-linux-gnu/lib/ -isystem
/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerpc-6
3-linux-gnu/include -isystem
/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerpc-603-l
nux-gnu/sys-include can compile D sources...
/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/b
ild-gcc/./gcc/cc1d: error while loading shared libraries:
/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/build-gcc/
/gcc/libgcc_s.so.1: ELF file data encoding not little-endian
no
configure: error: can't compile D sources!
make[1]: *** [configure-target-libphobos] Error 1
make[1]: Leaving directory
`/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/build-gcc'
make: *** [all] Error 2

The cross compiled library ought to be big endian (and seems to be) but cc1d
must be trying to load the target libraries instead of the native libraries
when it runs the compiler passes. A cross compiler for c, c++, and objc builds
fine with the same set of scripts, so this must be something specific to the D
makefiles that is getting confused...

I just thought I would ask before I wade into this if the issue has come up
before, or if anyone that has a working powerpc compiler running on x86 linux.

Thanks,

Matt
Feb 17 2007
parent Gregor Richards <Richards codu.org> writes:
Matt Brandt wrote:
 I've been checking out D for quite a while now and I would really like to use
it for some embedded stuff I do. We compile for powerpc-linux on x86-linux
boxen and so I've been trying to generate a cross compiler. I did the obvious
hack of using crosstool and repacking the gcc tarball with the D patches
applied and then trying to run that. It gets a long way (all the way to trying
to compile the Phobos libs) but then fails with:
 
 checking If /home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6
build-gcc/./gcc/gdc -B/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.
.6/build-gcc/./gcc/ -B/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerp
-603-linux-gnu/bin/ -B/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerp
-603-linux-gnu/lib/ -isystem
/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerpc-6
3-linux-gnu/include -isystem
/lifesize/tools/cross/gcc-4.1.1-glibc-2.3.6/powerpc-603-linux-gnu/powerpc-603-l
nux-gnu/sys-include can compile D sources...
/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/b
ild-gcc/./gcc/cc1d: error while loading shared libraries:
/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/build-gcc/
/gcc/libgcc_s.so.1: ELF file data encoding not little-endian
 no
 configure: error: can't compile D sources!
 make[1]: *** [configure-target-libphobos] Error 1
 make[1]: Leaving directory
`/home/mbrandt/Desktop/crosstool-0.43/build/powerpc-603-linux-gnu/gcc-4.1.1-glibc-2.3.6/build-gcc'
 make: *** [all] Error 2
 
 The cross compiled library ought to be big endian (and seems to be) but cc1d
must be trying to load the target libraries instead of the native libraries
when it runs the compiler passes. A cross compiler for c, c++, and objc builds
fine with the same set of scripts, so this must be something specific to the D
makefiles that is getting confused...
 
 I just thought I would ask before I wade into this if the issue has come up
before, or if anyone that has a working powerpc compiler running on x86 linux.
 
 Thanks,
 
 Matt
 
I haven't made a powerpc cross-compiler, but I have successfully made GDC cross compilers. I've never found it very productive to hack crosstool into doing what I want, so here's what I'd do: 1) Get a standard (C-capable) crosscompiler made with crosstool 2) Add it to your PATH (duh) 3) [standard GDC setup] tar jxf gcc-core-<version>.tar.bz2 ; tar jxf gcc-<anythingelse>-<version>.tar.bz2 ; cd gcc-<version>/gcc ; tar jxf ../../gdc-src-0.22.tar.bz2 ; cd .. ; ./gcc/d/setup-gcc.sh Now is the complicated part. Building a GDC cross compiler requires that you generate a few files /on the target/. So: 4) cd gcc/d/phobos/config 5) Compile with your target C compiler: gen_config1.c->gen_config1, gen_math.c->gen_math, gen_unix.c->gen_unix 6) ON THE TARGET, run gen_config1, gen_math and gen_unix to generate the files frag-gen, frag-math and frag-unix respectively. 7) Put those files into some directory on your host. 8) cd gcc-<version> ; mkdir build ; cd build 9) ../configure --prefix=<whatever> --build=`../config.guess` --target=powerpc-603-linux-gnu --enable-phobos-config-dir=<directory-with-frag-files> 10) make all install That ought to give you what you want. Good luck! - Gregor Richards Disclaimer: This is off the top of my head. I've made several cross-compilers, but all of this is of course subject to memory degradation.
Feb 17 2007