Thomas (boggyb) wrote,
Thomas
boggyb

  • Mood:
  • Music:

Slightly less silly things with cross-compilers, part 4a (successfully building GCC)

Part 4a: Successfully building GCC

Since compiling with gcc 4.6.1 was a) made of epic fail, and b) would have probably not worked anyway, I've given up on it. Instead I'm going to try building gcc 3.3.3, since that's the closest version that MinGW have available.

Begin by grabbing the src packages for gcc-core and gcc-g++ from the MinGW website and save them in C:\MinGW\var\cache\mingw-get\packages. Then pull up the MinGW shell, and unpack them somewhere sensible:

cd /cross/src/
tar -xvf /mingw/var/cache/mingw-get/packages/gcc-g++-3.3.3-200402017-1-src.tar.gz
tar -xvf /mingw/var/cache/mingw-get/packages/gcc-core-3.3.3-200402017-1-src.tar.gz

Run configure with some hopefully-sensible options, then cross your fingers and start the build.

mkdir -p $PREFIX/build/gcc-3.3.3
cd $PREFIX/build/gcc-3.3.3
../../../src/gcc-3.3.3-200402017-1/configure --prefix=$PREFIX --target=$TARGET --with-sysroot=$SYSROOT --enable-languages=c --disable-threads
make
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/stdint.h:3:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include/process.h:18,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include/unistd.h:13,
                 from ../../../../src/gcc-3.3.3-200402017-1/libiberty/getpwd.c:30:
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include/stdint.h:75:24: error: duplicate 'unsigned'
make[1]: *** [getpwd.o] Error 1
make[1]: Leaving directory `/cross/n2100/build/gcc-3.3.3/libiberty'
make: *** [all-libiberty] Error 2

Well, that was never going to work on the first try. Some digging shows that configure has (incorrectly) decided that I don't have an uintptr_t type, and so it substituted its own in the form of a #define. The C pre-processor as a result merrily destroyed the perfectly valid typedef, and the C compiler then spat out an almost completely useless error message. By the looks of things, the root cause this time is that the configure script was generated with a version of autoconf that predates the C99 standard.

--- /cross/src/gcc-3.3.3-200402017-1/libiberty/configure.orig   2012-01-26 20:07:53 +0000
+++ /cross/src/gcc-3.3.3-200402017-1/libiberty/configure        2012-01-26 20:11:25 +0000
@@ -1621,6 +1621,7 @@
 #line 1622 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
+#include <stdint.h>
 #if STDC_HEADERS
 #include <stdlib.h>
 #include <stddef.h>
cd $PREFIX/build
rm -rf $PREFIX/build/gcc-3.3.3
mkdir -p $PREFIX/build/gcc-3.3.3
cd $PREFIX/build/gcc-3.3.3
../../../src/gcc-3.3.3-200402017-1/configure --prefix=$PREFIX --target=$TARGET --with-sysroot=$SYSROOT --enable-languages=c --disable-threads
make
../../../../src/gcc-3.3.3-200402017-1/gcc/read-rtl.c: In function 'read_rtx':
../../../../src/gcc-3.3.3-200402017-1/gcc/read-rtl.c:653:8: error: lvalue required as increment operand
make[1]: *** [read-rtl.o] Error 1
make[1]: Leaving directory `/cross/n2100/build/gcc-3.3.3/gcc'
make: *** [all-gcc] Error 2

Fortunately I don't have to poke around in the depths of gcc to fix this one, because someone else has already solved it:

It's a problem. Older versions of gcc use a construct which newer versions of gcc won't compile. This makes it hard to bootstrap older versions of gcc with newer versions. This is indeed an absurd situation.
RCS file: /cvsroot/src/gnu/dist/gcc/include/obstack.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 obstack.h
--- obstack.h   23 Jul 2003 02:42:35 -0000      1.1.1.1
+++ obstack.h   22 Jan 2006 12:41:15 -0000
@@ -423,7 +423,8 @@
 ({ struct obstack *__o = (OBSTACK);                                    \
    if (__o->next_free + sizeof (void *) > __o->chunk_limit)            \
      _obstack_newchunk (__o, sizeof (void *));                         \
-   *((void **)__o->next_free)++ = ((void *)datum);                     \
+   *((void **)__o->next_free) = ((void *)datum);                       \
+   __o->next_free += sizeof(void *);                                   \
    (void) 0; })

 # define obstack_int_grow(OBSTACK,datum)                               \

Apply the patch (replacing the spaces before the backslashes with actual tabs), and try again.

collect2.o: In function `handler':
C:\MinGW\msys\1.0\cross\n2100\build\gcc-3.3.3\gcc/../../../../src/gcc-3.3.3-200402017-1/gcc/collect2.c:447: undefined reference to `kill'
collect2.o: In function `scan_prog_file':
C:\MinGW\msys\1.0\cross\n2100\build\gcc-3.3.3\gcc/../../../../src/gcc-3.3.3-200402017-1/gcc/collect2.c:2091: undefined reference to `pipe'
C:\MinGW\msys\1.0\cross\n2100\build\gcc-3.3.3\gcc/../../../../src/gcc-3.3.3-200402017-1/gcc/collect2.c:2114: undefined reference to `fork'
collect2: ld returned 1 exit status
make[1]: *** [collect2.exe] Error 1
make[1]: Leaving directory `/cross/n2100/build/gcc-3.3.3/gcc'
make: *** [all-gcc] Error 2

Computer says noooo. Fortunately yet another kind soul has encountered this and posted a solution. Apparently there's two potential pitfalls, so I'll fix both of them before I continue.

--- gcc/Makefile.orig   2012-01-26 20:26:33 +0000
+++ gcc/Makefile        2012-01-26 20:30:22 +0000
@@ -270,7 +270,7 @@

 # Control whether to run fixproto and fixincludes.
 STMP_FIXPROTO = stmp-fixproto
-STMP_FIXINC = stmp-fixinc
+STMP_FIXINC =

 # Test to see whether <limits.h> exists in the system header files.
 LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ]
@@ -440,7 +440,7 @@

 # It is convenient for configure to add the assignment at the beginning,
 # so don't override it here.
-USE_COLLECT2 = collect2$(exeext)
+USE_COLLECT2 =

 # List of extra C and assembler files to add to static and shared libgcc2.
 # Assembler files should have names ending in `.asm'.
C:\MinGW\msys\1.0\cross\n2100\armv5l-linux\bin\ld.exe: cannot find crti.o: No such file or directory
C:\MinGW\msys\1.0\cross\n2100\armv5l-linux\bin\ld.exe: cannot find -lc
C:\MinGW\msys\1.0\cross\n2100\armv5l-linux\bin\ld.exe: cannot find crtn.o: No such file or directory
make[2]: *** [libgcc_s.so] Error 1
make[2]: Leaving directory `/cross/n2100/build/gcc-3.3.3/gcc'
make[1]: *** [libgcc.a] Error 2
make[1]: Leaving directory `/cross/n2100/build/gcc-3.3.3/gcc'
make: *** [all-gcc] Error 2

Now, this looks more familiar. With any luck, the same patch as last time should work as well. So, apply it, then blow away the build directory and start again with configure. Fix the Makefile with the previous patch, then run make once again. And at long last it works!

make install

Next step: compiling glibc for real, with the cross-compiler.

Tags: computing, nas adventures
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments