objc4-841.13可调试/编译源码更新(for M1)

6,998 阅读2分钟

心心念念查看了下objc4源码 opensource.apple.com/releases/ ,果然更新了,果断编译调试

如果想最省时省力,直接 github 下载可编译源码

下面开始配置可编译环境(本次配置为M1)

首先确保下载到841.13源码

首先编译target objc

  1. unable to find sdk 'macosx.internal'

image.png

  • PROJECTS –> objc –> Build Settings, 将 Base SDK 改成 macOS
  • TARGETS –> objc –> Build Settings, 将 Base SDK 改成 macOS
  1. 'sys/reson.h' file not found

image.png

  • 下载xnu-8020.101.4, 把 xnu-8020.101.4/bsd/sys/reason.h 文件复制到 comm_ifl/sys 目录下

image.png

  • 设置头文件搜索路径:TARGETS –> objc –> Build Settings –> Header Search Paths, 添加一条 $(SRCROOT)/comm_ifl

image.png

  1. 'mach-o/dyld_priv.h' file not found

image.png

  • 下载 dyld-955, 把 dyld-955/include/mach-o/dyld_priv.h 拷贝到 comm_ifl/mach-o/dyld_priv.h

image.png

  1. 'os/lock_private.h' file not found

image.png

  • 下载 libplatform-273.100.5, 把 libplatform-273.100.5/private/os/lock_private.h 拷贝到 comm_ifl/os/lock_private.h

image.png

  1. extern dyld_platform_t dyld_get_active_platform(void) __API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0), bridgeos(3.0)); ---- 报错 Expected ','

image.png

  • 由于调试主要基于macos,删除, bridgeos(3.0)
  1. 同5

image.png

  • 同样均删除掉 , bridgeos(3.0)
  1. 'os/base_private.h' file not found

image.png

  • 下载源码(macOS Catalina 10.15 - macOS 10.15.6)libplatform-220.100.1, 把 libplatform-220.100.1/private/os/base_private 拷贝到 comm_ifl/os/base_private.h

image.png

  1. 'pthread/tsd_private.h' file not found
  • 下载 libpthread-libpthread-486.100.11 libpthread-libpthread-486.100.11/private/pthread/tsd_private.h 拷贝到 comm_ifl/pthread/tsd_private.h
  1. 'System/machine/cpu_capabilities.h' file not found
  • xnu-xnu-8020.101.4/osfmk/machine/cpu_capabilities.h 拷贝到 comm_ifl/System/machine/cpu_capabilities.h
  1. 'os/feature_private.h' file not found
  • 注释掉
  1. 'os/variant_private.h' file not found
  • google搜索 os/variant_private.h opensource.apple.com

    得到结果 opensource.apple.com/source/Libc… 根据路径找文件

  • 拷贝 Libc-Libc-1507.100.9/os/variant_private.hcomm_ifl/os/variant_private.h

  1. 'os/tsd.h' file not found
  • 拷贝 xnu-xnu-8020.101.4/libsyscall/os/tsd.hcomm_ifl/os/tsd.h
  1. 'pthread/spinlock_private.h' file not found
  • 拷贝 libpthread-libpthread-486.100.11/private/pthread/spinlock_private.hcomm_ifl/pthread/spinlock_private.h
  1. 'System/pthread_machdep.h' file not found
  • 拷贝 Libc-825.24/pthreads/pthread_machdep.hcomm_ifl/System/pthread_machdep.h
  1. bridgeos(4.0) 问题
  • 去除

image.png

  1. 'CrashReporterClient.h' file not found
  • 拷贝 Libc-825.24/include/CrashReporterClient.hcomm_ifl/CrashReporterClient.h
  1. Typedef redefinition with different types ('int' vs 'volatile OSSpinLock' (aka 'volatile int'))

image.png

  • 注释掉

image.png image.png

  1. Use of undeclared identifier 'dyld_platform_version_macOS_10_13'

image.png

  • 注释

image.png

  1. 'os/bsd.h' file not found
  • 注释
  1. 'os/reason_private.h' file not found
  • 拷贝 xnu-xnu-8020.101.4/libkern/os/reason_private.hcomm_ifl/os/reason_private.h
  1. 'objc-shared-cache.h' file not found
  • 拷贝 dyld-dyld-955/include/objc-shared-cache.hcomm_ifl/objc-shared-cache.h
  1. 'os/linker_set.h' file not found
  • 拷贝 Libc-Libc-1507.100.9/os/linker_set.hcomm_ifl/os/linker_set.h
  1. '_simple.h' file not found
  • 拷贝 Libc-825.24/gen/_simple.hcomm_ifl/_simple.h
  1. dyld_program_sdk_at_least(dyld_fall_2020_os_versions)

image.png

  • 注释掉

image.png

  1. Use of undeclared identifier 'objc4'
  • 注释掉
  1. Use of undeclared identifier 'CRGetCrashLogMessage'

image.png image.png

  1. 'Cambria/Traps.h Cambria/Cambria.h' file not found
  • 注释
  1. 'kern/restartable.h' file not found
  • xnu-xnu-8020.101.4/osfmk/kern/restartable.h 拷贝到 comm_ifl/kern/restartable.h
  1. Use of undeclared identifier 'oah_is_current_process_translated'

image.png image.png

  1. Block_private.h
  • libclosure-libclosure-79.1/Block_private.h 拷贝到 comm_ifl/Block_private.h
  1. Use of undeclared identifier 'os_parse_boot_arg_string'
  • 注释掉

image.png

  1. Use of undeclared identifier 'dyld_platform_version_macOS_10_11'

image.png image.png

  1. Use of undeclared identifier 'dyld_fall_2018_os_versions'
  • 注释掉

image.png

  1. Use of undeclared identifier 'dyld_platform_version_macOS_10_12'

image.png image.png

  1. '_static_assert' declared as an array with a negative size

image.png

  • 注释

在 dyld_priv.h 文件顶部加入宏

#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

CrashReporterClient异常

CrashReporterClient.h已经导入,还是报错 找不到

配置脚本

image.png

image.png

image.png

ld -loah报错

image.png

image.png

image.png

objc编译成功

image.png

接下来objc进行编译调试

  • 新建target

image.png

  • 建立依赖

image.png

image.png

编译调试target

image.png

  • 下符号 alloc调试

image.png

进入源码 alloc

坚持到这一步,M1 objc调试环境OK,就恭喜了