How to check a static library is built contain bitcode?

白昼怎懂夜的黑 提交于 2019-11-29 19:26:58
Oliver

As it was alread written in other answers,

otool -l yourlib.a | grep __LLVM

is the way to go.

An Apple engineer says using

otool -l yourlib.a | grep bitcode

is not reliable.

Searching for a "bitcode" section is not a reliable way to detect if your files contain embedded bitcode. If you want to do that, search for the "__LLVM" segment. You should be aware that a normal build with the -fembed-bitcode-marker option will produce minimal size embedded bitcode sections without any real content. This is done as a way of testing the bitcode-related aspects of your build without slowing down the build process. The actual bitcode content is included when you do an Archive build.

See also the comments by xCocoa.

It seems, that otool does not report the bitcode if code for the iPhone Simulator's architecture is included (x86_64 or arm64).

You can list the lib's architectures with:

lipo -info yourlib.a

Then you can check for bitcode for each architecture separately, e.g:

otool -arch armv7 -l yourlib.a  | grep bitcode
otool -arch arm64 -l yourlib.a  | grep bitcode

Disclaimer: I'm the author of LibEBC.

You can use ebcutil to see whether bitcode is present in a Mach-O binary or library. You can even use it to extract the embedded bitcode from it.

https://github.com/JDevlieghere/LibEBC

It is recommended to test against LLVM symbols:

otool -l yourlib.a | grep LLVM

You should get some lines with "__LLVM"

Naishta

And if you want to check if a specific file (yourFile.o) in the static library is bitcode enabled, you can extract the 'staticLibrary.a' and use the same otool command. However macOS doesn't allow to extract your staticLibrary.a at times with the default extract utility and most 3rd party tools doesn't work either.

You can follow these steps to check specific .o files

  1. Get the info of the architecture

    lipo -info yourStaticLibrary.a
    

eg output: armv7 arm64

  1. Extract yourStaticLibrary.a for any or both of the above architecture

    lipo yourStaticLibrary.a -thin armv7 -output yourStaticLibraryarmv7.a
    

(specify the output path you want to extract to)

  1. You get the 'yourStaticLibraryarmv7.a' which then can be easily extracted with the default mac unarchiver

  2. On extracting, you then get a folder 'yourStaticLibraryarmv7' containing all the .o files

  3. otool -l yourFile.o | grep bitcode or with the specific architecture

    otool -arch armv7 -l yourFile.o  | grep bitcode
    

If the file is bitcode enabled , you get 'sectname __bitcode' in the commandline

gheni4

You can try: otool -l (.o or .a file)

and look for "__bitcode" section

It was answered here: How do I xcodebuild a static library with Bitcode enabled?

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