The Path of Pain: mips64-elf-gcc on Darwin

This document takes you through compiling a mips64 crosscompiler for OS X. Specifically it takes you through the type of cross compiler required to build binaries for Mungi on MIPS. If you're just here to build a gcc cross compiler (or indeed a gcc native compiler) on OS X the key thing to note is the "-no-cpp-precomp" flag to GCC. If you are here for Mungi, but you can't be bothered doing this tedious compile job I recommend downloading the prebuilt binaries below.

Using the binaries

Building from Source

Okay, if you'd prefer to do it the hard way...

Set an environment variable

The first thing you should do is ensure that you don't use precompiled headers. For whatever stupid reason, the gcc that Apple distributes with OS X 10.2 can't compile GCC with precompiled headers turned on.

export CC="gcc -no-cpp-precomp"

Build binutils

I used binutils-2.13.2. Grab it and extract it somewhere...

Now follow Chris' instructions to include support for the 64-bit BFD, which I will reproduce here for your convenience. Edit bfd/config.bfd to include the following:

#ifdef BFD64
  mips64*-*-elf*)
    targ_defvec=bfd_elf64_bigmips_vec
    targ_selvecs="bfd_elf32_littlemips_vec bfd_elf32_bigmips_vec bfd_elf64_littlemips_vec"
    ;;  
#endif
There is a convenient place for this just before mips*-*-irix6*, which is already inside the relevant #ifdef.

Now configure and make the thing!

./configure --target=mips64-elf --prefix=/usr/local/mips64-elf-xdev --enable-64bit-bfd

make all
sudo make install

Now stick that directory in your path. You probably want to do this inside a .bashrc or equivalent, too...

export PATH=$PATH:/usr/local/mips64-elf-xdev/bin

Build GCC

Now for GCC. I used gcc-3.2.2.tar.gz from the GNU mirrors. Extract it, enter the new directory, and apply Dan's magic patch: (Note that this simply does the stuff that Chris mentions on the page linked above to setup GCC to use a 64bit bfd. This patch is also available from Chris' page so check there for updates)

patch -p3 <wherever-you-put-the-patch

This patch adds the 64-bit BFD to GCC as well.

Now configure and make that thing!

export CFLAGS="-Dinhibit_libc"

./configure --prefix=/usr/local/mips64-elf-xdev --target=mips64-elf --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-64bit-bfd --program-prefix=mips64-elf-

make all-gcc
sudo make install all-gcc

If you get a whole lot of syntax-ish errors, chances are you didn't define CC as "gcc -no-cpp-precomp". If you get warnings about "not valid for this BFD" then chances are your binutils aren't compiled with 64bit-bfd support. Even if you get everything right you'll get a few warnings about traditional C not liking this and ANSI C disagreeing with that, not to mention signed/unsigned comparisons blah blah blah.

Other bits

While you're here, if you're interested in compiling Mungi, you'll need the pax compiler, which compiles fine as long as you set the platform to "OSF" in the Makefile and include <sys/malloc.h> rather than <malloc.h> in parser/lex.yy.c.

Similarly, dite (part of l4alpha) uses some tricksy #defines which confuse the "smart" preprocessor. Just exporting CC doesn't work here; you'll need to modify dite/src/Makefile or supply a parameter to ./configure .

Unfortunately, the MIPS simulator that DiSY uses, Sulima, doesn't yet work properly on big-endian architectures, so you'll have to use real hardware or a Linux box running the sim for now. Good luck.

- Nicholas FitzRoy-Dale Fri Aug 15 01:55:12 EST 2003