Howto: Set up a Rumprun toolchain in Mac OS X

Brien Wankel edited this page Jul 29, 2016 · 8 revisions
Clone this wiki locally

This page details the extra steps required to obtain a Rumprun toolchain in OS X. For a complete tutorial on building a Rumprun Unikernel please see Rumprun unikernel tutorial and return here when directed.


The built in tools in OS X are not able to build the Rumprun platform, because they generate executables in the Mach-O format. So to obtain a Rumprun toolchain in OS X we have 2 options:

  • Use a prebuilt toolchain in Docker.
  • Build a compatible compiler in OS X and then build Rumprun using that compiler.

The rest of this page details option 2.

Build an ELF cross-compiler

With NetBSD and

Warning: since NetBSD 7.0 ships with ld 2.23 instead of the required ld 2.25, this method should be avoided for now. PLease build the toolchain manually

A simple way to get an ELF cross-compiler for OS X is to build the tools from the NetBSD sources using

$ mkdir netbsd
$ cd netbsd
$ curl -OOOO{share,gnu,sys,}src.tgz
$ for file in *.tgz; do tar -xzf $file; done
$ cd usr/src
$ ./ -U -T elftools.x86_64 -m amd64 tools
[... much compiling ...]

This should result in a toolchain being available in elftools.x86_64/bin.

Build Rumprun

Add the toolchain you built above to your $PATH. While we're here we'll also set the location of the readelf command, as we'll need that later:

$ export PATH=$PWD/elftools.x86_64/bin:$PATH
$ export READELF=$PWD/elftools.x86_64/bin/x86_64--netbsd-readelf

You can now tell to use the above compiler and tools by setting the $CC variable.

$ env CC=x86_64--netbsd-gcc ./ hw


To build the toolchain, you mainly need to compile binutils and gcc:

# we need a proper GCC to build another one
brew update
brew install gcc

# the directory for the generated files
mkdir toolchain

#required environment variables
export PREFIX=$PWD/toolchain
export TARGET=x86_64-netbsd
export CC=/usr/local/bin/gcc-6
export CXX=/usr/local/bin/g++-6
export LD=/usr/local/bin/gcc-6
export CFLAGS=-Wno-error=deprecated-declarations

# Download and build binutils

curl -O
tar xvf binutils-2.26.1.tar.gz 
cd binutils-2.26.1
./configure --prefix=$PREFIX --target=$TARGET --disable-nls
make install

cd ..

# Download and build GCC

curl -O
tar xvzf gcc-6.1.0.tar.gz 
cd gcc-6.1.0
./configure --prefix=$PREFIX --target=$TARGET --disable-nls --enable-languages=c --without-headers
make all-gcc
make install-gcc

# Delete the content of env variables, or it will break Rumprun compilation
export CFLAGS=
export CXX=
export LD=

Build Rumprun

Then, add the toolchain to the path:

export PATH=$PREFIX/bin:$PATH
export READELF=$PREFIX/bin/x86_64-netbsd-readelf

You can now tell to use the above compiler and tools by setting the $CC variable.

$ env CC=x86_64-netbsd-gcc ./ hw


At this point you should be able to eg. continue the Rumprun unikernel tutorial as per the instructions. You'll need to set the $READELF variable to use rumprun or rumprun-bake.