What is the difference between `-fembed-bitcode` and BITCODE_GENERATION_MODE?

I am updating the static library to support bit code, and from my research I have found two ways to achieve this:

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

Is there a difference between the two?

The only difference I noticed is that when using fembed-bitcode resulting static library for iphonesimulator will be built with the full bit code enabled (in my case, the size of the binary size varies from 5 MB to 13 MB, and I can check the bitcode support using otool ), which, apparently, does not affect its use.

+18
objective-c bitcode static-libraries
Jan 23 '16 at 4:53 on
source share
1 answer

When you usually create a library, ENABLE_BITCODE=YES , Xcode adds the -fembed-bitcode-marker assembly flag to any clang call, placing the "empty" bitcode in the last o file.

So, if you look at compilation in the build phase, it will look something like this:

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 = ru_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/ben : / 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 applies to assembly action (regardless of purpose).

When you are Build & Archive , the -fembed flag -fembed replaced with -fembed-bitcode , which does create binary code that supports bit code:

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 = ru_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/ben : / 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 send two flags to the compiler at compile time. You might turn off some warnings you might get when using the library associated with another project. But you need to check if you have the expected behavior. :)

(When I tested with -fembed-bitcode on other C flags, Xcode issued a warning clang: warning: argument unused during compilation: '-fembed-bitcode-marker' )


BITCODE_GENERATION_MODE

On the other hand,

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

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

So, if you want to include a bit code for each action (build and archive), the best way to do this is to use the BITCODE_GENERATION_MODE parameter.


Resources

+26
Jan 23 '16 at 15:18
source share
— -



All Articles