6

When building a library that is to be used in bitcode-enabled apps, does each arch in the fat binary need to be built with -fembed-bitcode or only one of them?

One of them because the bitcode is architecture-independent and will just be duplicated?

All of them because pre-processor commands may alter the code based on architecture (e.g. NSInteger width)?

Excluding x86 slices otherwise duplicate symbol _llvm.cmdline happens? - rdar://21884601

OrangeDog
  • 36,653
  • 12
  • 122
  • 207

1 Answers1

8

Bitcode is just another form of LLVM IR, which is architecture-dependent.

Which means that each slice in your fat binary should contain its own bitcode section.

Update: I wrote a blog-post about Bitcode, you may find there some useful details: Bitcode Demystified

mfaani
  • 33,269
  • 19
  • 164
  • 293
AlexDenisov
  • 4,022
  • 25
  • 31
  • Where does it say bitcode is architecture-dependent? – OrangeDog Jul 31 '15 at 10:11
  • Fair enough. Can't find it in documentation as well. But I can say for sure that's different for each slice. You can check it out manually by calling `clang -S -emit-llvm -arch arch_name main.c` using different 'arch_name' and discover LLVM IR. – AlexDenisov Jul 31 '15 at 10:17
  • I though the whole point of including bitcode was so Apple can compile it for different architectures in the future. – OrangeDog Apr 10 '17 at 16:30
  • In fact, if you do not include bitcode for each arch, you'll get failures at archive time. – Dan Field Aug 27 '19 at 20:22