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?
Asked
Active
Viewed 355 times
1 Answers
1
Yes. Static libraries can contain llvm-IR-bitcode also.
A. Step for build static libs with llvm-IR-bitcode
- In Xcode Static Lib Project:
Build Settings->Enable Bitcode
, Switch toYes
Product->Archive
B. Check if a static lib contains llvm-IR-bitcode or not.
otool -l libDemo.a
- In the output, search for
__bitcode
and check whether thesize
is bigger than 000001 or not.
ifsize
> 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