[LTO] Don't apply LTOPostLink module flag during writeMergedModule
authorSteven Wu <stevenwu@apple.com>
Wed, 26 Aug 2020 18:17:26 +0000 (11:17 -0700)
committerSteven Wu <stevenwu@apple.com>
Wed, 26 Aug 2020 18:17:45 +0000 (11:17 -0700)
commit476ca330894bf42feeb6c13547d14c821f6b8e0a
tree99ac70aa608329d405d6d8c282e6474b111ef403
parent6538fff37245921a0983d94c08af7e6cc120b3a9
[LTO] Don't apply LTOPostLink module flag during writeMergedModule

For `ld64` which uses legacy LTOCodeGenerator, it relies on
writeMergedModule to perform `ld -r` (generates a linked object file).
If all the inputs to `ld -r` is fullLTO bitcode, `ld64` will linked the
bitcode module, internalize all the symbols and write out another
fullLTO bitcode object file. This bitcode file doesn't have all the
bitcode inputs and it should not have LTOPostLink module flag. It will
also cause error when this bitcode object file is linked with other LTO
object file.
Fix the issue by not applying LTOPostLink flag during writeMergedModule
function. The flag should only be added when all the bitcode are linked
and ready to be optimized.

rdar://problem/58462798

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D84789
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/test/LTO/ARM/lto-linking-metadata.ll
llvm/tools/llvm-lto/llvm-lto.cpp