Mac OS X 10.11.6内核编译步骤

请关注DeveloperQ公众号

DeveloperQ公众号

1. 下载安装Xcode 7.2.1版本(注意Xcode 7.3.x或8.x无法编译10.11.6内核)


2. 下载所需要的AvailabilityVersions及dtrace工具:


$ wget https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-22.40.2.tar.gz

$ wget https://opensource.apple.com/tarballs/dtrace/dtrace-168.tar.gz


3. 编译安装dtrace中的ctf工具


$ tar xzvf 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. 安装AvailabilityVersions工具


$ tar xzvf AvailabilityVersions-22.40.2.tar.gz 

$ cd AvailabilityVersions-22.40.2

$ 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. 下载内核代码并解压


$ wget https://opensource.apple.com/tarballs/xnu/xnu-3248.60.10.tar.gz

$ tar xzvf xnu-3248.60.10


6. 需要修改一处Makefile,否则编译不通过:


diff -ur xnu-3248.60.10/libkern/libkern/Makefile Downloads/xnu-3248.60.10/libkern/libkern/Makefile

--- xnu-3248.60.10/libkern/libkern/Makefile2016-08-05 03:09:51.000000000 +0800

+++ Downloads/xnu-3248.60.10/libkern/libkern/Makefile2017-01-13 14:42:42.000000000 +0800

@@ -73,7 +73,8 @@

 kernel_mach_header.h   \

 kxld.h                 \

 kxld_types.h           \

-stack_protector.h

+stack_protector.h      \

+section_keywords.h


7. 编译内核


$ cd xnu-3248.60.10

$ make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE


8. 安装内核并重启


$ sudo cp BUILD/obj/RELEASE_X86_64/kernel /System/Library/Kernels/

$ sudo kextcache -invalidate /

$ sudo reboot

如不是黑苹果,安装自己编译的内核需先禁用SIP 







相关问题推荐