Adding bitcode to an existing MachO object file

This is a silly question, but I am in a situation where I need to build x86 and arm assembly sources for some sources while the rest will be built with C. I do know that just adding -fembed-bitcode to a C sources would embed bitcode, but doing the same for the assembly files will not do that (at least, it will add the 1-byte _LLVM,__asm section, but not the __LLVM,__bitcode section). Furthermore, I do need the final output to contain bitcode for all files used.

So, my question is if it is possible to add the __LLVM,__bitcode section later to the MachO object file. I tried to archive the bitcode using xar and run llvm-objcopy main.o --add-section=__LLVM,__bitcode=main.xar main2.o, but it failed with an unsupported load command. This seems to be the case for all usages of llvm-objcopy with MachO files.

Cheers and thanks

– Joseph

What version of llvm-objcopy are you using? I know it’s had many fixes for Mach-O recently. If you’re running into a bug with the latest llvm-objcopy (from the master branch), it’d be great if you could file a bug on with your input file (if possible).

Many thanks for your comment! I was using the one from Brew (llvm 10, I believe). I’ll build master and run it from there and report back tomorrow

Hi Joseph,
yeah, if you run into any issues with the latest version (built from master) - please, file a bug on
Kind regards,