Xcode Build Setting 整理(二)

本文详细介绍了 AppleClang 编译器的多种优化与调试设置,包括地址 sanitizer 清扫、代码生成、调试信息级别、额外向量扩展、代码覆盖率支持等功能。还探讨了如何通过调整编译器标志来优化 C 和 C++ 代码,例如控制优化级别、生成调试符号、链接时间优化等,以实现更快的构建速度和更小的二进制文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录

Apple Clang

Apple Clang - Address Sanitizer 清扫


Summary

Check for C++ container overflow when Address Sanitizer is enabled. This check requires the entire application to be built with Address Sanitizer. If not, it may report false positives.

Declaration

CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW

Value Type

Boolean

Apple Clang - Code Generation 产生

Debug Information Level (CLANG_DEBUG_INFORMATION_LEVEL)

Summary

Toggles the amount of debug information emitted when debug symbols are enabled. This can impact the size of the generated debug information, which may matter in some cases for large projects, such as when using LTO.

Declaration

CLANG_DEBUG_INFORMATION_LEVEL

Value Type

Enumeration (String)
Enable Additional Vector Extensions

Summary

Enables the use of extended vector instructions. Only used when targeting Intel architectures.

Declaration

CLANG_X86_VECTOR_INSTRUCTIONS

Value Type

Enumeration (String)

Enable Code Coverage Support

Summary

Enables building with code coverage instrumentation. This is only used when the build has code coverage enabled, which is typically done via the Xcode scheme settings.

Declaration

CLANG_ENABLE_CODE_COVERAGE

Value Type

Boolean
Enforce Strict Aliasing

Summary

Optimize code by making more aggressive assumptions about whether pointers can point to the same objects as other pointers. Programs that use pointers a lot may benefit from this, but programs that don't strictly follow the ISO C rules about the type with which an object may be accessed may behave unexpectedly.

Declaration

GCC_STRICT_ALIASING

Value Type

Boolean
Generate Debug Symbols

是否生成 Debug 符号文件,生成的时候可以设置 DEBUG_INFORMATION_FORMAT


Summary

Enables or disables generation of debug symbols. When debug symbols are enabled, the level of detail can be controlled by the `DEBUG_INFORMATION_FORMAT` setting.

Declaration

GCC_GENERATE_DEBUGGING_SYMBOLS

Value Type

Boolean
Generate Legacy Test Coverage Files

Summary

Activating this setting causes a `notes` file to be produced that the `gcov` code-coverage utility can use to show program coverage.

Declaration

GCC_GENERATE_TEST_COVERAGE_FILES

Value Type

Boolean
Generate Position-Dependent Code

Summary

Faster function calls for applications. Not appropriate for shared libraries, which need to be position-independent.

Declaration

GCC_DYNAMIC_NO_PIC

Value Type

Boolean
Inline Methods Hidden

Summary

When enabled, out-of-line copies of inline methods are declared `private extern`.

Declaration

GCC_INLINES_ARE_PRIVATE_EXTERN

Value Type

Boolean
Instrument Program Flow

Summary

Activating this setting indicates that code should be added so program flow arcs are instrumented.

Declaration

GCC_INSTRUMENT_PROGRAM_FLOW_ARCS

Value Type

Boolean
Kernel Development Mode

Summary

Activating this setting enables kernel development mode.

Declaration

GCC_ENABLE_KERNEL_DEVELOPMENT

Value Type

Boolean
Link-Time Optimization

Summary

Enabling this setting allows optimization across file boundaries during linking. * *No:* Disabled. Do not use link-time optimization. * *Monolithic Link-Time Optimization:* This mode performs monolithic link-time optimization of binaries, combining all executable code into a single unit and running aggressive compiler optimizations. * *Incremental Link-Time Optimization:* This mode performs partitioned link-time optimization of binaries, inlining between compilation units and running aggressive compiler optimizations on each unit in parallel. This enables fast incremental builds and uses less memory than Monolithic LTO.

Declaration

LLVM_LTO

Value Type

Enumeration (String)
Make Strings Read-Only

字符串常量重复使用,也就是在mach-o中字符串常量是在同一个区域内,使用的时候通过指针查找

Summary

Reuse string literals.

Declaration

GCC_REUSE_STRINGS

Value Type

Boolean
No Common Blocks

Summary

In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without `extern`) in two different compilations, you will get an error when you link them.

Declaration

GCC_NO_COMMON_BLOCKS

Value Type

Boolean

例子

GCC_NO_COMMON_BLOCKS=YES
Optimization Level

Summary

Specifies the degree to which the generated code is optimized for speed and binary size. * *None:* Do not optimize. [-O0] With this setting, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent—if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code. * *Fast:* Optimizing compilation takes somewhat more time, and a lot more memory for a large function. [-O1] With this setting, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. In Apple's compiler, strict aliasing, block reordering, and inter-block scheduling are disabled by default when optimizing. * *Faster:* The compiler performs nearly all supported optimizations that do not involve a space-speed tradeoff. [-O2] With this setting, the compiler does not perform loop unrolling or function inlining, or register renaming. As compared to the `Fast` setting, this setting increases both compilation time and the performance of the generated code. * *Fastest:* Turns on all optimizations specified by the `Faster` setting and also turns on function inlining and register renaming options. This setting may result in a larger binary. [-O3] * *Fastest, Smallest:* Optimize for size. This setting enables all `Faster` optimizations t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值