An excerpt from the repository, fetched Nov 13, 2026.
Read the project’s introduction
What is XNU?
XNU kernel is part of the Darwin operating system for use in macOS and iOS operating systems. XNU is an acronym for X is Not Unix.
XNU is a hybrid kernel combining the Mach kernel developed at Carnegie Mellon University with components from FreeBSD and a C++ API for writing drivers called IOKit.
XNU runs on x86_64 for both single processor and multi-processor configurations.
XNU Source Tree
config - configurations for exported apis for supported architecture and platform
SETUP - Basic set of tools used for configuring the kernel, versioning and kextsymbol management.
EXTERNAL_HEADERS - Headers sourced from other projects to avoid dependency cycles when building. These headers should be regularly synced when source is updated.
libkern - C++ IOKit library code for handling of drivers and kexts.
libsa - kernel bootstrap code for startup
libsyscall - syscall library interface for userspace programs
libkdd - source for user library for parsing kernel data like kernel chunked data.
makedefs - top level rules and defines for kernel build.
osfmk - Mach kernel based subsystems
pexpert - Platform specific code like interrupt handling, atomics etc.
security - Mandatory Access Check policy interfaces and related implementation.
bsd - BSD subsystems code
tools - A set of utilities for testing, debugging and profiling kernel.
How to build XNU
Building DEVELOPMENT kernel
The xnu make system can build kernel based on KERNEL_CONFIGS & ARCH_CONFIGS variables as arguments.
Here is the syntax:
make SDKROOT=<sdkroot> ARCH_CONFIGS=<arch> KERNEL_CONFIGS=<variant>
Where:
<sdkroot>: path to macOS SDK on disk. (defaults to /)
<variant>: can be debug, development, release, profile and configures compilation flags and asserts throughout kernel code.
<arch> : can be valid arch to build for. (E.g. X86_64)
To build a kernel for the same architecture as running OS, just type
$ make
$ make SDKROOT=macosx.internal
Additionally, there is support for configuring architectures through ARCH_CONFIGS and kernel configurations with KERNEL_CONFIGS.
$ make SDKROOT=macosx.internal ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=DEVELOPMENT
$ make SDKROOT=macosx.internal ARCH_CONFIGS=X86_64 KERNEL_CONFIGS="RELEASE DEVELOPMENT DEBUG"
Note:
By default, architecture is set to the build machine architecture, and the default kernel
config is set to build for DEVELOPMENT.
This will also create a bootable image, kernel.[config], and a kernel binary
with symbols, kernel.[config].unstripped.
To intall the kernel into a DSTROOT, use the install_kernels target:
$ make install_kernels DSTROOT=/tmp/xnu-dst
Hint:
For a more satisfying kernel debugging experience, with access to all
local variables and arguments, but without all the extra check of the
DEBUG kernel, add something like:
CFLAGS_DEVELOPMENTARM64="-O0 -g -DKERNEL_STACK_MULTIPLIER=2"
CXXFLAGS_DEVELOPMENTARM64="-O0 -g -DKERNEL_STACK_MULTIPLIER=2"
to your make command.
Replace DEVELOPMENT and ARM64 with the appropriate build and platform.
To build with RELEASE kernel configuration
make KERNEL_CONFIGS=RELEASE SDKROOT=/path/to/SDK
Building FAT kernel binary
Define architectures in your environment or when running a make command.
$ make ARCH_CONFIGS="X86_64" exporthdrs all
Other makefile options
$ make MAKEJOBS=-j8 # this will use 8 processes during the build. The default is 2x the number of active CPUS.
$ make -j8 # the standard command-line option is also accepted
$ make -w # trace recursive make invocations. Useful in combination with VERBOSE=YES
$ make BUILD_LTO=0 # build without LLVM Link Time Optimization
$ make REMOTEBUILD=user@remotehost # perform build on remote host
$ make BUILD_JSON_COMPILATION_DATABASE=1 # Build Clang JSON Compilation Database
The XNU build system can optionally output color-formatted build output. To enable this, you can either
set the XNU_LOGCOLORS environment variable to y, or you can pass LOGCOLORS=y to the make command.
Debug information formats
By default, a DWARF debug information repository is created during the install phase; this is a "bundle" named kernel.development.<variant>.dSYM
To select the older STABS debug information format (where debug information is embedded in the kernel.development.unstripped image), set the BUILD_STABS environment variable.
$ export BUILD_STABS=1
$ make
Building KernelCaches
To test the xnu kernel, you need to build a kernelcache that links the kexts and
kernel together into a single bootable image.
To build a kernelcache you can use the following mechanisms:
Using automatic kernelcache generation with kextd.
The kextd daemon keeps watching for changing in /System/Library/Extensions directory.
So you can setup new kernel as
$ cp BUILD/obj/DEVELOPMENT/X86_64/kernel.development /System/Library/Kernels/
$ touch /System/Library/Extensions
$ ps -e | grep kextd
Manually invoking kextcache to build new kernelcache.
$ kextcache -q -z -a x86_64 -l -n -c /var/tmp/kernelcache.test -K /var/tmp/kernel.test /System/Library/Extensions
Running KernelCache on Target machine
The development kernel and iBoot supports configuring boot arguments so that we can safely boot into test kernel and, if things go wrong, safely fall back to previously used kernelcache.
Following are the steps to get such a setup:
Create kernel cache using the kextcache command as /kernelcache.test
Copy exiting boot configurations to alternate file
$ cp /Library/Preferences/SystemConfiguration/com.apple.Boot.plist /next_boot.plist
Update the kernelcache and boot-args for your setup
$ plutil -insert "Kernel Cache" -string "kernelcache.test" /next_boot.plist
$ plutil -replace "Kernel Flags" -string "debug=0x144 -v kernelsuffix=test " /next_boot.plist
Copy the new config to /Library/Preferences/SystemConfiguration/
$ cp /next_boot.plist /Library/Preferences/SystemConfiguration/boot.plist
Bless the volume with new configs.
$ sudo -n bless --mount / --setBoot --nextonly --options "config=boot"
T
Read the full README on GitHub