Ensure ModuleLinker materializes complete comdat groups
authorTeresa Johnson <tejohnson@google.com>
Tue, 10 Nov 2015 21:09:06 +0000 (21:09 +0000)
committerTeresa Johnson <tejohnson@google.com>
Tue, 10 Nov 2015 21:09:06 +0000 (21:09 +0000)
commitd1fec24fb5de8fe9ff65258a79989b7d7694c441
treeaf0107656475c805151c1eea0ee72f970fe7f8bc
parent4afa7f1d5714a58ab1e79f749652872d666177a8
Ensure ModuleLinker materializes complete comdat groups

Summary:
The module linker lazy links some "discardable if unused" global
values (e.g. linkonce), materializing and linking them only
if they are referenced in the module. If a comdat group contains a
linkonce member that is not referenced, however, it would not be
materialized and linked, leading to an incomplete comdat group.

If there are other object files not part of the same LTO link that also
define and use that comdat group, the linker may select the incomplete
group leading to link time unsats.

To solve this, whenever a global value body is linked, make sure we
materialize any other members of the same comdat group that are not yet
materialized. This ensures they are in the lazy link list and get linked
as well.

Added new test and adjusted old test to remove parts that didn't
make sense with fix.

Reviewers: rafael

Subscribers: dexonsmith, davidxl, llvm-commits

Differential Revision: http://reviews.llvm.org/D14516

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252647 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Linker/LinkModules.cpp
test/Linker/Inputs/only-needed-named-metadata.ll
test/Linker/comdat_group.ll [new file with mode: 0644]
test/Linker/only-needed-named-metadata.ll