Skip to content

Building XNU

Alexander Bradley edited this page Oct 4, 2018 · 4 revisions

Building XNU for Arm64/Aarch64

Getting SDK ready

WARNING: This will make Xcode useless for iOS Apps.

There are a few tools needed in order to successfully build XNU, and a lot of headers are missing. This guide will help you get most of them.

Defines

To make things easier, let's just define some useful variables

SDKPATH

SDKPATH="$(xcrun --sdk iphoneos --show-sdk-path)"

TOOLCHAINPATH

TOOLCHAINPATH="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"

Installing necessary Tools & SDKs

Tools needed:

  • dtrace

Missing headers

  • AvailabilityVersions
  • libplatform
  • libdispatch

Getting sources

mkdir Dependencies && cd ./Dependencies
git clone https://github.com/Darm64/dtrace.git
git clone https://github.com/Darm64/AvailabilityVersions.git
git clone https://github.com/Darm64/libplatform.git
git clone https://github.com/Proteas/install_firehose_lib.git
git clone https://github.com/Darm64/xnu.git

Installing tools

cd ./dtrace
mkdir -p obj dst sym
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/${TOOLCHAINPATH}" "${TOOLCHAINPATH}"
cd ..

Installing missing Header Files

cd ./AvailabilityVersions
mkdir -p dst
make install SRCROOT="${PWD}" DSTROOT="${PWD}/dst"
sudo ditto "${PWD}/dst/usr/local" "${SDKPATH}/usr/local"
cd ../xnu
mkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst
make installhdrs SDKROOT=iphoneos ARCH_CONFIGS=ARM64 SRCROOT="${PWD}" OBJROOT="${PWD}/BUILD.hdrs/obj" SYMROOT="${PWD}/BUILD.hdrs/sym" DSTROOT="${PWD}/BUILD.hdrs/dst"
touch libsyscall/os/thread_self_restrict.h
xcodebuild installhdrs -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS="x86_64" SRCROOT="${PWD}/libsyscall" OBJROOT="${PWD}/BUILD.hdrs/obj" SYMROOT="${PWD}/BUILD.hdrs/sym" DSTROOT="${PWD}/BUILD.hdrs/dst"
sudo chown -R root:wheel BUILD.hdrs/dst/
sudo ditto BUILD.hdrs/dst "${SDKPATH}"
cd ../libplatform
sudo ditto "${PWD}/include" "${SDKPATH}/usr/local/include"
sudo ditto "${PWD}/private"  "${SDKPATH}/usr/local/include"
cd ../install_firehose_lib
sudo ./install-firehose.sh
cd ../xnu

You also need a special version of libclang_rt.cc_kext_ios.a.

sudo mv $TOOLCHAINPATH/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.cc_kext_ios.a $TOOLCHAINPATH/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.cc_kext_ios.a.BK
mv (YOUR OWN BUILD OF LLVM)/lib/clang/8.0.0/lib/darwin/libclang_rt.cc_kext_ios.a $TOOLCHAINPATH/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.cc_kext_ios.a  

Compiling XNU for ARM

make -j$(sysctl -n hw.ncpu) SDKROOT=iphoneos ARCH_CONFIGS=ARM64 KERNEL_CONFIGS=DEBUG BUILD_WERROR=0

BSD.xcconfig

If an error asking you for BSD.xcconfig appears, clone Darm64/CoreOSMakefiles.git and put its contents on Xcode.app/Contents/Developer/Makefiles/CoreOS.