<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.4">Jekyll</generator><link href="https://blog.fergofrog.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.fergofrog.com/" rel="alternate" type="text/html" /><updated>2019-04-09T11:13:26+00:00</updated><id>https://blog.fergofrog.com/feed.xml</id><title type="html">fergofrog’s blog</title><subtitle>fergofrog's blog about software and other stuff.</subtitle><author><name>fergofrog</name></author><entry><title type="html">Compiling XNU 4903.221.2 for ARM64</title><link href="https://blog.fergofrog.com/xnu/arm64/2018/12/23/compile-xnu-4903.221.2-for-arm64.html" rel="alternate" type="text/html" title="Compiling XNU 4903.221.2 for ARM64" /><published>2018-12-23T00:00:00+00:00</published><updated>2018-12-23T00:00:00+00:00</updated><id>https://blog.fergofrog.com/xnu/arm64/2018/12/23/compile-xnu-4903.221.2-for-arm64</id><content type="html" xml:base="https://blog.fergofrog.com/xnu/arm64/2018/12/23/compile-xnu-4903.221.2-for-arm64.html">&lt;p&gt;This is a follow up to the previous post on &lt;a href=&quot;2018-07-07-compile-xnu-for-arm64.md&quot;&gt;compling XNU 4570.41.2 for ARM64&lt;/a&gt;, but covering the newly released XNU 4903.221.2 (macOS 14.1).
This guide is, again, mostly based on &lt;a href=&quot;https://kernelshaman.blogspot.com/2018/12/building-xnu-for-macos-mojave-10141.html&quot;&gt;the kernelshamin guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The future of compilation for arm64 looked bad from Apple’s release of xnu-4570.71.2 which contained several broken components for the architecture.
Thankfully, this release required only two minor modifications (and nothing to code!):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;We don’t have access to the device map database, nor the &lt;code class=&quot;highlighter-rouge&quot;&gt;embedded_device_map&lt;/code&gt; tool, thankfully these are only needed to actually build for the device&lt;/li&gt;
  &lt;li&gt;As before, &lt;code class=&quot;highlighter-rouge&quot;&gt;Availability.h&lt;/code&gt; is needed but not included in the &lt;code class=&quot;highlighter-rouge&quot;&gt;installhdrs&lt;/code&gt; stage - simply fixed by modifying &lt;code class=&quot;highlighter-rouge&quot;&gt;EXTERNAL_HEADERS/Makefile&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This release included Apple’s intended use for the &lt;code class=&quot;highlighter-rouge&quot;&gt;MACHINE_CONFIG&lt;/code&gt; build variable. This allows the targetted AP to be specified as part of the build (or 
for multiple device builds to occur). In the original modifications, I hardcoded the T8011 board, but later included a great suggestion from @zhouwei
(&lt;a href=&quot;https://github.com/fergofrog/xnu/issues/1&quot;&gt;see issue #1&lt;/a&gt;) which did exactly what Apple has now released. An additional machine is also included, the BCM2837,
the AP for the Raspberry Pi 3 - very cool! The big challenges that someone would need to resolve for the rpi3 is that a device map is needed, ideally they would
create an &lt;code class=&quot;highlighter-rouge&quot;&gt;embedded_device_map&lt;/code&gt; tool, and a custom iBoot to take over from the Pi’s bootloader and pass off to XNU. @zhouwei has done this for &lt;a href=&quot;https://worthdoingbadly.com/xnuqemu/&quot;&gt;qemu&lt;/a&gt;
and of course &lt;a href=&quot;https://corellium.com/&quot;&gt;Corellium&lt;/a&gt; have done it better than anyone - it can be done!&lt;/p&gt;

&lt;h1 id=&quot;tldr&quot;&gt;tl;dr&lt;/h1&gt;
&lt;p&gt;The complication process is as simple as following the &lt;a href=&quot;https://kernelshaman.blogspot.com/2018/12/building-xnu-for-macos-mojave-10141.html&quot;&gt;kernelshaman blog&lt;/a&gt;,
with the following modifications:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Use my repository for &lt;a href=&quot;https://github.com/fergofrog/xnu/tree/xnu-4903.221.2&quot;&gt;xnu 4903.221.2&lt;/a&gt; - it contains modifications to the xnu source 
necessary for building
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Note&lt;/em&gt;: if you would rather build from Apple’s source, check the &lt;a href=&quot;https://github.com/fergofrog/xnu/commit/70b35d4532423155f62cdafe0d4e12bfb90836ad&quot;&gt;diff&lt;/a&gt;
from my repo for changes I made&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;a copy of the &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt; header must be made from the iPhoneOS SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/usr/include&lt;/code&gt; directory to the 
iPhoneOS SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers&lt;/code&gt; directory in order to build
libfirehose&lt;/li&gt;
  &lt;li&gt;When building: the SDK is “&lt;code class=&quot;highlighter-rouge&quot;&gt;iphoneos&lt;/code&gt;”, the ARCH is “&lt;code class=&quot;highlighter-rouge&quot;&gt;arm64&lt;/code&gt;”, and XNU’s build also needs &lt;code class=&quot;highlighter-rouge&quot;&gt;ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG=arm64&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;the-details&quot;&gt;The Details&lt;/h1&gt;
&lt;p&gt;This process was tested on a mostly-clean macOS 10.14.2 with Xcode 10.1.&lt;/p&gt;

&lt;h2 id=&quot;ctf-tools&quot;&gt;CTF Tools&lt;/h2&gt;
&lt;p&gt;The CTF tools (&lt;code class=&quot;highlighter-rouge&quot;&gt;ctfconvert&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;ctfdump&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ctfmerge&lt;/code&gt;) are executed as part of XNU’s build and are expected to be in 
your hosts’s SDK path.&lt;/p&gt;

&lt;p&gt;For macOS 10.14.1 dtrace has had a version bump to 284.200.15. Compilation requires some additional header search paths
to resolve locating &lt;code class=&quot;highlighter-rouge&quot;&gt;elf.h&lt;/code&gt; and a few others.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf dtrace-284.200.15.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;dtrace-284.200.15
mkdir obj sym dst
xcodebuild install &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; macosx &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfconvert &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfdump &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfmerge &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;ARCHS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;x86_64 &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OBJROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/obj &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;SYMROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/sym &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;HEADER_SEARCH_PATHS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/compat/opensolaris/** &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/lib/**&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;availabilityversions&quot;&gt;AvailabilityVersions&lt;/h2&gt;
&lt;p&gt;AvailabilityVersions provides a perl script used as part of the XNU build. Build and installation is per the blog, 
except the install target is the &lt;code class=&quot;highlighter-rouge&quot;&gt;iphoneos&lt;/code&gt; SDK.&lt;/p&gt;

&lt;p&gt;AvailabilityVersions had a version bump to 33.200.4 in macOS 10.14.1, however the installation is as before.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf AvailabilityVersions-33.200.4.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;AvailabilityVersions-33.200.4
mkdir dst
make install &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/usr/local/libexec &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/libexec
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;libplatform-headers&quot;&gt;libplatform Headers&lt;/h2&gt;
&lt;p&gt;Just three header files are required from this project. These are now at version 177.200.16, but install is the same.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf libplatform-177.200.16.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;libplatform-177.200.16
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;mkdir &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/include/os/internal
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/private/os/internal &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/include/os/internal
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;xnu-headers&quot;&gt;XNU Headers&lt;/h2&gt;
&lt;p&gt;The headers are ready to be built now. I’d recommend using my repo and check the &lt;a href=&quot;https://github.com/fergofrog/xnu/commit/70b35d4532423155f62cdafe0d4e12bfb90836ad&quot;&gt;diff&lt;/a&gt;
to see what I did.&lt;/p&gt;

&lt;p&gt;After the headers are installed, a copy of the &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt; header must be made from the SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/usr/include&lt;/code&gt;
directory to the SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers&lt;/code&gt; directory in order to build
libfirehose.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; xnu-4903.221.2 https://github.com/fergofrog/xnu.git
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;xnu
make &lt;span class=&quot;nv&quot;&gt;LOGCOLORS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;y &lt;span class=&quot;nv&quot;&gt;SDKROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;iphoneos &lt;span class=&quot;nv&quot;&gt;ARCH_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ARM64 &lt;span class=&quot;nv&quot;&gt;MACHINE_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;T8011 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
     &lt;span class=&quot;nv&quot;&gt;KERNEL_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;RELEASE &lt;span class=&quot;nv&quot;&gt;ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;arm64 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
     installhdrs
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/BUILD/dst &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;cp &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/include/TargetConditionals.h &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/TargetConditionals.h
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;libfirehose_kernel-from-libdispatch&quot;&gt;libfirehose_kernel From libdispatch&lt;/h2&gt;
&lt;p&gt;The kernel libfirehose header and objects are required to build XNU. As before, the XNU headers and &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt; need to be in place, however the new
libdispatch 1008.220.2 requires several additional modifications, documented by the &lt;a href=&quot;https://kernelshaman.blogspot.com/2018/12/building-xnu-for-macos-mojave-10141.html&quot;&gt;kernelsharman blog&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf libdispatch-1008.220.2.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;libdispatch-1008.220.2
mkdir obj sym dst
awk &lt;span class=&quot;s1&quot;&gt;'/include &quot;&amp;lt;DEVELOPER/ {next;} /SDKROOT =/ {print &quot;SDKROOT = macosx&quot;; next;} {print $0}'&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    xcodeconfig/libdispatch.xcconfig &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; .__tmp__ &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    mv &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; .__tmp__ xcodeconfig/libdispatch.xcconfig
awk &lt;span class=&quot;s1&quot;&gt;'/#include / { next; } { print $0 }'&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    xcodeconfig/libfirehose_kernel.xcconfig &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; .__tmp__ &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    mv &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; .__tmp__ xcodeconfig/libfirehose_kernel.xcconfig
xcodebuild install &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; libfirehose_kernel &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OBJROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/obj &lt;span class=&quot;nv&quot;&gt;SYMROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/sym &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;ENABLE_BITCODE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;no
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/usr/local &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;xnu&quot;&gt;XNU&lt;/h2&gt;
&lt;p&gt;Now it’s time to build XNU. With all the setup from before, this process is as simple as one command.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;xnu
make &lt;span class=&quot;nv&quot;&gt;LOGCOLORS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;y &lt;span class=&quot;nv&quot;&gt;SDKROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;iphoneos &lt;span class=&quot;nv&quot;&gt;ARCH_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ARM64 &lt;span class=&quot;nv&quot;&gt;MACHINE_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;T8011 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
     &lt;span class=&quot;nv&quot;&gt;KERNEL_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;RELEASE &lt;span class=&quot;nv&quot;&gt;ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;arm64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>fergofrog</name></author><summary type="html">This is a follow up to the previous post on compling XNU 4570.41.2 for ARM64, but covering the newly released XNU 4903.221.2 (macOS 14.1). This guide is, again, mostly based on the kernelshamin guide.</summary></entry><entry><title type="html">Compiling XNU 4570.41.2 for ARM64</title><link href="https://blog.fergofrog.com/xnu/arm64/2018/07/07/compile-xnu-for-arm64.html" rel="alternate" type="text/html" title="Compiling XNU 4570.41.2 for ARM64" /><published>2018-07-07T00:00:00+00:00</published><updated>2018-07-07T00:00:00+00:00</updated><id>https://blog.fergofrog.com/xnu/arm64/2018/07/07/compile-xnu-for-arm64</id><content type="html" xml:base="https://blog.fergofrog.com/xnu/arm64/2018/07/07/compile-xnu-for-arm64.html">&lt;p&gt;Compiling XNU for x86_64 is quite easy, particularly when armed with a &lt;a href=&quot;https://kernelshaman.blogspot.com/2018/01/building-xnu-for-macos-high-sierra-1013.html&quot;&gt;good guide&lt;/a&gt;.
Aside from an extremely helpful &lt;a href=&quot;https://gist.github.com/Proteas/fe7bbb4c1b35a50de5e44d7c121d9601&quot;&gt;gist&lt;/a&gt; and a
&lt;a href=&quot;https://twitter.com/proteaswang/status/914067270397157376?lang=en&quot;&gt;Twitter thread&lt;/a&gt; from Proteas, there didn’t seem to 
be much on compiling XNU for arm64.&lt;/p&gt;

&lt;p&gt;Why would you want to compile XNU for arm64? Well, you definitely can’t run it on your i-device. But there could be
many other reasons. For me, a clean compile means I can generate a clean &lt;code class=&quot;highlighter-rouge&quot;&gt;compile-commands.json&lt;/code&gt; file for use with 
&lt;a href=&quot;https://fergofrog.com/code/cbowser/xnu/&quot;&gt;Woboq&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;tldr&quot;&gt;tl;dr&lt;/h1&gt;
&lt;p&gt;The long and short of this process is, follow the steps from &lt;a href=&quot;https://kernelshaman.blogspot.com/2018/01/building-xnu-for-macos-high-sierra-1013.html&quot;&gt;this blog&lt;/a&gt;,
with the following ammendments:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Use my repository for &lt;a href=&quot;https://github.com/fergofrog/xnu/tree/xnu-4570.41.2&quot;&gt;xnu&lt;/a&gt; - it contains modifications to the xnu source 
necessary for building
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Note&lt;/em&gt;: if you would rather build from Apple’s source, check the &lt;a href=&quot;https://github.com/fergofrog/xnu/commit/3f9807a1601c982580b77859e0aae6a915252c05&quot;&gt;diff&lt;/a&gt;
from my repo for changes I made&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;a copy of the &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt; header must be made from the iPhoneOS SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/usr/include&lt;/code&gt; directory to the 
iPhoneOS SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers&lt;/code&gt; directory in order to build
libfirehose&lt;/li&gt;
  &lt;li&gt;When building: the SDK is “&lt;code class=&quot;highlighter-rouge&quot;&gt;iphoneos&lt;/code&gt;”, the ARCH is “&lt;code class=&quot;highlighter-rouge&quot;&gt;arm64&lt;/code&gt;”, and XNU’s build also needs &lt;code class=&quot;highlighter-rouge&quot;&gt;BUILD_WERROR=0&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;the-details&quot;&gt;The Details&lt;/h1&gt;
&lt;p&gt;This process worked for me compiling XNU 4570.41.2 with a clean install of macOS High Sierra (10.13.5) and XCode 9.4, 
however, your mileage may vary.&lt;/p&gt;

&lt;h2 id=&quot;ctf-tools&quot;&gt;CTF Tools&lt;/h2&gt;
&lt;p&gt;The CTF tools (&lt;code class=&quot;highlighter-rouge&quot;&gt;ctfconvert&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;ctfdump&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ctfmerge&lt;/code&gt;) are executed as part of XNU’s build and are expected to be in 
your hosts’s SDK path. Build is per the blog.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf dtrace-262.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;dtrace-262
mkdir obj sym dst
xcodebuild install &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfconvert &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfdump &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; ctfmerge &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;ARCHS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;x86_64 &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OBJROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/obj &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;SYMROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/sym &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;availabilityversions&quot;&gt;AvailabilityVersions&lt;/h2&gt;
&lt;p&gt;AvailabilityVersions provides a perl script used as part of the XNU build. Build and installation is per the blog, 
except the install target is the &lt;code class=&quot;highlighter-rouge&quot;&gt;iphoneos&lt;/code&gt; SDK.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf AvailabilityVersions-32.30.1.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;AvailabilityVersions-32.30.1
mkdir dst
make install &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/usr/local/libexec &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/libexec
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;libplatform-headers&quot;&gt;libplatform Headers&lt;/h2&gt;
&lt;p&gt;Just three header files are required from this project.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf libplatform-161.20.1.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;libplatform-161.20.1
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;mkdir &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/include/os/internal
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/private/os/internal &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local/include/os/internal
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;xnu-headers&quot;&gt;XNU Headers&lt;/h2&gt;
&lt;p&gt;The headers are ready to be built now. This is where the first modifications are required. Proteas’ suggestion of 
copying the compile and link flags for the ARM64 architecture at this point just works. I’d recommend using my repo and
check the &lt;a href=&quot;https://github.com/fergofrog/xnu/commit/3f9807a1601c982580b77859e0aae6a915252c05&quot;&gt;diff&lt;/a&gt; to see what I did.&lt;/p&gt;

&lt;p&gt;After the headers are installed, a copy of the &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt; header must be made from the SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/usr/include&lt;/code&gt;
directory to the SDK’s &lt;code class=&quot;highlighter-rouge&quot;&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers&lt;/code&gt; directory in order to build
libfirehose.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; xnu-4570.41.2 https://github.com/fergofrog/xnu.git
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;xnu
make &lt;span class=&quot;nv&quot;&gt;LOGCOLORS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;y &lt;span class=&quot;nv&quot;&gt;SDKROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;iphoneos &lt;span class=&quot;nv&quot;&gt;ARCH_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ARM64 &lt;span class=&quot;nv&quot;&gt;KERNEL_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;RELEASE installhdrs
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/BUILD/dst &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;cp &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/include/TargetConditionals.h &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/TargetConditionals.h
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;libfirehose_kernel-from-libdispatch&quot;&gt;libfirehose_kernel From libdispatch&lt;/h2&gt;
&lt;p&gt;The kernel libfirehose header and objects are required to build XNU. With the XNU headers and &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetConditionals.h&lt;/code&gt;
header in the right place, this step is the same as before, however &lt;code class=&quot;highlighter-rouge&quot;&gt;ENABLE_BITCODE&lt;/code&gt; must be set to “no” in the build.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;zxvf libdispatch-913.30.4.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;libdispatch-913.30.4
mkdir obj sym dst
xcodebuild install &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-target&lt;/span&gt; libfirehose_kernel &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;SRCROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OBJROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/obj &lt;span class=&quot;nv&quot;&gt;SYMROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/sym &lt;span class=&quot;nv&quot;&gt;DSTROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;ENABLE_BITCODE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;no
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;ditto &lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt;/dst/usr/local &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;xcrun &lt;span class=&quot;nt&quot;&gt;-sdk&lt;/span&gt; iphoneos &lt;span class=&quot;nt&quot;&gt;-show-sdk-path&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;/usr/local
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;xnu&quot;&gt;XNU&lt;/h2&gt;
&lt;p&gt;Now it’s time to build XNU. With several code modifications (one fix and some code stubbing) and help to the make 
scripts, this is as simple as running one make command.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;xnu
make &lt;span class=&quot;nv&quot;&gt;LOGCOLORS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;y &lt;span class=&quot;nv&quot;&gt;SDKROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;iphoneos &lt;span class=&quot;nv&quot;&gt;ARCH_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ARM64 &lt;span class=&quot;nv&quot;&gt;KERNEL_CONFIGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;RELEASE &lt;span class=&quot;nv&quot;&gt;BUILD_WERROR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From there, you’ll have your very own XNU kernel targetting ARM64 located at &lt;code class=&quot;highlighter-rouge&quot;&gt;BUILD/obj/RELEASE_ARM64/mach&lt;/code&gt; (and an 
unstripped version at &lt;code class=&quot;highlighter-rouge&quot;&gt;BUILD/obj/RELEASE_ARM64/mach.unstripped&lt;/code&gt;)&lt;/p&gt;</content><author><name>fergofrog</name></author><summary type="html">Compiling XNU for x86_64 is quite easy, particularly when armed with a good guide. Aside from an extremely helpful gist and a Twitter thread from Proteas, there didn’t seem to be much on compiling XNU for arm64.</summary></entry></feed>