Skip to content →

i386-jos-elf toolchain on OS X Lion

Yesterday friend and I decided to follow the MIT Operating System Engineering course together in order to get a deep understanding of OS’s. And today I started setting up the cross compling environment for the labs. At first I wanted to get the toolchain from macports, but unluckily it didn’t successfully build binutils on my Mac. As a result, I started building the toolchain from the source code, following the instructions at http://pdos.csail.mit.edu/6.828/2011/tools.html.

The programs you need for the toolchain include binutils, gcc, and gdb. For compiling gcc you also need GMP, MPFR, and MPC. The source codes are available at:

wget http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2
wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2
wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz
wget http://ftpmirror.gnu.org/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2
wget http://ftpmirror.gnu.org/gdb/gdb-6.8a.tar.gz

Unzip them in a directory and build binutils, gcc, and gdb one by one.

$ tar jxvf binutils-2.21.1.tar.bz2
$ cd binutils-2.21.1
$ ./configure --target=i386-jos-elf --disable-nls && make && sudo make install

In order to build gcc, GMP, MPFR and MPC needs to be built first.

$ mkdir -p libs/install
$ mv gmp-5.0.4.tar.bz2 mpfr-3.1.0.tar.bz2 mpc-0.8.2.tar.gz libs/
$ tar jxvf gmp-5.0.4.tar.bz2
$ mkdir gmp-build; cd gmp-build
$ ../gmp-5.0.4/configure --prefix=$(cd ../install && pwd)
$ make && sudo make install
$ cd ..
$ tar jxvf mpfr-3.1.0.tar.bz2
$ mkdir mpfr-build; cd mpfr-build
$ ../mpfr-3.1.0/configure --prefix=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make && sudo make install
$ cd ..
$ tar zxvf mpc-0.8.2.tar.gz
$ mkdir mpc-build; cd mpc-build
$ ./configure --prefix=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpfr=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make ; sudo make install
$ cd ..
$ tar jxvf gcc-core-4.5.1.tar.bz2
$ mkdir gcc-build; cd gcc-build
$ ../gcc-4.5.1/configure --target=i386-jos-elf --disable-nls --without-headers --with-newlib --disable-threads --disable-shared --disable-libmudflap --disable-libssp --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpfr=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpc=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make ; sudo make install

Note that it’s essential to build gcc in a directory different from the source code directory to avoid compiling errors.

Then make gdb:

$ tar zxvf gdb-6.8a.tar.gz
$ mkdir gdb-build; cd gdb-build
$ ../gdb-6.8/./configure --target=i386-jos-elf --program-prefix=i386-jos-elf- --disable-werror
$ make && sudo make install

QEMU is available in macports:

$ sudo port install qemu

Published in OS

15 Comments

  1. Anonymous

    Thanks for your post. really helped me a lot!

  2. Anonymous

    Thanks for your post. really helped me a lot!

  3. Thank you! It worked like a charm! Now debugging with qemu and DDD. 🙂

  4. Thank you! It worked like a charm! Now debugging with qemu and DDD. 🙂

  5. Bianca

    Maybe it’s a problem with kernel compilation without parameter – g, but I don’t know how to solve it.

  6. Bianca

    Maybe it’s a problem with kernel compilation without parameter – g, but I don’t know how to solve it.

  7. Bianca

    Hi! Thank you for the reply. Now it’s working, but I still am having some problems with symbol table, this is the error message I received when I launch gdb:
    “+ symbol-file obj/kern/kernel
    .gdbinit:30: Error in sourced command file:
    “/Users/username/jos/lab/obj/kern/kernel”: can’t read symbols: File format not recognized.”

    Could you maybe help me?

    Thanks a lot!

    • Hi Bianca, I’m not sure what causes the problem, so I’m afraid I’m not able to help, sorry…

  8. Bianca

    Hi! Thank you for the reply. Now it’s working, but I still am having some problems with symbol table, this is the error message I received when I launch gdb:
    “+ symbol-file obj/kern/kernel
    .gdbinit:30: Error in sourced command file:
    “/Users/username/jos/lab/obj/kern/kernel”: can’t read symbols: File format not recognized.”

    Could you maybe help me?

    Thanks a lot!

  9. Hi, sorry for my late reply. I think `i386-elf-gcc` is available on macports, maybe you can try `sudo port install i386-elf-gcc`?

  10. Hi, sorry for my late reply. I think `i386-elf-gcc` is available on macports, maybe you can try `sudo port install i386-elf-gcc`?

  11. Bianca

    Hi!!
    I have to follow the Mit Operating System Course and I am using a MacBook Air. I followed your precious advices but I am not able to compile binutils because I receive this error: make[1]: Nothing to be done for `all-target’.

    Could you please help me?

  12. Bianca

    Hi!!
    I have to follow the Mit Operating System Course and I am using a MacBook Air. I followed your precious advices but I am not able to compile binutils because I receive this error: make[1]: Nothing to be done for `all-target’.

    Could you please help me?

Leave a Reply to Bianca Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.