Index: llvm/trunk/include/llvm/Linker/Linker.h =================================================================== --- llvm/trunk/include/llvm/Linker/Linker.h +++ llvm/trunk/include/llvm/Linker/Linker.h @@ -30,9 +30,6 @@ OverrideFromSrc = (1 << 0), LinkOnlyNeeded = (1 << 1), InternalizeLinkedSymbols = (1 << 2), - /// Don't force link referenced linkonce definitions, import declaration. - DontForceLinkLinkonceODR = (1 << 3) - }; Linker(Module &M); @@ -41,13 +38,9 @@ /// /// Passing OverrideSymbols as true will have symbols from Src /// shadow those in the Dest. - /// For ThinLTO function importing/exporting the \p ModuleSummaryIndex - /// is passed. If \p GlobalsToImport is provided, only the globals that - /// are part of the set will be imported from the source module. /// /// Returns true on error. - bool linkInModule(std::unique_ptr Src, unsigned Flags = Flags::None, - DenseSet *GlobalsToImport = nullptr); + bool linkInModule(std::unique_ptr Src, unsigned Flags = Flags::None); static bool linkModules(Module &Dest, std::unique_ptr Src, unsigned Flags = Flags::None); Index: llvm/trunk/lib/Linker/LinkModules.cpp =================================================================== --- llvm/trunk/lib/Linker/LinkModules.cpp +++ llvm/trunk/lib/Linker/LinkModules.cpp @@ -15,11 +15,13 @@ #include "llvm-c/Linker.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringSet.h" +#include "llvm/IR/Comdat.h" #include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/Linker/Linker.h" #include "llvm/Support/Error.h" -#include "llvm/Transforms/Utils/FunctionImportUtils.h" using namespace llvm; namespace { @@ -36,19 +38,12 @@ /// For symbol clashes, prefer those from Src. unsigned Flags; - /// Functions to import from source module, all other functions are - /// imported as declarations instead of definitions. - DenseSet *GlobalsToImport; - /// Used as the callback for lazy linking. /// The mover has just hit GV and we have to decide if it, and other members /// of the same comdat, should be linked. Every member to be linked is passed /// to Add. void addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add); - bool shouldLinkReferencedLinkOnce() { - return !(Flags & Linker::DontForceLinkLinkonceODR); - } bool shouldOverrideFromSrc() { return Flags & Linker::OverrideFromSrc; } bool shouldLinkOnlyNeeded() { return Flags & Linker::LinkOnlyNeeded; } bool shouldInternalizeLinkedSymbols() { @@ -108,30 +103,14 @@ bool linkIfNeeded(GlobalValue &GV); - /// Helper method to check if we are importing from the current source - /// module. - bool isPerformingImport() const { return GlobalsToImport != nullptr; } - - /// If we are importing from the source module, checks if we should - /// import SGV as a definition, otherwise import as a declaration. - bool doImportAsDefinition(const GlobalValue *SGV); - public: - ModuleLinker(IRMover &Mover, std::unique_ptr SrcM, unsigned Flags, - DenseSet *GlobalsToImport = nullptr) - : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags), - GlobalsToImport(GlobalsToImport) {} + ModuleLinker(IRMover &Mover, std::unique_ptr SrcM, unsigned Flags) + : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags) {} bool run(); }; } -bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) { - if (!isPerformingImport()) - return false; - report_fatal_error("ModuleLinker does not support importing"); -} - static GlobalValue::VisibilityTypes getMinVisibility(GlobalValue::VisibilityTypes A, GlobalValue::VisibilityTypes B) { @@ -265,18 +244,10 @@ // We always have to add Src if it has appending linkage. if (Src.hasAppendingLinkage()) { - // Should have prevented importing for appending linkage in linkIfNeeded. - assert(!isPerformingImport()); LinkFromSrc = true; return false; } - if (isPerformingImport()) { - // LinkFromSrc iff this is a global requested for importing. - LinkFromSrc = GlobalsToImport->count(&Src); - return false; - } - bool SrcIsDeclaration = Src.isDeclarationForLinker(); bool DestIsDeclaration = Dest.isDeclarationForLinker(); @@ -382,19 +353,9 @@ GV.setUnnamedAddr(UnnamedAddr); } - // Don't want to append to global_ctors list, for example, when we - // are importing for ThinLTO, otherwise the global ctors and dtors - // get executed multiple times for local variables (the latter causing - // double frees). - if (GV.hasAppendingLinkage() && isPerformingImport()) - return false; - - if (isPerformingImport()) { - if (!doImportAsDefinition(&GV)) - return false; - } else if (!DGV && !shouldOverrideFromSrc() && - (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() || - GV.hasAvailableExternallyLinkage())) + if (!DGV && !shouldOverrideFromSrc() && + (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() || + GV.hasAvailableExternallyLinkage())) return false; if (GV.isDeclaration()) @@ -417,12 +378,6 @@ } void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) { - if (!shouldLinkReferencedLinkOnce()) - // For ThinLTO we don't import more than what was required. - // The client has to guarantee that the linkonce will be availabe at link - // time (by promoting it to weak for instance). - return; - // Add these to the internalize list if (!GV.hasLinkOnceLinkage() && !GV.hasAvailableExternallyLinkage() && !shouldLinkOnlyNeeded()) @@ -583,8 +538,8 @@ [this](GlobalValue &GV, IRMover::ValueAdder Add) { addLazyFor(GV, Add); }, - /* LinkModuleInlineAsm */ !isPerformingImport(), - /* IsPerformingImport */ isPerformingImport())) { + /* LinkModuleInlineAsm */ true, + /* IsPerformingImport */ false)) { handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { DstM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, EIB.message())); HasErrors = true; @@ -603,9 +558,8 @@ Linker::Linker(Module &M) : Mover(M) {} -bool Linker::linkInModule(std::unique_ptr Src, unsigned Flags, - DenseSet *GlobalsToImport) { - ModuleLinker ModLinker(Mover, std::move(Src), Flags, GlobalsToImport); +bool Linker::linkInModule(std::unique_ptr Src, unsigned Flags) { + ModuleLinker ModLinker(Mover, std::move(Src), Flags); return ModLinker.run(); }