From d7e88e515c19ccf7ca21d01f1762697a67e1da8e Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 8 Feb 2016 18:47:20 +0000 Subject: [ThinLTO] Remove imported available externally defs from comdats. Summary: Available externally definitions are considered declarations for the linker and eventually dropped. As such they are not allowed to be in comdats. Remove any such imported functions from comdats. Reviewers: rafael Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D16120 llvm-svn: 260122 --- llvm/lib/Linker/LinkModules.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Linker') diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index a9b8ef2470b..4bb4b3f4f23 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -722,9 +722,21 @@ void ThinLTOGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) { GV.setVisibility(GlobalValue::HiddenVisibility); if (isModuleExporting()) NewExportedValues.insert(&GV); - return; + } else + GV.setLinkage(getLinkage(&GV)); + + // Remove functions imported as available externally defs from comdats, + // as this is a declaration for the linker, and will be dropped eventually. + // It is illegal for comdats to contain declarations. + auto *GO = dyn_cast_or_null(&GV); + if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) { + // The IRMover should not have placed any imported declarations in + // a comdat, so the only declaration that should be in a comdat + // at this point would be a definition imported as available_externally. + assert(GO->hasAvailableExternallyLinkage() && + "Expected comdat on definition (possibly available external)"); + GO->setComdat(nullptr); } - GV.setLinkage(getLinkage(&GV)); } void ThinLTOGlobalProcessing::processGlobalsForThinLTO() { -- cgit v1.2.3