Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check a static library is built contain bitcode?

Tags:

bitcode

I have a static library that is built by other company. I want to know if it's a static library containing bitcode, which command can detect it in terminal?

like image 341
xCocoa Avatar asked Sep 24 '15 07:09

xCocoa


People also ask

What is Bitcode enabled?

Bitcode-enabled builds When this option is disabled, the compiler generates an executable file that only contains machine code. But when it is enabled, the bitcode is included in the executable file alongside the generated machine code.

Is Bitcode required?

For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS apps, bitcode is required.


1 Answers

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 i386).

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 
like image 100
Oliver Avatar answered Oct 06 '22 09:10

Oliver