(iOS)

This paper is mainly through the successful compilation of objC4-781 source code, and then debugging in the source code, easy to trace the method of the underlying implementation process

The preparatory work

Environment version & latest objC source code

  • MAC OS 10.15
  • Xcode 11.4
  • objc4-781

Dependent file download

You need to download the following dependency files

With the exception of LaunchD-106.10, which needs to be downloaded on Mac OS X 10.4.4, the others are available in the latest version of macOS 10.15

The source code to compile

Source code compilation is the constant debugging and modification of the source code, the main problems are as follows

Problem a:unable to find sdk 'macosx.internal'

  • choosetarget -> objc -> Build Settings -> Base SDK-> Select macOS from targetObjc and obc - trampolinesBoth need to be changed.

Problem 2: File cannot be found error problem

【1】’sys/reason.h’ file not found

  • inApple sourcetheMacOS10.15 - > xnu - 6153.11.26 / BSD/sys/reason. HPath download
  • inobjc4-781Is created in the root directory ofCJLCommonFile, which is also created in the CJLCommon filesysfile
  • The final will bereason.h Copy files tosysIn the file

  • Set the file search path: choosetarget -> objc -> Build Settings, in engineeringHeader Serach PathsTo add a search path$(SRCROOT)/CJLCommon

【2】’mach-o/ dyLD_priv. h’ file not found

  • inCJLCommonCreate in filemach-ofile
  • Find the file:-- include -- mai-o -- dyLD_priv.h

  • Copy to the mach-o file

  • After you copy it to a file, you need to modify itdyld_priv.hFile, i.edyld_priv.h Add the following macro at the top of the file:
#define DYLD_MACOSX_VERSION_10_11 0x000A0B00 #define DYLD_MACOSX_VERSION_10_12 0x000A0C00 #define DYLD_MACOSX_VERSION_10_13 0x000A0D00 #define DYLD_MACOSX_VERSION_10_14 0x000A0E00 Copy codeCopy the code

[3] ‘OS/lock_privately. h’ file not found and’ OS/base_privately. h’ file not found

  • Created in CJLCommonosfile
  • findLock_private. H, base_private. HFile:Libplatform-220 --> private --> OS --> lock_private.h, base_private.hAnd copy the file to the OS file

  • Lock_privately. h dyLD_priv. h = = “bridgeos(3.0)”

Children’s shoes

【4】’pthread/tsd_private. H ‘file is not found and ‘pthread/spinlock_private

  • Create the pthread file in CJLCommon
  • findTsd_private. H, spinlock_private. HFile, h file path:Libpthread-416.11.1 --> private --> tsd_privately. h, spinlock_privately. hAnd copy topthreadfile

【5】’System/machine/cpu_capabilities. H ‘file not found

  • createSystem -- machinefile
  • findcpu_capabilities.h Copy files tomachineFile, h file path:Xnu6153.11.26 --> osfmk --> machine --> CPU_capabilities

【6】 OS/tsD. h ‘file not found

  • findtsd.hFile, copy toosFile, h file path:Xnu6153.11.26 --> libsyscall --> OS --> tsD.h

[7] ‘System/pthread_machdep.h’ file not found

  • inDownload from herepthread_machdep.hFile, h file path:Libc-583/pthreads/pthread_machdep.h
  • Copy it tosystemIn the file

The h file is not available in the latest version of LIBC downloaded in the latest macOS 10.15, so you need to download the LIBC-583 version

[8] ‘CrashReporterClient.h’ file not found

  • This file is inChange the address and search for LIBc-825.24The file is found inLibc - 825.24 / include/CrashReporterClient. H, stored directly in the CJLCommon file
  • Preprocessor Macros: Preprocessor Macros: Preprocessor Macros: Preprocessor Macros: LIBC_NO_LIBCRASHREPORTERCLIENT – or download the CrashReporterClient file I gave you, which we changed to #define LIBC_NO_LIBCRASHREPORTERCLIENT – If the error is still reportedCrashReporterClientThe solution to the problem is inBuildSetting --> Other Linker Flags Removing theCrashReporterClient .

[9] ‘objc-shared-cache.h’ file not found

  • The file path is:Dyld-733.6 --> include --> objc-shared-cache.h

  • Copy the h file filing system toCJLCommon

【10】Mismatch in debug-ness macros

  • Comment # Error mismatch in debug-ness macros in objc-Runtime. mm

【11】’_simple. H ‘file not found

  • The file path is:libplatform-220 --> private --> _simple.h

  • Copy the file toCJLCommonIn the

[12] ‘kern/restartable.h’ file not found

  • Created in CJLCommonkernfile
  • Find the h file, path isXnu-6153.11.26 --> osfmk --> kern -->restartable.h

[13] ‘block_privately. h’ file not found

  • Find the h file, file path islibclosure-74 --> Block_private.h

  • Copy toCJLCommondirectory

[14] Libobjc. Order path problem

Can’t open order file: / Applications/Xcode. App/Contents/Developer/Platforms/MacOSX platform/Developer/SDKs/MacOSX10.15 SDK/AppleInternal/OrderF iles/libobjc.order

  • choosetarget -> objc -> Build Settings
  • In the engineering ofOrder FileTo add a search path$(SRCROOT)/libobjc.order

[14] Xcodebuild :1:1: SDK “Macosx. internal” cannot be located.

  • choosetarget -> objc -> Build Phases -> Run Script(markgc)
  • Put the script textmacosx.internaltomacosx

debugging

  • Create a newtarget: CJLTest

  • The bindingBinary dependency

The source code to debug

  • Customize a CJLPerson class

  • Create an object for CJLPerson in main.m to debug the source code

supplement

If you have any of the following debugging problems, you can try them out according to the solution provided

The breakpoint on main in the created debug target cannot be broken

  • Build Phases –> Compile Source, move the main file to the first digit

  • Build Setting— > will beEnable Hardened RuntimeSet toNO

The 2021-03-22 supplement

Since the 781 source code cannot run on xCODE12, again provide an OBJC4-818.2 source code that can run on xCODE12 and above