?

Log in

No account? Create an account
Even siller things with cross-compilers, part 4 ((failing at) building GCC) - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Even siller things with cross-compilers, part 4 ((failing at) building GCC) [Sunday 22nd January 2012 at 9:36 pm]
Thomas

boggyb
[Tags|, ]
[Feeling |annoyedannoyed]

Part 4: (failing at) Building GCC

The MinGW distribution of GCC is a little different - their tarball contains a custom build script along with a second tarball inside with the actual sources. Since I'm building a cross-compiler I probably just want the actual GCC source and not their patches, so:

cd /cross/src
tar -xvf /mingw/var/cache/mingw-get/packages/gcc-4.6.1-2-mingw32-src.tar.lzma
tar -xvf gcc-4.6.1-2-mingw32-src/gcc-4.6.1.tar.bz2

And try and build the thing (remembering to use a relative path for configure to avoid epic fail). I don't have a proper glibc yet, so apparently the only language that'll work is plain C.

mkdir -p $PREFIX/build/gcc-4.6.1
cd $PREFIX/build/gcc-4.6.1
../../../src/gcc-4.6.1/configure --prefix=$PREFIX --target=$TARGET --with-sysroot=$SYSROOT --enable-languages=c
make
In file included from ../../../../../src/gcc-4.6.1/libgcc/../gcc/tsystem.h:87:0,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/libgcc2.c:29:
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/stdio.h:28:23: fatal error: features.h: No such file or directory
compilation terminated.
make[2]: *** [_muldi3.o] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-4.6.1/armv5l-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-4.6.1'
make: *** [all] Error 2

As usual, that failed part-way through compilation though this time the file genuinely doesn't exist. That header is present in both the glibc and gcc sources, so I'm not sure which one failed with it. I'll try copying it in and re-running the build.

cp /cross/src/glibc-2.2.5/include/features.h $SYSROOT/usr/include/
make
In file included from ../../../../../src/gcc-4.6.1/libgcc/../gcc/libgcc2.c:29:0:
../../../../../src/gcc-4.6.1/libgcc/../gcc/tsystem.h:93:19: fatal error: errno.h: No such file or directory
compilation terminated.
make[2]: *** [_muldi3.o] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-4.6.1/armv5l-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-4.6.1'
make: *** [all] Error 2

Wasn't glibc's make install-headers supposed to actually install the headers?

cp /cross/src/glibc-2.2.5/include/errno.h $SYSROOT/usr/include/
cp /cross/src/glibc-2.2.5/sysdeps/unix/sysv/linux/bits/errno.h $SYSROOT/usr/include/bits/
make
In file included from ../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr-posix.h:41:0,
                 from ../.././gcc/gthr-default.h:1,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr.h:162,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/unwind-dw2.c:37:
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/pthread.h:163:50: error: expected ';', ',' or ')' before '__thread'
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/pthread.h:591:1: error: storage class specified for unnamed parameter
In file included from C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/pthread.h:655:0,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr-posix.h:41,
                 from ../.././gcc/gthr-default.h:1,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr.h:162,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/unwind-dw2.c:37:
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/bits/sigthread.h:36:1: error: storage class specified for unnamed parameter
In file included from ../.././gcc/gthr-default.h:1:0,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr.h:162,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/unwind-dw2.c:37:
../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr-posix.h:122:1: error: 'pthread_create' undeclared here (not in a function)
../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr-posix.h: In function '__gthread_create':
../../../../../src/gcc-4.6.1/libgcc/../gcc/gthr-posix.h:663:35: error: called object '__gthrw_pthread_create' is not a function
make[2]: *** [unwind-dw2.o] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-4.6.1/armv5l-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-4.6.1'
make: *** [all] Error 2

That's a more epic fail, and it looks like something to do with Linux's threading support is missing. Hmm. Now, one of the howto's I'm basing this on suggested adding --disable-threads to the gcc configuration. Let's give that a try.

cd $PREFIX
rm -rf $PREFIX/build/gcc-4.6.1
mkdir -p $PREFIX/build/gcc-4.6.1
cd $PREFIX/build/gcc-4.6.1
../../../src/gcc-4.6.1/configure --prefix=$PREFIX --target=$TARGET --with-sysroot=$SYSROOT --enable-languages=c --disable-threads
make
In file included from ../../../../../src/gcc-4.6.1/libgcc/../gcc/tsystem.h:90:0,
                 from ../../../../../src/gcc-4.6.1/libgcc/../gcc/crtstuff.c:61:
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/sys/types.h:116:19: error: two or more data types in declaration specifiers
C:/MinGW/msys/1.0/cross/n2100/sysroot/usr/include/sys/types.h:116:26: error: expected identifier or '(' before ';' token
make[2]: *** [crtbegin.o] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-4.6.1/armv5l-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-4.6.1'
make: *** [all] Error 2

Aren't GCC error messages wonderful? The line in question reads typedef __caddr_t caddr_t; which looks perfectly fine - it's saying that the type caddr_t is really the type __caddr_t. Except what appears to have happened is the configure script in its infinite wisdom has created a header with #define caddr_t char * in it. The result is that the preprocessor merrily turns that typedef into typedef __caddr_t char *;. The compiler only sees the output from the preprocessor, and raises an error on that line. But since nothing normally saves the preprocessor output, when you investigate the error you see the original perfectly correct typedef and are left without any hint as to what went wrong.

It turns out that configure made that decision because the host sys/type.h doesn't have a definition for caddr_t. So when it did all it's umpteen "does the system support this" checks, the test for caddr_t failed and so it added in a #define. Unfortuantly the build process then builds against the target includes which does contain a definition, and so failed. Fortuantly, I'm not the first to run into this issue and there's a patch available to fix this. I've hacked it a bit so it works:

--- /mingw/include/sys/types.h.orig     2010-11-13 22:20:46.696332007 +0100
+++ /mingw/include/sys/types.h  2010-11-13 22:37:55.836332007 +0100
@@ -14,6 +14,9 @@
 /* All the headers include this file. */
 #include <_mingw.h>

+typedef int     daddr_t;
+typedef char *  caddr_t;
+
 #define __need_wchar_t
 #define __need_size_t
 #define __need_ptrdiff_t

Apply the patch, re-run configure, run make for the 5th time... and it fails yet again (C:\MinGW\msys\1.0\cross\n2100\armv5l-linux\bin\ld.exe: cannot find crti.o: No such file or directory). Fortuantly, this time at least the fix is explicitly given in one of the howtos. Applying this patch should make it actually build crti.o and crtn.o.

Or not.

/cross/n2100/armv5l-linux/bin/ranlib libgcc.a
# If the gcc directory specifies which extra parts to
# build for this target, and the libgcc configuration also
# specifies, make sure they match.  This can be removed
# when the gcc directory no longer holds libgcc configuration;
# it is useful when migrating a target.
Configuration mismatch!
Extra parts from gcc directory: crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crti.o crtn.o
Extra parts from libgcc: crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o
exit 1
make[2]: *** [libgcc-extra-parts] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-4.6.1/armv5l-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-4.6.1'
make: *** [all] Error 2

This will require some thought.

Link | Previous Entry | Share | Next Entry[ Penny for your thoughts? ]