1

This article discusses how object files can contain LLVM IR that is used for link-time optimization. But what if the linker is compiling a project that includes a static library, do static libraries have the information as well? If so, under which circumstances?

meisel
  • 2,151
  • 2
  • 21
  • 38

1 Answers1

1

Yes. Static libraries can contain llvm-IR-bitcode also.

A. Step for build static libs with llvm-IR-bitcode

  1. In Xcode Static Lib Project:
    Build Settings->Enable Bitcode , Switch to Yes
  2. Product->Archive

B. Check if a static lib contains llvm-IR-bitcode or not.

  1. otool -l libDemo.a
  2. In the output, search for __bitcode and check whether the size is bigger than 000001 or not.
    if size > 000001 : then the static lib contain llvm-IR-bitcode
    else: the static lib do not contain llvm-IR-bitcode.

Wish this answers your question.

Community
  • 1
  • 1
Simon Huang
  • 334
  • 2
  • 7
  • Does this mean bitcode needs to also be enabled for the object files that are being given to the linker? – meisel Oct 15 '19 at 14:41
  • It depends, If you need the bitcode been included in the final generated binary file, then, the answer is `yes`. If you just do something (maybe bitcode optimization just like I do), then you then answer is `no`. – Simon Huang Nov 27 '20 at 10:26