Friday, December 11, 2015

Building xnu for OS X 10.11 El Capitan

The OS X kernel source (xnu) has been released for OS X 10.11 El Capitan: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:


  1. Install OS X El Capitan and Xcode 7.0, 7.1, or 7.2 from the Mac App Store, make sure the Xcode license has been agreed-to with "sudo xcodebuild -license"
  2. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O https://opensource.apple.com/tarballs/dtrace/dtrace-168.tar.gz
    $ curl -O https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-20.tar.gz
    $ curl -O https://opensource.apple.com/tarballs/xnu/xnu-3247.1.106.tar.gz
  3. Build and install CTF tools from dtrace
    $ tar zxf dtrace-168.tar.gz
    $ cd dtrace-168
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
    Password:
    $ cd ..
    
  4. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-20.tar.gz 
    $ cd AvailabilityVersions-20
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local `xcrun -sdk macosx -show-sdk-path`/usr/local
    $ cd ..
    
  5. Build xnu
    $ tar zxf xnu-3247.1.106.tar.gz
    $ cd xnu-3247.1.106
    $ make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE
See xnu's top-level README for additional build variables that can be passed on the command-line, such as BUILD_LTO=0 or KERNEL_CONFIGS=DEVELOPMENT .

Update: If you are attempting to add system calls, you may also need to build Libsyscall.


  1. Download the Libsystem source
    $ curl -O https://opensource.apple.com/tarballs/Libsystem/Libsystem-1225.1.1.tar.gz
    
  2. Install Libsystem headers
    $ tar zxf Libsystem-1225.1.1.tar.gz
    $ cd Libsystem-1225.1.1
    $ xcodebuild installhdrs -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst `xcrun -sdk macosx -show-sdk-path`
    $ cd ..
    
  3. Install xnu and Libsyscall headers
    $ cd xnu-3247.1.106
    $ mkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst
    $ make installhdrs SDKROOT=macosx ARCH_CONFIGS=X86_64 SRCROOT=$PWD OBJROOT=$PWD/BUILD.hdrs/obj SYMROOT=$PWD/BUILD.hdrs/sym DSTROOT=$PWD/BUILD.hdrs/dst
    $ sudo xcodebuild installhdrs -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD/libsyscall OBJROOT=$PWD/BUILD.hdrs/obj SYMROOT=$PWD/BUILD.hdrs/sym DSTROOT=$PWD/BUILD.hdrs/dst
    $ sudo ditto BUILD.hdrs/dst `xcrun -sdk macosx -show-sdk-path`
  4. Build Libsyscall
    $ mkdir -p BUILD.libsyscall/obj BUILD.libsyscall/sym BUILD.libsyscall/dst
    $ sudo xcodebuild install -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD/libsyscall OBJROOT=$PWD/BUILD.libsyscall/obj SYMROOT=$PWD/BUILD.libsyscall/sym DSTROOT=$PWD/BUILD.libsyscall/dst
    
  5. To install custom OS components, System Integrity Protection must be disabled.
  6. To install the resulting new binaries, execute:
    1. xnu:
      $ sudo cp BUILD/obj/RELEASE_X86_64/kernel /System/Library/Kernels/
      $ sudo kextcache -invalidate /
      / locked; waiting for lock.
      Lock acquired; proceeding.
      ...
      $ sudo reboot
      
    2. Libsyscall:
      $ sudo cp BUILD.libsyscall/dst/usr/lib/system/libsystem_kernel.dylib /usr/lib/system/
      $ sudo update_dyld_shared_cache
      ...
      $ sudo reboot
      

Friday, October 31, 2014

Building xnu for OS X 10.10 Yosemite

The OS X kernel source (xnu) has been released for OS X 10.10 Yosemite: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:


  1. Install OS X Yosemite and Xcode 6.1 from the Mac App Store, make sure the Xcode license has been agreed-to with "sudo xcodebuild -license"
  2. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O http://opensource.apple.com/tarballs/dtrace/dtrace-147.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-9.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/xnu/xnu-2782.1.97.tar.gz
  3. Build and install CTF tools from dtrace
    $ tar zxf dtrace-147.tar.gz
    $ cd dtrace-147
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..
    
  4. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-9.tar.gz
    $ cd AvailabilityVersions-9
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local `xcrun -sdk macosx -show-sdk-path`/usr/local
    $ cd ..
    
  5. Build xnu
    $ tar zxf xnu-2782.1.97.tar.gz
    $ cd xnu-2782.1.97
    $ make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE
See xnu's top-level README for additional build variables that can be passed on the command-line, such as BUILD_LTO=0 .

