iOS编译优化

Xcode常见配置

生成LinkMap文件

Project->Build Settings->Write Link Map File为YES,并设置Path to Link Map File

Generate Debug Symbols

Generate Debug Symbols 是否产生调试符号,肯定要为YES。
当每个源文件编译成.o的时候,多了-g -gmodules 两项。
Generate Debug Symbols 当设置为NO的时候,在Xcode中断点不会中断,但是在程序中打印[NSThread callStackSymbols]可以看到方法和类名。

Debug Information Level

有两个选项 Compiler default Line tables only

Strip Style

All Symbols (-s) 移除符号表和重定位信息
Non-Global Symbols (-x) 移除非全局符号,保留外部符号
Debugging Symbols (-S) 移除调试符号,保存本地和全局符号。

DEPLOYMENT_POSTPROCESSING (Deployment Postprocessing)

是否开启后期处理。
但是要 STRIP_INSTALLED_PRODUCT (Strip Linked Product)开启: 指定是否去除二进制文件的符号信息。

STRIP_STYLE (Strip Style)
all: Strips the binary completely, removing the symbol table and relocation information. 去除所有信息
non-global: Strips nonglobal symbols but saves external symbols.	保留外部符号
debugging: Strips debugging symbols but saves local and global symbols. 保留本地和全局符号

编译静态库隐藏符号

Strip Style 使用Non-Global Symbols
Perform Single-Object Prelink : YES
strip -r -S -x libSAKGuard.a
Optimization Level : -O0
Deployment Postprocessing: YES

strip:
-r      Save all symbols referenced dynamically.
-S     Remove the debugging symbol table entries (those created by the -g option to cc(1) and other compilers).
-x     Remove all local symbols (saving only global symbols).

编译优化

1、BuildSettings->Optimization Level,Xcode默认设置为“Fastest ,Smallest”。
2、Build Settings-> Linking->Dead Code Stripping 设置成 YES,去除没有使用的代码。
3、Deployment Postprocessing 设置成YES, Strip Linked Product 设置成YES。
Deployment Postprocessing DEBUG下设为NO,RELEASE下设为YES
5、工程的Enable C++ Exceptions和Enable Objective-C Exceptions选项都设置为NO。手动管理异常。
6、symbols hidden by default选项设置为YES。
7、所有没有使用C++动态特性的lib库(搜索工程没有使用dynamic_cast关键字) Enable C++ Runtime Types 选项设置为NO。

ref:
https://www.jianshu.com/p/11710e7ab661 Xcode中和symbols有关的几个设置
https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=207986417&idx=1&sn=77ea7d8e4f8ab7b59111e78c86ccfe66&3rd=MzA3MDU4NTYzMw==&scene=6#rd iOS微信安装包瘦身
https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-DontLinkElementID_233 官方文档
https://mp.weixin.qq.com/s/-wgBhE11xEXDS7Hqgq3FjA 微信编译优化 clang -ftrace

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值