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 Engineering 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 ?