Thursday, September 10, 2009

The Mac OS X kernel source (xnu) has been released for Mac OS X 10.6 Snow Leopard: here

Building xnu requires some open source (but not pre-installed) tools. Darwinbuild is the most reliable way for building these dependencies and xnu itself. Until that is ready, you can build the tools manually as follows:

  1. Download the build tools source(s)

    $ curl -s -O http://www.opensource.apple.com/tarballs/cxxfilt/cxxfilt-9.tar.gz
    $ curl -s -O http://www.opensource.apple.com/tarballs/dtrace/dtrace-78.tar.gz
    $ curl -s -O http://www.opensource.apple.com/tarballs/kext_tools/kext_tools-177.tar.gz
    $ curl -s -O http://www.opensource.apple.com/tarballs/bootstrap_cmds/bootstrap_cmds-72.tar.gz

  2. Unpack the tools

    $ tar zxf cxxfilt-9.tar.gz
    $ tar zxf dtrace-78.tar.gz
    $ tar zxf kext_tools-177.tar.gz
    $ tar zxf bootstrap_cmds-72.tar.gz

  3. Build cxxfilt

    $ cd cxxfilt-9
    $ mkdir -p obj sym dst
    $ make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..

  4. Build dtrace

    $ cd dtrace-78
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..

  5. Build kext_tools

    $ cd kext_tools-177
    $ mkdir -p obj sym dst
    $ xcodebuild install -target kextsymboltool -target setsegname ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..

  6. Build bootstrap_cmds

    $ cd bootstrap_cmds-72
    $ mkdir -p obj sym dst
    $ make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..

  7. Download the xnu source

    $ curl -s -O http://www.opensource.apple.com/tarballs/xnu/xnu-1456.1.26.tar.gz

  8. Unpack xnu

    $ tar zxf xnu-1456.1.26.tar.gz

  9. Build xnu

    $ cd xnu-1456.1.26
    $ make ARCH_CONFIGS="I386 X86_64" KERNEL_CONFIGS="RELEASE"
    ...
    $ file BUILD/obj/RELEASE_*/mach_kernel
    BUILD/obj/RELEASE_I386/mach_kernel: Mach-O executable i386
    BUILD/obj/RELEASE_X86_64/mach_kernel: Mach-O 64-bit executable x86_64

3 comments:

Unknown said...

Thanks for the instructions. They work great. Only problem is that when I install the new mach_kernel, my test machine takes approx. 10 minutes to boot. Actually, boot is ok, but it seems to hang once SecurityAgent launches. There seems to be some kind of timeout occuring.

Furious ksc91u said...

Hi, I have the same problem as Breetai.

Also I found there is a message in dmesg.

display: Not usable

The blue screen shows up, and wait for a few minutes, then background then login window.

Any idea what is going on?

Thanks for the guide.

Unknown said...

Hi, I tried to compile OS X 10.12, but there is an error as follows:

fatal error:
'os/firehose_buffer_private.h' file not found

Did you have a try to compile 10.12 and have the same problem?

Thanks.