How to check a static library is built contain bitcode?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

How to check a static library is built contain 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?




5 Answers
5



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


otool



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





Is the following correct: if static library was not build with ENABLE_BITCODE=NO it cannot be used from target which has ENABLE_BITCODE=YES? Is opposite correct too?
– Yevhen Dubinin
Jun 29 '16 at 13:34


ENABLE_BITCODE=NO


ENABLE_BITCODE=YES





@EugeneDubinin Bitcode is just some extra information, so having it does no harm besides a slightly increased size. However, the lack of bitcode in the binary means you can't link it against a target that requires bitcode (i.e. bitcode is enabled).
– Mazyod
Aug 1 '16 at 6:50





Be aware that if you compile with -fembed-bitcode-marker and not -fembed-bitcode (inspect your compiler output), you may get a false positive with these commands, as the bitcode "marker" is present, just not the actual bitcode. This answer has more info on that.
– William Denniss
Nov 9 '17 at 1:09



-fembed-bitcode-marker


-fembed-bitcode





Following up on @WilliamDenniss's answer you can check for the false positive by grepping for bitcode in the otool results and then looking at the size field 4 lines after that. (you can use the -A 4 parameter to see the next 4 lines after the grep match) If the size is 1 then it means that -fembed-bitcode was not set and the library does not contain bitcode.
– Deemoe
Jul 18 at 17:35




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.


ebcutil



https://github.com/JDevlieghere/LibEBC





I tried using the library but on the latest macOS, it doesn't seem to compile at all.
– jarora
Nov 9 '17 at 13:42





Feel free to open an issue on GitHub.
– Jonas
Nov 10 '17 at 16:00





github.com/JDevlieghere/LibEBC/issues/5
– jarora
Nov 10 '17 at 18:47



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.


(yourFile.o)


'staticLibrary.a'


otool



You can follow these steps to check specific .o files


.o



Get the info of the architecture


lipo -info yourStaticLibrary.a



eg output: armv7 arm64



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


yourStaticLibrary.a


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



(specify the output path you want to extract to)



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


'yourStaticLibraryarmv7.a'



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


yourStaticLibraryarmv7'



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


otool -l yourFile.o | grep bitcode


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



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





the default mac unarchiver was giving me grief, so you can try this command ar -t yourStaticLibraryarmv7.a to see the list of .o files, and ar -xv yourStaticLibraryarmv7.a yourFile.o
– yano
Oct 25 '17 at 23:23


ar -t yourStaticLibraryarmv7.a


ar -xv yourStaticLibraryarmv7.a yourFile.o





@yano That doesn't work for me I get ar:***.a: Inappropriate file type or format when running ar -t ***.a, I followed instructions to remove the armv7 slice as stated in the answer
– marchinram
May 1 at 16:17



ar:***.a: Inappropriate file type or format


ar -t ***.a



It is recommended to test against LLVM symbols:



otool -l yourlib.a | grep LLVM



You should get some lines with "__LLVM"





I try it,but not found anything,the yourlib.a is contain bitcode,i'm sure.
– xCocoa
Sep 25 '15 at 2:37





Have you build for Archive?
– SeikoTheWiz
Sep 25 '15 at 7:20





Could you please indicate the source of your claim? Why should I grep for LLVM?
– Paul
Feb 3 '16 at 10:55



LLVM





See this answer regarding searching for "__LLVM".
– Quintin Willison
Jun 9 '16 at 11:27



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?





My development is Xcode7 and EI Capitan 10.11.1,i used the command,but can not found "__bitcode" section
– xCocoa
Sep 25 '15 at 2:34






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Trying to Print Gridster Items to PDF without overlapping contents