The source code

  1. Download address opensource.apple.com/tarballs/

  2. The Runtime objc4-818.2

  3. Dependent libraries

  • Xnu – 7195.81.3
  • Dyld – 832.7.3
  • Libplatform – 254.80.2
  • Libpthreads – 454.80.2
  • Libc – 825.40.1
  • Libc – 1244.50.9
  • libclosure-78

IDE

  • Xcode 12.4

Set the dependent library directory

  1. Create the PrivateHeaders folder in the Runtime project root directory
  2. Open the Runtime source code, click objc in the left project navigation window, select objc under TARGETS in the right Settings window, click Build Settings, search for “Search Path” under “Search Paths” Open Header Search Paths and add $(SRCROOT)/PrivateHeaders

Compile error handling

Note: It was found in actual test that CMD +B compilation reported an error. If CMD +B compilation is repeated without any modification, another error may be reported in priority. Therefore, the error order may be different in actual operation, and you can modify it according to the actual order.

  1. Problem: error: Unable to find SDK ‘macosx.internal’ (in target ‘objc-trampolines’ from project ‘objc’) Under PROJECT, select objc and click Build Settings. Under Architetures, change the Base SDK from Macosx. internal to macOS

  2. Fatal error: ‘sys/reason. H file not found files: xnu – 7195.81.3 / BSD/sys/reason. H: “reason. H copy to objc4-818.2 / PrivateHeaders/sys /

  3. Fatal error: ‘dyld-832.7.3/include/mach-o/ dyLD_priv. h’ file not found Will dyld_priv. H copy to objc4-818.2 / PrivateHeaders/Mach – o /

  4. Problem: error: Expected ‘,’ extern dyLD_platform_t dyLD_GEt_base_platform (dyLD_platform_t platform) __API_AVAILABLE(macOS (10.14), Ios (12.0), watchos (5.0), tvos (12.0), bridgeos (3.0)); Bridgeos (3.0)

  5. Fatal error: ‘OS /lock_private.h’ file not found: libplatform-254.80.2/private/ OS /lock_private.h Copy lock_private.h to objC4-818.2 /PrivateHeaders/ OS /

  6. Fatal error: ‘OS/base_private. H file not found files: xnu – 7195.81.3 / libkern/OS/base_private. H plan: Copy base_private.h to objC4-818.2 /PrivateHeaders/ OS /

  7. Error: Expected ‘,’ tVOs (13.0), Watchos (6.0), Bridgeos (4.0)) = 0x00040000, lock_private.h, bridgeos(4.0)

  8. Fatal error: ‘pthread/tsd_private. H file not found files: libpthreads – 454.80.2 / private/pthread/tsd_private h plan: Will tsd_private. H copy to objc4-818.2 / PrivateHeaders/pthread /

  9. Fatal error: ‘the System/machine/cpu_capabilities. H’ file not found files: xnu – 7195.81.3 / osfmk/machine/cpu_capabilities h plan: Will cpu_capabilities. H copy to objc4-818.2 / PrivateHeaders/System/machine /

  10. Fatal error: ‘OS/TSD. H file not found files: xnu – 7195.81.3 / libsyscall/OS/TSD. H: will TSD. Copy to objc4-818.2 h/PrivateHeaders/OS /

  11. Fatal error: ‘pthread/spinlock_private. H file not found files: libpthreads – 454.80.2 / private/pthread/spinlock_private h plan: Will spinlock_private. H copy to objc4-818.2 / PrivateHeaders/pthread /

  12. Fatal error: ‘System/pthread_machdep. H file not found files: the Libc – 825.40.1 / pthreads/pthread_machdep. H plan: Will pthread_machdep. H copy to objc4-818.2 / PrivateHeaders/System /

  13. Problem: error: typedef redefinition with different types (‘int’ vs ‘volatile OSSpinLock’ (aka ‘volatile int’)) typedef long pthread_lock_t; error: static declaration of ‘_pthread_has_direct_tsd’ follows non-static declaration error: static declaration of ‘_pthread_getspecific_direct’ follows non-static declaration error: Static declaration of ‘_pthread_setspecific_direct’ follows non-static declaration scheme: comment pthread_machdep.h lines 61 to 299

  14. Fatal error: ‘CrashReporterClient. H file not found files: the Libc 825.40.1 / include/CrashReporterClient. H plan: Copy crashReporterClient. h to objC4-818.2 /PrivateHeaders on TARGETS objc: Build Settings: Added LIBC_NO_LIBCRASHREPORTERCLIENT to Preprocessor Macros

  15. Fatal error: ‘OS/feature_private. H file not found: note: NSObject. Line 42 mm, objc – runtime. Line 36 mm, Line 444-446

  16. Fatal error: ‘objc-shared-cache.h’ file not found file: dyld-832.7.3/include/objc-shared-cache.h Copy objc-shared-cache.h to objC4-818.2 /PrivateHeaders/

  17. Error: use of undeclared identifier ‘dyLD_FALL_2020_OS_VERSIONS’ Line 379 to 380 in objC-runtime. mm

  18. Fatal error: ‘Cambria/ traps.h ‘file not found’ fatal error: ‘Cambria/ traps.h ‘file not found

  19. Fatal error: ‘kern/restartable. H file not found files: xnu 7195.81.3 / osfmk/kern/restartable. H plan: Will be restartable. H copy to objc4-818.2 / PrivateHeaders/kern /

  20. Fatal error: ‘objc-bP-assist. h’ file not found fatal error:’ objc-bP-assist. h’ file not found fatal error: ‘objc-bP-assist. h’ file not found

  21. Error: use of undeclared identifier ‘dyld_platform_version_macOS_10_13’ objC-os. mm lines 567 to 574

  22. Fatal error: ‘OS /linker_set.h’ file not found file: xnu-7195.81.3/ BSD /sys/linker_set.h Copy linker_set.h to objC4-818.2 /PrivateHeaders/ OS /

  23. Error: use of undeclared identifier ‘dyld_platform_version_macOS_10_11’ objC-runtime-new. mm lines 3547 to 3553

  24. Error: use of undeclared identifier ‘dyLD_FALL_2018_OS_VERSIONS’ Line 8328 to 8350 in objC-runtime-new. mm

  25. Fatal error: H file not found file: libplatform-254.80.2/private/_simple.h Solution: Copy _simple.h to objC4-818.2 /PrivateHeaders/

  26. Fatal error: H ‘file not found file: libclosure-78/ block_private. h Solution: Copy block_private. h to objC4-818.2 /PrivateHeaders/

  27. Fatal error: ‘OS/reason_private. H file not found files: xnu – 7195.81.3 / libkern/OS/reason_private. H plan: Copy reason_private.h to objC4-818.2 /PrivateHeaders/ OS /

  28. Fatal error: ‘OS /variant_private.h’ file not found: libc-1244.50.9 / OS /variant_private.h Copy variant_private.h to objC4-818.2 /PrivateHeaders/ OS /

  29. Error: use of undeclared identifier ‘dyld_platform_version_macOS_10_12’ use of undeclared identifier ‘dyld_platform_version_iOS_10_0’ error: use of undeclared identifier ‘dyld_platform_version_tvOS_10_0’ error: use of undeclared identifier ‘dyld_platform_version_watchOS_3_0’ error: Use of undeclared identifier ‘dyld_platform_version_bridgeOS_2_0’ objc-os.h: Line 1045 to 1050 #define sdkIsAtLeast(x, i, t, w, b) true

  30. Error: ‘_static_assert’ declared as an array with a negative size objC-runtime-new. mm Line 176~177

  31. Can’t open order file: / Applications/Xcode. App/Contents/Developer/Platforms/MacOSX platform/Developer/SDKs/MacOSX11.1 SDK/AppleInternal/OrderFi Les /libobjc.order scheme: Select objc under TARGETS, click Build Settings, search order, change order File to $(SRCROOT)/ libobjC. order

  32. Library not found for -lCrashReporterClient TARGETS select objc, click Build Settings, search for Other Link, and delete -lCrashReporterClient from other Linker Flags

  33. Llibrary not found for-loah solution: Select objc under TARGETS, click Build Settings, search for Other link, delete -loah from other Linker Flags

  34. Problem: error: SDK “Macosx. internal” cannot be located TARGETS select objC, click Build Phases, and change macosx.internal to MacosX in Run Script(MarkGC)

    At this point, objC4-818.2 has compiled successfully

Create a test project

  1. Click the plus sign at the bottom of the TARGETS column to create the macOS Command Line Tool project objc_test

  2. Under the TARGETS column, select objc_test, click Build Phases, add Dependencies to Dependencies, and select objC

  3. TARGETS select objc_test, click Build Settings, and search for the Signing. Under the Signing, change the Enable Hardened Runtime from YES to NO. (If you do not modify this item, debug objC4-818.2 source code will not hit the breakpoint)

    At this point, you are ready to debug the objC4-818.2 source code

Source code and test engineering download

Github.com/hubupc/objc…