What's the difference between `-fembed-bitcode` and BITCODE_GENERATION_MODE?

让人想犯罪 __ 提交于 2019-11-27 01:04:09

问题


I've been updating a static library to support bitcode, and from my research I found two ways to achieve that:

  • Adding the fembed-bitcode flag to the Other C flags option in my project Build Settings (link)
  • Adding a User-defined Setting with the key BITCODE_GENERATION_MODE set to bitcode (link)

Is there any difference between these two options?

The only difference I noted is that by using fembed-bitcode, the resulting static library for iphonesimulator will be built with full bitcode enabled (in my case, binary size changes from 5MB to 13MB, and I can check bitcode support using otool), which doesn't seem to make any difference in its usage.


回答1:


When you build the library normally, with ENABLE_BITCODE=YES, Xcode adds the build flag -fembed-bitcode-marker to any clang invocation, placing an "empty" bitcode in the final o file.

So, if you look to the compile action in the build phase, it will look something like:

CompileC {build_path}/StaticBitcode/StaticLogger.o StaticBitcode/StaticLogger.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler cd {path}/StaticBitcode export LANG=en_US.US-ASCII export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -gmodules -fmodules-cache- [...] -fembed-bitcode-marker [...]

This is true to the build action (independent of the target).

When you Build & Archive, the -fembed flag is replaced by -fembed-bitcode, which really does build a Bitcode enabled binary:

CompileC {build_path}/StaticBitcode/StaticLogger.o StaticBitcode/StaticLogger.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler cd {path}/StaticBitcode export LANG=en_US.US-ASCII export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -gmodules -fmodules-cache- [...] -fembed-bitcode [...]


fembed-bitcode flag

Given that, if you add the -fembed-bitcode flag to the Other C flags, you will be sending two flags to the compiler during the compile time. It maybe silence some warnings that you can receive when using the library linked on another project. But, you need to check if you get the expected behavior. :)

(When I tested using the -fembed-bitcode on the Other C flags, Xcode gave the warning clang: warning: argument unused during compilation: '-fembed-bitcode-marker')


BITCODE_GENERATION_MODE

On the other hand,

If you set BITCODE_GENERATION_MODE=bitcode on your User-defined Setting, even during the build phase, the files will be compiled using the flag -fembed-bitcode.

And, if you set BITCODE_GENERATION_MODE=marker, the files will be compiled using the flag -fembed-bitcode-marker, independent of the action phase.

So, if you want to enable the bitcode to every action (build and archive), the better way to do so is using the BITCODE_GENERATION_MODE setting.


Resources

  • How do I xcodebuild a static library with Bitcode enabled?
  • Apple DevForums: Bitcode and Assembly?
  • SO: iOS library to BitCode


来源:https://stackoverflow.com/questions/34959767/whats-the-difference-between-fembed-bitcode-and-bitcode-generation-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!