标记位码(-fembed-bitcode-marker)有什么意义?

What is the point of marker bitcode (-fembed-bitcode-marker)?

这在 Apple 开发中经常出现——当使用位码提交到应用商店时,您当然必须包含完整的位码 (-fembed-bitcode)。但是,为什么要有这种中间“标记”模式,它包括部分而不是位码本身?这一定有一些存在的原因,以及为什么它经常为调试版本打开。

重点是在开发过程中加快构建速度。

来源: 您可以阅读提交的代码审查,将 embed-bitcode 标志添加到 clang 编译器前端以获取更多详细信息:

  • Introduce -fembed-bitcode driver option

    This is the clang driver part of the change to embedded bitcode. This includes:

    1. -fembed-bitcode option which breaks down the compilation into two stages. The first stage emits optimized bitcode and the second stage compiles bitcode into object file.

    2. -fembed-bitcode-marker option which doesn't really break down to two stages to speedup the compilation flow.

    3. pass the correct linker flag to darwin linker if tool chains supports embedded bitcode.

  • Embed bitcode in object file (clang cc1 part)

    marker only mode is used to speed up the compilation while still producing enough information in the final output to check if all the files are containing a bitcode section. -fembed-bitcode option will split the compilation into two stages and it adds measurable costs to compile time due to the extra process launch, the serialization and the verifier. -fembed-bitcode-marker is just a way to avoid that costs but still mark the section for the sanity check later (done by linker in our case).

上下文: Guardsquare blog article 讨论启用位码的构建。相关备注为:

What does Apple do with the embedded bitcode?

The question remains: why does Apple offer the option to embed bitcode? The answer is straightforward. With the bitcode embedded in the executable, Apple is able to recompile applications without interacting with the developer. This has a lot of advantages.

  1. Apple is continuously enhancing the optimization performed by the Clang compiler to further improve the performance of mobile applications and reduce their size. Using the embedded bitcode, Apple itself can recompile applications using the latest, improved version of the compiler. This frees app developers from the burden of continuously having to update their development environment and recompile and reupload their applications to benefit from the latest improvements.

  2. By embedding the bitcode, developers enable Apple to migrate their applications to new types of devices. The embedded bitcode enables Apple to recompile existing applications and make them compatible with the chipsets of new devices.

如果您只是调试 and/or 测试您的应用程序,您将不会执行上述任何操作。那么,当您真的只想确保一切正确构建和运行时,为什么还要浪费时间和资源(包括位码)呢?因此启用 embed-bitcode-marker 标志,以便在开发过程中 伪造 构建过程的这一部分。