【OC底层】(2)环境-libmalloc-283.100.6源码编译

一.前言

本文基于dandelionYD大神的libmalloc-166.200.60之源码编译的转载和更新整理,感谢dandelionYD大神的分享。
说明:工程删除了部分源码,并未知影响,所以该方式仅供参考。
环境说明:macOS10.15.3 Xcode11.2

二.准备工作

libmalloc-283.100.6.tar.gz
xnu-6153.141.1.tar.gz
dyld-732.8.tar.gz
Libc-1353.41.1.tar.gz
libplatform-220
将以上代码分别解压

三.编译修复

1.删除非必要Target

(仅保留libsystem_malloc)

2.删除非必要文件夹及文件

文件夹:resolvertestsxcodeconfigtools
文件:perfdata.frameworkktrace.framework

3、配置头文件路径

libsystem_malloc -> Build Settings -> System Header Search Paths,添加$(SRCROOT)/include,后面添加的头文件同时也放进include中。

4、编译出错过程

问题:'_simple.h' file not found
解决:libplatform中的_simple.h添加进include/

问题:'platform/string.h' file not found
解决:libplatform中的string.h添加进include/platform/

问题:'platform/compat.h' file not found
解决:libplatform中的compat.h添加进include/platform/

问题:'mach-o/dyld_priv.h' file not found
解决:dyld中的dyld_priv.h添加进include/mach-o/

问题:'os/internal/internal_shared.h' file not found
解决:libplatform中的internal_shared.h添加进include/os/internal/

问题:'os/base_private.h' file not found
解决:libplatform中的base_private.h添加进include/os/

问题:'os/internal/atomic.h' file not found
解决:libplatform中的atomic.h添加进include/os/internal/

问题:'os/internal/crashlog.h' file not found
解决:libplatform中的crashlog.h添加进include/os/

问题:'os/lock_private.h' file not found
解决:libplatform中的lock_private.h添加进include/os/

问题:'os/once_private.h' file not found
解决:libplatform中的once_private.h添加进include/os/

问题:'os/tsd.h' file not found
解决:libplatform中的tsd.h添加进include/os/

问题:'thread_stack_pcs.h' file not found
解决:Libc中的thread_stack_pcs.h添加进include/

问题:'machine/cpu_capabilities.h' file not found
解决:xnu中的machine/cpu_capabilities.h添加进include/machine/

问题:'resolver.h' file not found
解决:libplatform中的resolver.h添加进include/

问题:Use of undeclared identifier '_COMM_PAGE_MEMORY_SIZE'
Use of undeclared identifier '_COMM_PAGE_NCPUS'
解决:添加自定义头文件missingDefines.h放进include/

附: missingDefines.h源码:

#ifndef missingDefines_h
#define missingDefines_h
//( 0x00007fffffe00000ULL )
//( 0x00007fffffe00000 )
#define _COMM_PAGE64_BASE_ADDRESS	( 0x00007fffffe00000ULL )
#define _COMM_PAGE_START_ADDRESS	_COMM_PAGE64_BASE_ADDRESS
#define _COMM_PAGE_MEMORY_SIZE		(_COMM_PAGE_START_ADDRESS+0x038)
#define _COMM_PAGE_NCPUS			(_COMM_PAGE_START_ADDRESS+0x022)
#define _COMM_PAGE_PHYSICAL_CPUS	(_COMM_PAGE_START_ADDRESS+0x035)
#define _COMM_PAGE_LOGICAL_CPUS		(_COMM_PAGE_START_ADDRESS+0x036)
#define _COMM_PAGE_VERSION			(_COMM_PAGE_START_ADDRESS+0x01E)        // 16-bit version#

#define NOTE_MEMORYSTATUS_PRESSURE_WARN			0x00000002      /* system memory pressure has changed to the warning state */
#define NOTE_MEMORYSTATUS_PROC_LIMIT_WARN		0x00000010      /* process memory limit has hit a warning state */
#define NOTE_MEMORYSTATUS_MSL_STATUS			0xf0000000      /* bits used to request change to process MSL status */
#define NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL	0x00000020      /* process memory limit has hit a critical state - soft limit */
#define NOTE_MEMORYSTATUS_PRESSURE_CRITICAL		0x00000004      /* system memory pressure has changed to the critical state */
#endif /* missingDefines_h */

问题:'resolver_internal.h' file not found
解决:libplatform中的resolver_internal.h添加进include/

问题:'os/internal.h' file not found
解决:libplatform中的internal.h添加进include/os/

问题:'os/semaphore_private.h' file not found
解决:libplatform中的semaphore_private.h.h添加进include/os/

问题:'yield.h' file not found
解决:libplatform中的yield.h添加进include/

问题:Use of undeclared identifier '_COMM_PAGE_START_ADDRESS'
Use of undeclared identifier '_COMM_PAGE64_BASE_ADDRESS'
Use of undeclared identifier '_COMM_PAGE_PHYSICAL_CPUS'
Use of undeclared identifier '_COMM_PAGE_LOGICAL_CPUS'
Use of undeclared identifier '_COMM_PAGE_VERSION'
解决:参考missingDefines.h

问题:_nanov2_configure_nanov2_create_zone_nanov2_forked_zone_nanov2_init错误
解决:删除nanov2_malloc.cnanov2_malloc.hnanov2_zone.h,并将所有关于nanov2的缺失的.h文件都注释掉,所有判断nanov2的源码都改为nanov的源码。(存在风险)

至此,编译顺利完成。

四.新建调试Target

1.macOS -> Command Line Tool -> mallocTest
2.添加Build Phasses->Dependencies->libsystem_malloc
添加Build Phasses->Link Binary With Libraries->.dylib
3.在main.m文件中编写测试代码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值