Bitcode XML .xar corrupted after llvm-link

Hi all, I’m facing the next problem with a Xcode project with mixed Swift, Objective-C and C++ code:

Context: How Uber Deals with Large iOS App Size | Uber Blog.

I’m trying to do the same as Uber did in that article, I was able to replicate it, but the problem comes when embed bitcode is enabled.

1.- I compile with Xcode with -emit-bc (for swift compiler) and flto=thin (clang compiler). Also I enable bitcode in Xcode settings (that adds -fembed-bitcode flag)

2.- Then, I link all the files in a single one

llvm-link file1.bc file2.bc file3.ll ... -o app.ll

3.- I run the optimizer

OPT app.ll -code-model=small -Oz -cost-kind=code-size -objc-arc-contract -o app.opt

4.- Then I run the llc to get the object file

llc app.opt -filetype=obj -code-model=small -o app.o

5.- Finally I link it through clang

clang -filelist WholeApp.LinkFileList -dead_strip -no_deduplicate -fembed-bitcode -fobjc-link-runtime -o app.exec

Where WholeApp.LinkFileList just contains the path to app.o

All the process is successful, but if i try to recompile from bitcode it fails due to this:

Left: Good XML

Right: Bad XML

(extracted from the .xar taken from __bundle section __LLVM segment)

Any Idea what am I doing wrong? or what is the correct way to generate the bitcode metadata from a file generated with llvm-link ?

Hey friend, have you figured out the solution? I’m currently working on this too, thinking a way to deal with xcode settings to do this job. Custom some of the link tools


Unfortunately I haven’t found a solution, I ended up disabling Bitcode for now.

I had a WWDC lab with Apple Devs regarding this, and they suggested to me to edit the __LLVM, __cmdline section of app.ll (more info here Embedded Bitcode)
Basically, that section contains the commands that bitcode-build-tool uses to rebuild the application from the Bitcode section. You can find bitcode-build-tool in the Xcode directory, or use this repo as a reference bitcode-build-tool
In our case, __LLVM, __cmdline contains the concatenated instructions of each file that was linked with llvm-link, so the idea is to rewrite that section (or even better to add this capability to the LLVM tools in some way) to contain only one instruction since now we only have 1 file containing the complete application. But that was only an idea, not really sure if it’s gonna work.
I have not tried it myself, but I will post here what happens with that.

Thanks for your reply. Guess I’ll turn that off for now too.

And if bitcode is turned off.

are you taking this all out on a project with pods? How are you doing this with pods? Would you mind sharing some info on that?

Sorry for the delay. And yes I am. I’m doing this taking into account pods.
I made a medium post explaining all you need to know, and there’s also a GitHub repo with an example

Thanks, really appreciated.