The verifier complains if a declaration is in a comdat. However,
the module linker speculatively adds linked global values that are
in comdats in the source module into comdats in the destination module,
which assumes their bodies will also be linked.
For ThinLTO we may not link the body if it isn't an imported function.
Also, with currently reverted patch r251926 (D14195: Move metadata
linking after lazy global materialization/linking), during an LTO build
a function referenced only from metadata will not have its definition
linked and will become a declaration. If it was in a comdat it will also
hit the verifier error.
To handle this, delay setting up comdats on the Dest module until after
all global value bodies have been linked, so that we know which are
definitions vs declarations in Dest.
This change is an enabler for resubmitting r251926, and also for some
follow-on fixes for ThinLTO comdat handling I discovered in the process
of working on these changes.
Is is possible to just iterate over ComdatsChosen?