Update: If you are attempting to add system calls, you may also need to build Libsyscall.


  1. Download the Libsystem source
    $ curl -O http://opensource.apple.com/tarballs/Libsystem/Libsystem-1213.tar.gz
    
  2. Install Libsystem headers
    $ tar zxf Libsystem-1213.tar.gz 
    $ cd Libsystem-1213
    $ xcodebuild installhdrs -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst `xcrun -sdk macosx -show-sdk-path`
    $ cd ..
    
  3. Install xnu and Libsyscall headers
    $ cd xnu-2782.1.97
    $ mkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst
    $ make installhdrs SDKROOT=macosx ARCH_CONFIGS=X86_64 SRCROOT=$PWD OBJROOT=$PWD/BUILD.hdrs/obj SYMROOT=$PWD/BUILD.hdrs/sym DSTROOT=$PWD/BUILD.hdrs/dst
    $ xcodebuild installhdrs -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD/libsyscall OBJROOT=$PWD/BUILD.hdrs/obj SYMROOT=$PWD/BUILD.hdrs/sym DSTROOT=$PWD/BUILD.hdrs/dst
    $ sudo ditto BUILD.hdrs/dst `xcrun -sdk macosx -show-sdk-path`
  4. Build Libsyscall
    $ mkdir -p BUILD.libsyscall/obj BUILD.libsyscall/sym BUILD.libsyscall/dst
    $ xcodebuild install -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD/libsyscall OBJROOT=$PWD/BUILD.libsyscall/obj SYMROOT=$PWD/BUILD.libsyscall/sym DSTROOT=$PWD/BUILD.libsyscall/dst
    

Wednesday, October 23, 2013

Building xnu for OS X 10.9 Mavericks

The OS X kernel source (xnu) has been released for OS X 10.9 Mavericks: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:


  1. Install OS X Mavericks and Xcode 5.0.1, make sure the Xcode license has been agreed-to with "sudo xcodebuild -license"
  2. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O http://opensource.apple.com/tarballs/dtrace/dtrace-118.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-6.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/xnu/xnu-2422.1.72.tar.gz
  3. Build and install CTF tools from dtrace
    $ tar zxf dtrace-118.tar.gz
    $ cd dtrace-118
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..
    
  4. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-6.tar.gz
    $ cd AvailabilityVersions-6
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local `xcrun -sdk / -show-sdk-path`/usr/local
    $ cd ..
    
  5. Build xnu
    $ tar zxf xnu-2422.1.72.tar.gz
    $ cd xnu-2422.1.72
    $ make ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE

Tuesday, July 31, 2012

Building xnu for OS X 10.8 Mountain Lion

The OS X kernel source (xnu) has been released for OS X 10.8 Mountain Lion: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:


  1. Install OS X Mountain Lion and Xcode 4.4
  2. Launch Xcode, go to Preferences... > Downloads and install the Command Line Tools
  3. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O http://opensource.apple.com/tarballs/dtrace/dtrace-96.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-4.2.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/xnu/xnu-2050.7.9.tar.gz
  4. Build and install CTF tools from dtrace
    $ tar zxf dtrace-96.tar.gz
    $ cd dtrace-96
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..
    
  5. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-4.2.tar.gz
    $ cd AvailabilityVersions-4.2
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local /usr/local
    $ cd ..
    
  6. Build xnu
    $ tar zxf xnu-2050.7.9.tar.gz 
    $ cd xnu-2050.7.9
    $ make ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE
    
Update: If you are using Xcode 4.6, add CWARNFLAGS_STD="-Wall" CXXWARNFLAGS_STD="-Wall" to your make(1) invocation to avoid new warnings-as-errors

Thursday, July 21, 2011

Building xnu with clang


You can build xnu with clang from Xcode 4.1 by doing:

$ make ARCH_CONFIGS="X86_64 I386" CC=clang CXX=clang++ CWARNFLAGS_STD="-Wall" CXXWARNFLAGS_STD="-Wall"

Building xnu for Mac OS X 10.7


The Mac OS X kernel source (xnu) has been released for Mac OS X 10.7 Lion: 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://opensource.apple.com/tarballs/dtrace/dtrace-90.tar.gz
    $ curl -s -O http://opensource.apple.com/tarballs/bootstrap_cmds/bootstrap_cmds-79.tar.gz

  2. Unpack the tools

    $ tar zxf dtrace-90.tar.gz
    $ tar zxf bootstrap_cmds-79.tar.gz

  3. Build dtrace

    $ cd dtrace-90
    $ 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 ..

  4. Build bootstrap_cmds

    $ cd bootstrap_cmds-79
    $ mkdir -p obj sym dst
    $ make install RC_ARCHS="i386" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    ...
    $ sudo ditto $PWD/dst/usr/local /usr/local
    Password:
    $ cd ..

  5. Download the xnu source

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

  6. Unpack xnu

    $ tar zxf xnu-1699.22.73.tar.gz

  7. Build xnu

    $ cd xnu-1699.22.73
    $ 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

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