Each ld invocation within the clang command needs a unique filename on the
-object_path_lto option so that dsymutil can extract debug info for all compiled
slices. In the current code, every slice uses the same temporary filename and
as a result only one slice of debug info ends up in the dSYM.
clang already knows how to use -object_path_file and dsymutil for multiarch
builds correctly so use that method instead. There is however a strange quirk.
clang will only do this if there is at least one non-object in the command that
performs a link (this doesn't make sense in my opinion). To work around this
we include a nearly-empty file (empty causes warnings) in the linking clang
invocation.
I've posted https://reviews.llvm.org/D84572 which will (eventually) allow us to remove this emit+move dance by adding -external-dsym-dir=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR} to the cflags/cxxflags in order to emit the dSYM in the desired location to begin with.