llvm.org GIT mirror llvm / 0292f06
Restore "Support for ThinLTO function importing and symbol linking." This restores commit r251837, with the new library dependence added to llvm-link/Makefile to address bot failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251866 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
14 changed file(s) with 763 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
6363 DiagnosticHandlerFunction DiagnosticHandler);
6464
6565 /// Parse the specified bitcode buffer, returning the function info index.
66 /// If ExportingModule is true, check for functions in the index from this
67 /// module when the combined index is built during parsing and set flag.
6668 /// If IsLazy is true, parse the entire function summary into
6769 /// the index. Otherwise skip the function summary section, and only create
6870 /// an index object with a map from function name to function summary offset.
7072 ErrorOr>
7173 getFunctionInfoIndex(MemoryBufferRef Buffer, LLVMContext &Context,
7274 DiagnosticHandlerFunction DiagnosticHandler,
75 const Module *ExportingModule = nullptr,
7376 bool IsLazy = false);
7477
7578 /// This method supports lazy reading of function summary data from the
164164 /// Holds strings for combined index, mapping to the corresponding module ID.
165165 ModulePathStringTableTy ModulePathStringTable;
166166
167 /// The main module being compiled, that we are importing into, if applicable.
168 /// Used to check if any of its functions are in the index and therefore
169 /// potentially exported.
170 const Module *ExportingModule;
171
172 /// Flag indicating whether the exporting module has any functions in the
173 /// index and therefore potentially exported (imported into another module).
174 bool HasExportedFunctions;
175
167176 public:
168 FunctionInfoIndex() = default;
177 FunctionInfoIndex(const Module *M = nullptr)
178 : ExportingModule(M), HasExportedFunctions(false){};
169179 ~FunctionInfoIndex() = default;
170180
171181 // Disable the copy constructor and assignment operators, so
185195
186196 /// Add a function info for a function of the given name.
187197 void addFunctionInfo(StringRef FuncName, std::unique_ptr Info) {
198 if (ExportingModule) {
199 assert(Info->functionSummary());
200 if (ExportingModule->getModuleIdentifier() ==
201 Info->functionSummary()->modulePath())
202 HasExportedFunctions = true;
203 }
188204 FunctionMap[FuncName].push_back(std::move(Info));
189205 }
190206
222238 return ModulePathStringTable.insert(std::make_pair(ModPath, ModId))
223239 .first->first();
224240 }
241
242 /// Check if the given Module has any functions available for exporting
243 /// in the index.
244 bool hasExportedFunctions(const Module *M) {
245 assert(M == ExportingModule &&
246 "Checking for exported functions on unexpected module");
247 return HasExportedFunctions;
248 }
225249 };
226250
227251 } // End llvm namespace
1313 #include "llvm/ADT/DenseMap.h"
1414 #include "llvm/ADT/DenseSet.h"
1515 #include "llvm/IR/DiagnosticInfo.h"
16 #include "llvm/IR/FunctionInfo.h"
1617
1718 namespace llvm {
1819 class Module;
7576 /// \brief Link \p Src into the composite. The source is destroyed.
7677 /// Passing OverrideSymbols as true will have symbols from Src
7778 /// shadow those in the Dest.
79 /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
80 /// is passed. If a \p FuncToImport is provided, only that single
81 /// function is imported from the source module.
7882 /// Returns true on error.
79 bool linkInModule(Module *Src, unsigned Flags = Flags::None);
83 bool linkInModule(Module *Src, unsigned Flags = Flags::None,
84 FunctionInfoIndex *Index = nullptr,
85 Function *FuncToImport = nullptr);
8086
8187 /// \brief Set the composite to the passed-in module.
8288 void setModule(Module *Dst);
1717
1818 namespace llvm {
1919 class FunctionInfoIndex;
20 class Module;
2021
2122 namespace object {
2223 class ObjectFile;
8384 /// Return new FunctionIndexObjectFile instance containing parsed function
8485 /// summary/index.
8586 static ErrorOr>
86 create(MemoryBufferRef Object, LLVMContext &Context, bool IsLazy = false);
87 create(MemoryBufferRef Object, LLVMContext &Context,
88 const Module *ExportingModule = nullptr, bool IsLazy = false);
8789
8890 /// \brief Parse the function summary information for function with the
8991 /// given name out of the given buffer. Parsed information is
58125812 ErrorOr>
58135813 llvm::getFunctionInfoIndex(MemoryBufferRef Buffer, LLVMContext &Context,
58145814 DiagnosticHandlerFunction DiagnosticHandler,
5815 bool IsLazy) {
5815 const Module *ExportingModule, bool IsLazy) {
58165816 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false);
58175817 FunctionIndexBitcodeReader R(Buf.get(), Context, DiagnosticHandler, IsLazy);
58185818
58195819 std::unique_ptr Index =
5820 llvm::make_unique();
5820 llvm::make_unique(ExportingModule);
58215821
58225822 auto cleanupOnError = [&](std::error_code EC) {
58235823 R.releaseBuffer(); // Never take ownership on error.
368368 TypeMapTy &TypeMap;
369369 Module *DstM;
370370 std::vector &LazilyLinkGlobalValues;
371 ModuleLinker *ModLinker;
371372
372373 public:
373374 ValueMaterializerTy(TypeMapTy &TypeMap, Module *DstM,
374 std::vector &LazilyLinkGlobalValues)
375 std::vector &LazilyLinkGlobalValues,
376 ModuleLinker *ModLinker)
375377 : ValueMaterializer(), TypeMap(TypeMap), DstM(DstM),
376 LazilyLinkGlobalValues(LazilyLinkGlobalValues) {}
378 LazilyLinkGlobalValues(LazilyLinkGlobalValues), ModLinker(ModLinker) {}
377379
378380 Value *materializeValueFor(Value *V) override;
379381 };
426428 /// For symbol clashes, prefer those from Src.
427429 unsigned Flags;
428430
431 /// Function index passed into ModuleLinker for using in function
432 /// importing/exporting handling.
433 FunctionInfoIndex *ImportIndex;
434
435 /// Function to import from source module, all other functions are
436 /// imported as declarations instead of definitions.
437 Function *ImportFunction;
438
439 /// Set to true if the given FunctionInfoIndex contains any functions
440 /// from this source module, in which case we must conservatively assume
441 /// that any of its functions may be imported into another module
442 /// as part of a different backend compilation process.
443 bool HasExportedFunctions;
444
429445 public:
430446 ModuleLinker(Module *dstM, Linker::IdentifiedStructTypeSet &Set, Module *srcM,
431 DiagnosticHandlerFunction DiagnosticHandler, unsigned Flags)
447 DiagnosticHandlerFunction DiagnosticHandler, unsigned Flags,
448 FunctionInfoIndex *Index = nullptr,
449 Function *FuncToImport = nullptr)
432450 : DstM(dstM), SrcM(srcM), TypeMap(Set),
433 ValMaterializer(TypeMap, DstM, LazilyLinkGlobalValues),
434 DiagnosticHandler(DiagnosticHandler), Flags(Flags) {}
451 ValMaterializer(TypeMap, DstM, LazilyLinkGlobalValues, this),
452 DiagnosticHandler(DiagnosticHandler), Flags(Flags), ImportIndex(Index),
453 ImportFunction(FuncToImport), HasExportedFunctions(false) {
454 assert((ImportIndex || !ImportFunction) &&
455 "Expect a FunctionInfoIndex when importing");
456 // If we have a FunctionInfoIndex but no function to import,
457 // then this is the primary module being compiled in a ThinLTO
458 // backend compilation, and we need to see if it has functions that
459 // may be exported to another backend compilation.
460 if (ImportIndex && !ImportFunction)
461 HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
462 }
435463
436464 bool run();
437465
440468 bool shouldInternalizeLinkedSymbols() {
441469 return Flags & Linker::InternalizeLinkedSymbols;
442470 }
471
472 /// Handles cloning of a global values from the source module into
473 /// the destination module, including setting the attributes and visibility.
474 GlobalValue *copyGlobalValueProto(TypeMapTy &TypeMap, const GlobalValue *SGV,
475 const GlobalValue *DGV = nullptr);
476
477 /// Check if we should promote the given local value to global scope.
478 bool doPromoteLocalToGlobal(const GlobalValue *SGV);
443479
444480 private:
445481 bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest,
507543 void linkAliasBody(GlobalAlias &Dst, GlobalAlias &Src);
508544 bool linkGlobalValueBody(GlobalValue &Src);
509545
546 /// Functions that take care of cloning a specific global value type
547 /// into the destination module.
548 GlobalVariable *copyGlobalVariableProto(TypeMapTy &TypeMap,
549 const GlobalVariable *SGVar);
550 Function *copyFunctionProto(TypeMapTy &TypeMap, const Function *SF);
551 GlobalValue *copyGlobalAliasProto(TypeMapTy &TypeMap, const GlobalAlias *SGA);
552
553 /// Helper methods to check if we are importing from or potentially
554 /// exporting from the current source module.
555 bool isPerformingImport() { return ImportFunction != nullptr; }
556 bool isModuleExporting() { return HasExportedFunctions; }
557
558 /// If we are importing from the source module, checks if we should
559 /// import SGV as a definition, otherwise import as a declaration.
560 bool doImportAsDefinition(const GlobalValue *SGV);
561
562 /// Get the name for SGV that should be used in the linked destination
563 /// module. Specifically, this handles the case where we need to rename
564 /// a local that is being promoted to global scope.
565 std::string getName(const GlobalValue *SGV);
566
567 /// Get the new linkage for SGV that should be used in the linked destination
568 /// module. Specifically, for ThinLTO importing or exporting it may need
569 /// to be adjusted.
570 GlobalValue::LinkageTypes getLinkage(const GlobalValue *SGV);
571
572 /// Copies the necessary global value attributes and name from the source
573 /// to the newly cloned global value.
574 void copyGVAttributes(GlobalValue *NewGV, const GlobalValue *SrcGV);
575
576 /// Updates the visibility for the new global cloned from the source
577 /// and, if applicable, linked with an existing destination global.
578 /// Handles visibility change required for promoted locals.
579 void setVisibility(GlobalValue *NewGV, const GlobalValue *SGV,
580 const GlobalValue *DGV = nullptr);
581
510582 void linkNamedMDNodes();
511583 void stripReplacedSubprograms();
512584 };
518590 static void forceRenaming(GlobalValue *GV, StringRef Name) {
519591 // If the global doesn't force its name or if it already has the right name,
520592 // there is nothing for us to do.
593 // Note that any required local to global promotion should already be done,
594 // so promoted locals will not skip this handling as their linkage is no
595 // longer local.
521596 if (GV->hasLocalLinkage() || GV->getName() == Name)
522597 return;
523598
535610
536611 /// copy additional attributes (those not needed to construct a GlobalValue)
537612 /// from the SrcGV to the DestGV.
538 static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
539 DestGV->copyAttributesFrom(SrcGV);
540 forceRenaming(DestGV, SrcGV->getName());
613 void ModuleLinker::copyGVAttributes(GlobalValue *NewGV,
614 const GlobalValue *SrcGV) {
615 auto *GA = dyn_cast(SrcGV);
616 // Check for the special case of converting an alias (definition) to a
617 // non-alias (declaration). This can happen when we are importing and
618 // encounter a weak_any alias (weak_any defs may not be imported, see
619 // comments in ModuleLinker::getLinkage) or an alias whose base object is
620 // being imported as a declaration. In that case copy the attributes from the
621 // base object.
622 if (GA && !dyn_cast(NewGV)) {
623 assert(isPerformingImport() &&
624 (GA->hasWeakAnyLinkage() ||
625 !doImportAsDefinition(GA->getBaseObject())));
626 NewGV->copyAttributesFrom(GA->getBaseObject());
627 } else
628 NewGV->copyAttributesFrom(SrcGV);
629 forceRenaming(NewGV, getName(SrcGV));
541630 }
542631
543632 static bool isLessConstraining(GlobalValue::VisibilityTypes a,
553642 return false;
554643 }
555644
645 bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) {
646 if (!isPerformingImport())
647 return false;
648 // Always import GlobalVariable definitions. The linkage changes
649 // described in ModuleLinker::getLinkage ensure the correct behavior (e.g.
650 // global variables with external linkage are transformed to
651 // available_externally defintions, which are ultimately turned into
652 // declaratios after the EliminateAvailableExternally pass).
653 if (dyn_cast(SGV) && !SGV->isDeclaration())
654 return true;
655 // Only import the function requested for importing.
656 auto *SF = dyn_cast(SGV);
657 if (SF && SF == ImportFunction)
658 return true;
659 // Otherwise no.
660 return false;
661 }
662
663 bool ModuleLinker::doPromoteLocalToGlobal(const GlobalValue *SGV) {
664 assert(SGV->hasLocalLinkage());
665 // Both the imported references and the original local variable must
666 // be promoted.
667 if (!isPerformingImport() && !isModuleExporting())
668 return false;
669
670 // Local const variables never need to be promoted unless they are address
671 // taken. The imported uses can simply use the clone created in this module.
672 // For now we are conservative in determining which variables are not
673 // address taken by checking the unnamed addr flag. To be more aggressive,
674 // the address taken information must be checked earlier during parsing
675 // of the module and recorded in the function index for use when importing
676 // from that module.
677 auto *GVar = dyn_cast(SGV);
678 if (GVar && GVar->isConstant() && GVar->hasUnnamedAddr())
679 return false;
680
681 // Eventually we only need to promote functions in the exporting module that
682 // are referenced by a potentially exported function (i.e. one that is in the
683 // function index).
684 return true;
685 }
686
687 std::string ModuleLinker::getName(const GlobalValue *SGV) {
688 // For locals that must be promoted to global scope, ensure that
689 // the promoted name uniquely identifies the copy in the original module,
690 // using the ID assigned during combined index creation. When importing,
691 // we rename all locals (not just those that are promoted) in order to
692 // avoid naming conflicts between locals imported from different modules.
693 if (SGV->hasLocalLinkage() &&
694 (doPromoteLocalToGlobal(SGV) || isPerformingImport()))
695 return FunctionInfoIndex::getGlobalNameForLocal(
696 SGV->getName(),
697 ImportIndex->getModuleId(SGV->getParent()->getModuleIdentifier()));
698 return SGV->getName();
699 }
700
701 GlobalValue::LinkageTypes ModuleLinker::getLinkage(const GlobalValue *SGV) {
702 // Any local variable that is referenced by an exported function needs
703 // to be promoted to global scope. Since we don't currently know which
704 // functions reference which local variables/functions, we must treat
705 // all as potentially exported if this module is exporting anything.
706 if (isModuleExporting()) {
707 if (SGV->hasLocalLinkage() && doPromoteLocalToGlobal(SGV))
708 return GlobalValue::ExternalLinkage;
709 return SGV->getLinkage();
710 }
711
712 // Otherwise, if we aren't importing, no linkage change is needed.
713 if (!isPerformingImport())
714 return SGV->getLinkage();
715
716 switch (SGV->getLinkage()) {
717 case GlobalValue::ExternalLinkage:
718 // External defnitions are converted to available_externally
719 // definitions upon import, so that they are available for inlining
720 // and/or optimization, but are turned into declarations later
721 // during the EliminateAvailableExternally pass.
722 if (doImportAsDefinition(SGV))
723 return GlobalValue::AvailableExternallyLinkage;
724 // An imported external declaration stays external.
725 return SGV->getLinkage();
726
727 case GlobalValue::AvailableExternallyLinkage:
728 // An imported available_externally definition converts
729 // to external if imported as a declaration.
730 if (!doImportAsDefinition(SGV))
731 return GlobalValue::ExternalLinkage;
732 // An imported available_externally declaration stays that way.
733 return SGV->getLinkage();
734
735 case GlobalValue::LinkOnceAnyLinkage:
736 case GlobalValue::LinkOnceODRLinkage:
737 // These both stay the same when importing the definition.
738 // The ThinLTO pass will eventually force-import their definitions.
739 return SGV->getLinkage();
740
741 case GlobalValue::WeakAnyLinkage:
742 // Can't import weak_any definitions correctly, or we might change the
743 // program semantics, since the linker will pick the first weak_any
744 // definition and importing would change the order they are seen by the
745 // linker. The module linking caller needs to enforce this.
746 assert(!doImportAsDefinition(SGV));
747 // If imported as a declaration, it becomes external_weak.
748 return GlobalValue::ExternalWeakLinkage;
749
750 case GlobalValue::WeakODRLinkage:
751 // For weak_odr linkage, there is a guarantee that all copies will be
752 // equivalent, so the issue described above for weak_any does not exist,
753 // and the definition can be imported. It can be treated similarly
754 // to an imported externally visible global value.
755 if (doImportAsDefinition(SGV))
756 return GlobalValue::AvailableExternallyLinkage;
757 else
758 return GlobalValue::ExternalLinkage;
759
760 case GlobalValue::AppendingLinkage:
761 // It would be incorrect to import an appending linkage variable,
762 // since it would cause global constructors/destructors to be
763 // executed multiple times. This should have already been handled
764 // by linkGlobalValueProto.
765 assert(false && "Cannot import appending linkage variable");
766
767 case GlobalValue::InternalLinkage:
768 case GlobalValue::PrivateLinkage:
769 // If we are promoting the local to global scope, it is handled
770 // similarly to a normal externally visible global.
771 if (doPromoteLocalToGlobal(SGV)) {
772 if (doImportAsDefinition(SGV))
773 return GlobalValue::AvailableExternallyLinkage;
774 else
775 return GlobalValue::ExternalLinkage;
776 }
777 // A non-promoted imported local definition stays local.
778 // The ThinLTO pass will eventually force-import their definitions.
779 return SGV->getLinkage();
780
781 case GlobalValue::ExternalWeakLinkage:
782 // External weak doesn't apply to definitions, must be a declaration.
783 assert(!doImportAsDefinition(SGV));
784 // Linkage stays external_weak.
785 return SGV->getLinkage();
786
787 case GlobalValue::CommonLinkage:
788 // Linkage stays common on definitions.
789 // The ThinLTO pass will eventually force-import their definitions.
790 return SGV->getLinkage();
791 }
792
793 llvm_unreachable("unknown linkage type");
794 }
795
556796 /// Loop through the global variables in the src module and merge them into the
557797 /// dest module.
558 static GlobalVariable *copyGlobalVariableProto(TypeMapTy &TypeMap, Module &DstM,
559 const GlobalVariable *SGVar) {
798 GlobalVariable *
799 ModuleLinker::copyGlobalVariableProto(TypeMapTy &TypeMap,
800 const GlobalVariable *SGVar) {
560801 // No linking to be performed or linking from the source: simply create an
561802 // identical version of the symbol over in the dest module... the
562803 // initializer will be filled in later by LinkGlobalInits.
563804 GlobalVariable *NewDGV = new GlobalVariable(
564 DstM, TypeMap.get(SGVar->getType()->getElementType()),
565 SGVar->isConstant(), SGVar->getLinkage(), /*init*/ nullptr,
566 SGVar->getName(), /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
805 *DstM, TypeMap.get(SGVar->getType()->getElementType()),
806 SGVar->isConstant(), getLinkage(SGVar), /*init*/ nullptr, getName(SGVar),
807 /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
567808 SGVar->getType()->getAddressSpace());
568809
569810 return NewDGV;
571812
572813 /// Link the function in the source module into the destination module if
573814 /// needed, setting up mapping information.
574 static Function *copyFunctionProto(TypeMapTy &TypeMap, Module &DstM,
575 const Function *SF) {
815 Function *ModuleLinker::copyFunctionProto(TypeMapTy &TypeMap,
816 const Function *SF) {
576817 // If there is no linkage to be performed or we are linking from the source,
577818 // bring SF over.
578 return Function::Create(TypeMap.get(SF->getFunctionType()), SF->getLinkage(),
579 SF->getName(), &DstM);
819 return Function::Create(TypeMap.get(SF->getFunctionType()), getLinkage(SF),
820 getName(SF), DstM);
580821 }
581822
582823 /// Set up prototypes for any aliases that come over from the source module.
583 static GlobalAlias *copyGlobalAliasProto(TypeMapTy &TypeMap, Module &DstM,
584 const GlobalAlias *SGA) {
824 GlobalValue *ModuleLinker::copyGlobalAliasProto(TypeMapTy &TypeMap,
825 const GlobalAlias *SGA) {
826 // If we are importing and encounter a weak_any alias, or an alias to
827 // an object being imported as a declaration, we must import the alias
828 // as a declaration as well, which involves converting it to a non-alias.
829 // See comments in ModuleLinker::getLinkage for why we cannot import
830 // weak_any defintions.
831 if (isPerformingImport() && (SGA->hasWeakAnyLinkage() ||
832 !doImportAsDefinition(SGA->getBaseObject()))) {
833 // Need to convert to declaration. All aliases must be definitions.
834 const GlobalValue *GVal = SGA->getBaseObject();
835 GlobalValue *NewGV;
836 if (auto *GVar = dyn_cast(GVal))
837 NewGV = copyGlobalVariableProto(TypeMap, GVar);
838 else {
839 auto *F = dyn_cast(GVal);
840 assert(F);
841 NewGV = copyFunctionProto(TypeMap, F);
842 }
843 // Set the linkage to ExternalWeak, see also comments in
844 // ModuleLinker::getLinkage.
845 if (SGA->hasWeakAnyLinkage())
846 NewGV->setLinkage(GlobalValue::ExternalWeakLinkage);
847 // Don't attempt to link body, needs to be a declaration.
848 DoNotLinkFromSource.insert(SGA);
849 return NewGV;
850 }
585851 // If there is no linkage to be performed or we're linking from the source,
586852 // bring over SGA.
587853 auto *Ty = TypeMap.get(SGA->getValueType());
588854 return GlobalAlias::create(Ty, SGA->getType()->getPointerAddressSpace(),
589 SGA->getLinkage(), SGA->getName(), &DstM);
590 }
591
592 static GlobalValue *copyGlobalValueProto(TypeMapTy &TypeMap, Module &DstM,
593 const GlobalValue *SGV) {
855 getLinkage(SGA), getName(SGA), DstM);
856 }
857
858 void ModuleLinker::setVisibility(GlobalValue *NewGV, const GlobalValue *SGV,
859 const GlobalValue *DGV) {
860 GlobalValue::VisibilityTypes Visibility = SGV->getVisibility();
861 if (DGV)
862 Visibility = isLessConstraining(Visibility, DGV->getVisibility())
863 ? DGV->getVisibility()
864 : Visibility;
865 // For promoted locals, mark them hidden so that they can later be
866 // stripped from the symbol table to reduce bloat.
867 if (SGV->hasLocalLinkage() && doPromoteLocalToGlobal(SGV))
868 Visibility = GlobalValue::HiddenVisibility;
869 NewGV->setVisibility(Visibility);
870 }
871
872 GlobalValue *ModuleLinker::copyGlobalValueProto(TypeMapTy &TypeMap,
873 const GlobalValue *SGV,
874 const GlobalValue *DGV) {
594875 GlobalValue *NewGV;
595876 if (auto *SGVar = dyn_cast(SGV))
596 NewGV = copyGlobalVariableProto(TypeMap, DstM, SGVar);
877 NewGV = copyGlobalVariableProto(TypeMap, SGVar);
597878 else if (auto *SF = dyn_cast(SGV))
598 NewGV = copyFunctionProto(TypeMap, DstM, SF);
879 NewGV = copyFunctionProto(TypeMap, SF);
599880 else
600 NewGV = copyGlobalAliasProto(TypeMap, DstM, cast(SGV));
881 NewGV = copyGlobalAliasProto(TypeMap, cast(SGV));
601882 copyGVAttributes(NewGV, SGV);
883 setVisibility(NewGV, SGV, DGV);
602884 return NewGV;
603885 }
604886
607889 if (!SGV)
608890 return nullptr;
609891
610 GlobalValue *DGV = copyGlobalValueProto(TypeMap, *DstM, SGV);
892 GlobalValue *DGV = ModLinker->copyGlobalValueProto(TypeMap, SGV);
611893
612894 if (Comdat *SC = SGV->getComdat()) {
613895 if (auto *DGO = dyn_cast(DGV)) {
7411023
7421024 // We always have to add Src if it has appending linkage.
7431025 if (Src.hasAppendingLinkage()) {
1026 // Caller should have already determined that we can't link from source
1027 // when importing (see comments in linkGlobalValueProto).
1028 assert(!isPerformingImport());
7441029 LinkFromSrc = true;
7451030 return false;
7461031 }
7471032
7481033 bool SrcIsDeclaration = Src.isDeclarationForLinker();
7491034 bool DestIsDeclaration = Dest.isDeclarationForLinker();
1035
1036 if (isPerformingImport()) {
1037 if (isa(&Src)) {
1038 // For functions, LinkFromSrc iff this is the function requested
1039 // for importing. For variables, decide below normally.
1040 LinkFromSrc = (&Src == ImportFunction);
1041 return false;
1042 }
1043
1044 // Check if this is an alias with an already existing definition
1045 // in Dest, which must have come from a prior importing pass from
1046 // the same Src module. Unlike imported function and variable
1047 // definitions, which are imported as available_externally and are
1048 // not definitions for the linker, that is not a valid linkage for
1049 // imported aliases which must be definitions. Simply use the existing
1050 // Dest copy.
1051 if (isa(&Src) && !DestIsDeclaration) {
1052 assert(isa(&Dest));
1053 LinkFromSrc = false;
1054 return false;
1055 }
1056 }
7501057
7511058 if (SrcIsDeclaration) {
7521059 // If Src is external or if both Src & Dest are external.. Just link the
10391346 GlobalValue *DGV = getLinkedToGlobal(SGV);
10401347
10411348 // Handle the ultra special appending linkage case first.
1349 assert(!DGV || SGV->hasAppendingLinkage() == DGV->hasAppendingLinkage());
1350 if (SGV->hasAppendingLinkage() && isPerformingImport()) {
1351 // Don't want to append to global_ctors list, for example, when we
1352 // are importing for ThinLTO, otherwise the global ctors and dtors
1353 // get executed multiple times for local variables (the latter causing
1354 // double frees).
1355 DoNotLinkFromSource.insert(SGV);
1356 return false;
1357 }
10421358 if (DGV && DGV->hasAppendingLinkage())
10431359 return linkAppendingVarProto(cast(DGV),
10441360 cast(SGV));
10451361
10461362 bool LinkFromSrc = true;
10471363 Comdat *C = nullptr;
1048 GlobalValue::VisibilityTypes Visibility = SGV->getVisibility();
10491364 bool HasUnnamedAddr = SGV->hasUnnamedAddr();
10501365
10511366 if (const Comdat *SC = SGV->getComdat()) {
10691384 ConstantExpr::getBitCast(DGV, TypeMap.get(SGV->getType()));
10701385 }
10711386
1072 if (DGV) {
1073 Visibility = isLessConstraining(Visibility, DGV->getVisibility())
1074 ? DGV->getVisibility()
1075 : Visibility;
1387 if (DGV)
10761388 HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr();
1077 }
10781389
10791390 if (!LinkFromSrc && !DGV)
10801391 return false;
10821393 GlobalValue *NewGV;
10831394 if (!LinkFromSrc) {
10841395 NewGV = DGV;
1396 // When linking from source we setVisibility from copyGlobalValueProto.
1397 setVisibility(NewGV, SGV, DGV);
10851398 } else {
10861399 // If the GV is to be lazily linked, don't create it just yet.
10871400 // The ValueMaterializerTy will deal with creating it if it's used.
1088 if (!DGV && !shouldOverrideFromSrc() &&
1401 if (!DGV && !shouldOverrideFromSrc() && SGV != ImportFunction &&
10891402 (SGV->hasLocalLinkage() || SGV->hasLinkOnceLinkage() ||
10901403 SGV->hasAvailableExternallyLinkage())) {
10911404 DoNotLinkFromSource.insert(SGV);
10991412 return false;
11001413 }
11011414
1102 NewGV = copyGlobalValueProto(TypeMap, *DstM, SGV);
1415 NewGV = copyGlobalValueProto(TypeMap, SGV, DGV);
11031416
11041417 if (DGV && isa(DGV))
11051418 if (auto *NewF = dyn_cast(NewGV))
11071420 }
11081421
11091422 NewGV->setUnnamedAddr(HasUnnamedAddr);
1110 NewGV->setVisibility(Visibility);
11111423
11121424 if (auto *NewGO = dyn_cast(NewGV)) {
11131425 if (C)
16121924 if (DoNotLinkFromSource.count(&SF))
16131925 continue;
16141926
1927 // When importing, only materialize the function requested for import.
1928 if (isPerformingImport() && &SF != ImportFunction)
1929 continue;
1930
16151931 if (linkGlobalValueBody(SF))
16161932 return true;
16171933 }
16451961 while (!LazilyLinkGlobalValues.empty()) {
16461962 GlobalValue *SGV = LazilyLinkGlobalValues.back();
16471963 LazilyLinkGlobalValues.pop_back();
1964 if (isPerformingImport() && !doImportAsDefinition(SGV))
1965 continue;
16481966
16491967 // Skip declarations that ValueMaterializer may have created in
16501968 // case we link in only some of SrcM.
17782096 Composite = nullptr;
17792097 }
17802098
1781 bool Linker::linkInModule(Module *Src, unsigned Flags) {
2099 bool Linker::linkInModule(Module *Src, unsigned Flags, FunctionInfoIndex *Index,
2100 Function *FuncToImport) {
17822101 ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
1783 DiagnosticHandler, Flags);
2102 DiagnosticHandler, Flags, Index, FuncToImport);
17842103 bool RetCode = TheLinker.run();
17852104 Composite->dropTriviallyDeadConstantArrays();
17862105 return RetCode;
None //===- FunctionIndexObjectFile.cpp - Function index file implementation
1 //----===//
0 //===- FunctionIndexObjectFile.cpp - Function index file implementation ---===//
21 //
32 // The LLVM Compiler Infrastructure
43 //
8584 // function summary/index.
8685 ErrorOr>
8786 FunctionIndexObjectFile::create(MemoryBufferRef Object, LLVMContext &Context,
88 bool IsLazy) {
87 const Module *ExportingModule, bool IsLazy) {
8988 std::unique_ptr Index;
9089
9190 ErrorOr BCOrErr = findBitcodeInMemBuffer(Object);
9291 if (!BCOrErr)
9392 return BCOrErr.getError();
9493
95 ErrorOr> IOrErr =
96 getFunctionInfoIndex(BCOrErr.get(), Context, nullptr, IsLazy);
94 ErrorOr> IOrErr = getFunctionInfoIndex(
95 BCOrErr.get(), Context, nullptr, ExportingModule, IsLazy);
9796
9897 if (std::error_code EC = IOrErr.getError())
9998 return EC;
4848 return new EliminateAvailableExternally();
4949 }
5050
51 static void convertAliasToDeclaration(GlobalAlias &GA, Module &M) {
52 GlobalValue *GVal = GA.getBaseObject();
53 GlobalValue *NewGV;
54 if (auto *GVar = dyn_cast(GVal)) {
55 GlobalVariable *NewGVar = new GlobalVariable(
56 M, GVar->getType()->getElementType(), GVar->isConstant(),
57 GVar->getLinkage(), /*init*/ nullptr, GA.getName(), GVar,
58 GVar->getThreadLocalMode(), GVar->getType()->getAddressSpace());
59 NewGV = NewGVar;
60 NewGV->copyAttributesFrom(GVar);
61 } else {
62 auto *F = dyn_cast(GVal);
63 assert(F);
64 Function *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
65 GA.getName(), &M);
66 NewGV = NewF;
67 NewGV->copyAttributesFrom(F);
68 }
69 GA.replaceAllUsesWith(ConstantExpr::getBitCast(NewGV, GA.getType()));
70 GA.eraseFromParent();
71 }
72
5173 bool EliminateAvailableExternally::runOnModule(Module &M) {
5274 bool Changed = false;
75
76 // Convert any aliases that alias with an available externally
77 // value (which will be turned into declarations later on in this routine)
78 // into declarations themselves. All aliases must be definitions, and
79 // must alias with a definition. So this involves creating a declaration
80 // equivalent to the alias's base object.
81 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) {
82 // Increment the iterator first since we may delete the current alias.
83 GlobalAlias &GA = *(I++);
84 GlobalValue *GVal = GA.getBaseObject();
85 if (!GVal->hasAvailableExternallyLinkage())
86 continue;
87 convertAliasToDeclaration(GA, M);
88 Changed = true;
89 }
5390
5491 // Drop initializers of available externally global variables.
5592 for (GlobalVariable &GV : M.globals()) {
64101 GV.removeDeadConstantUsers();
65102 GV.setLinkage(GlobalValue::ExternalLinkage);
66103 NumVariables++;
104 Changed = true;
67105 }
68106
69107 // Drop the bodies of available externally functions.
75113 F.deleteBody();
76114 F.removeDeadConstantUsers();
77115 NumFunctions++;
116 Changed = true;
78117 }
79118
80119 return Changed;
0 define i32 @main() #0 {
1 entry:
2 call void (...) @weakalias()
3 call void (...) @analias()
4 %call = call i32 (...) @referencestatics()
5 %call1 = call i32 (...) @referenceglobals()
6 %call2 = call i32 (...) @referencecommon()
7 call void (...) @setfuncptr()
8 call void (...) @callfuncptr()
9 call void (...) @callweakfunc()
10 ret i32 0
11 }
12
13 declare void @weakalias(...) #1
14
15 declare void @analias(...) #1
16
17 declare i32 @referencestatics(...) #1
18
19 declare i32 @referenceglobals(...) #1
20
21 declare i32 @referencecommon(...) #1
22
23 declare void @setfuncptr(...) #1
24
25 declare void @callfuncptr(...) #1
26
27 declare void @callweakfunc(...) #1
0 ; Do setup work for all below tests: generate bitcode and combined index
1 ; RUN: llvm-as -function-summary %s -o %t.bc
2 ; RUN: llvm-as -function-summary %p/Inputs/funcimport.ll -o %t2.bc
3 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
4
5 ; Ensure statics are promoted/renamed correctly from this file (all but
6 ; constant variable need promotion).
7 ; RUN: llvm-link %t.bc -functionindex=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC
8 ; EXPORTSTATIC: @staticvar.llvm.1 = hidden global
9 ; EXPORTSTATIC: @staticconstvar = internal unnamed_addr constant
10 ; EXPORTSTATIC: @P.llvm.1 = hidden global void ()* null
11 ; EXPORTSTATIC: define hidden i32 @staticfunc.llvm.1
12 ; EXPORTSTATIC: define hidden void @staticfunc2.llvm.1
13
14 ; Ensure that both weak alias to an imported function and strong alias to a
15 ; non-imported function are correctly turned into declarations.
16 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1
17 ; IMPORTGLOB1: define available_externally void @globalfunc1
18 ; IMPORTGLOB1: declare void @globalfunc2
19 ; IMPORTGLOB1: declare extern_weak void @weakalias
20 ; IMPORTGLOB1: declare void @analias
21
22 ; Ensure that weak alias to a non-imported function is correctly
23 ; turned into a declaration, but that strong alias to an imported function
24 ; is imported as alias.
25 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB2
26 ; IMPORTGLOB2: @analias = alias void (...), bitcast (void ()* @globalfunc2
27 ; IMPORTGLOB2: declare void @globalfunc1
28 ; IMPORTGLOB2: define available_externally void @globalfunc2
29 ; IMPORTGLOB2: declare extern_weak void @weakalias
30
31 ; Ensure that strong alias imported in second pass of importing ends up
32 ; as an alias.
33 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB3
34 ; IMPORTGLOB3: @analias = alias void (...), bitcast (void ()* @globalfunc2
35 ; IMPORTGLOB3: define available_externally void @globalfunc1
36 ; IMPORTGLOB3: define available_externally void @globalfunc2
37 ; IMPORTGLOB3: declare extern_weak void @weakalias
38
39 ; Ensure that strong alias imported in first pass of importing ends up
40 ; as an alias, and that seeing the alias definition during a second inlining
41 ; pass is handled correctly.
42 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc2:%t.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB4
43 ; IMPORTGLOB4: @analias = alias void (...), bitcast (void ()* @globalfunc2
44 ; IMPORTGLOB4: define available_externally void @globalfunc2
45 ; IMPORTGLOB4: define available_externally void @globalfunc1
46 ; IMPORTGLOB4: declare extern_weak void @weakalias
47
48 ; Ensure that imported static variable and function references are correctly
49 ; promoted and renamed (including static constant variable).
50 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referencestatics:%t.bc -S | FileCheck %s --check-prefix=IMPORTSTATIC
51 ; IMPORTSTATIC: @staticvar.llvm.1 = available_externally hidden global
52 ; IMPORTSTATIC: @staticconstvar.llvm.1 = internal unnamed_addr constant
53 ; IMPORTSTATIC: define available_externally i32 @referencestatics
54 ; IMPORTSTATIC: %call = call i32 @staticfunc.llvm.1
55 ; IMPORTSTATIC: %0 = load i32, i32* @staticvar.llvm.1
56 ; IMPORTSTATIC: declare hidden i32 @staticfunc.llvm.1
57
58 ; Ensure that imported global (external) function and variable references
59 ; are handled correctly (including referenced variable imported as
60 ; available_externally definition)
61 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referenceglobals:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOBALS
62 ; IMPORTGLOBALS: @globalvar = available_externally global
63 ; IMPORTGLOBALS: declare void @globalfunc1()
64 ; IMPORTGLOBALS: define available_externally i32 @referenceglobals
65
66 ; Ensure that common variable correctly imported as common defition.
67 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=referencecommon:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMMON
68 ; IMPORTCOMMON: @commonvar = common global
69 ; IMPORTCOMMON: define available_externally i32 @referencecommon
70
71 ; Ensure that imported static function pointer correctly promoted and renamed.
72 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=callfuncptr:%t.bc -S | FileCheck %s --check-prefix=IMPORTFUNCPTR
73 ; IMPORTFUNCPTR: @P.llvm.1 = available_externally hidden global void ()* null
74 ; IMPORTFUNCPTR: define available_externally void @callfuncptr
75 ; IMPORTFUNCPTR: %0 = load void ()*, void ()** @P.llvm.1
76
77 ; Ensure that imported weak function reference/definition handled properly.
78 ; Imported weak_any definition should be skipped with warning, and imported
79 ; reference should turned into an external_weak declaration.
80 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=callweakfunc:%t.bc -import=weakfunc:%t.bc -S 2>&1 | FileCheck %s --check-prefix=IMPORTWEAKFUNC
81 ; IMPORTWEAKFUNC: Ignoring import request for weak-any function weakfunc
82 ; IMPORTWEAKFUNC: declare extern_weak void @weakfunc
83 ; IMPORTWEAKFUNC: define available_externally void @callweakfunc
84
85 @globalvar = global i32 1, align 4
86 @staticvar = internal global i32 1, align 4
87 @staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4
88 @commonvar = common global i32 0, align 4
89 @P = internal global void ()* null, align 8
90
91 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
92 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
93
94 define void @globalfunc1() #0 {
95 entry:
96 ret void
97 }
98
99 define void @globalfunc2() #0 {
100 entry:
101 ret void
102 }
103
104 define i32 @referencestatics(i32 %i) #0 {
105 entry:
106 %i.addr = alloca i32, align 4
107 store i32 %i, i32* %i.addr, align 4
108 %call = call i32 @staticfunc()
109 %0 = load i32, i32* @staticvar, align 4
110 %add = add nsw i32 %call, %0
111 %1 = load i32, i32* %i.addr, align 4
112 %idxprom = sext i32 %1 to i64
113 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom
114 %2 = load i32, i32* %arrayidx, align 4
115 %add1 = add nsw i32 %add, %2
116 ret i32 %add1
117 }
118
119 define i32 @referenceglobals(i32 %i) #0 {
120 entry:
121 %i.addr = alloca i32, align 4
122 store i32 %i, i32* %i.addr, align 4
123 call void @globalfunc1()
124 %0 = load i32, i32* @globalvar, align 4
125 ret i32 %0
126 }
127
128 define i32 @referencecommon(i32 %i) #0 {
129 entry:
130 %i.addr = alloca i32, align 4
131 store i32 %i, i32* %i.addr, align 4
132 %0 = load i32, i32* @commonvar, align 4
133 ret i32 %0
134 }
135
136 define void @setfuncptr() #0 {
137 entry:
138 store void ()* @staticfunc2, void ()** @P, align 8
139 ret void
140 }
141
142 define void @callfuncptr() #0 {
143 entry:
144 %0 = load void ()*, void ()** @P, align 8
145 call void %0()
146 ret void
147 }
148
149 define weak void @weakfunc() #0 {
150 entry:
151 ret void
152 }
153
154 define void @callweakfunc() #0 {
155 entry:
156 call void @weakfunc()
157 ret void
158 }
159
160 define internal i32 @staticfunc() #0 {
161 entry:
162 ret i32 1
163 }
164
165 define internal void @staticfunc2() #0 {
166 entry:
167 ret void
168 }
22 Core
33 IRReader
44 Linker
5 Object
56 Support
67 )
78
1818 type = Tool
1919 name = llvm-link
2020 parent = Tools
21 required_libraries = AsmParser BitReader BitWriter IRReader Linker
21 required_libraries = AsmParser BitReader BitWriter IRReader Linker Object
88
99 LEVEL := ../..
1010 TOOLNAME := llvm-link
11 LINK_COMPONENTS := linker bitreader bitwriter asmparser irreader
11 LINK_COMPONENTS := linker bitreader bitwriter asmparser irreader object
1212
1313 # This tool has no plugins, optimize startup time.
1414 TOOL_NO_EXPORTS := 1
1717 #include "llvm/IR/AutoUpgrade.h"
1818 #include "llvm/IR/DiagnosticInfo.h"
1919 #include "llvm/IR/DiagnosticPrinter.h"
20 #include "llvm/IR/FunctionInfo.h"
2021 #include "llvm/IR/LLVMContext.h"
2122 #include "llvm/IR/Module.h"
2223 #include "llvm/IR/Verifier.h"
2324 #include "llvm/IRReader/IRReader.h"
25 #include "llvm/Object/FunctionIndexObjectFile.h"
2426 #include "llvm/Support/CommandLine.h"
2527 #include "llvm/Support/FileSystem.h"
2628 #include "llvm/Support/ManagedStatic.h"
4143 "override", cl::ZeroOrMore, cl::value_desc("filename"),
4244 cl::desc(
4345 "input bitcode file which can override previously defined symbol(s)"));
46
47 // Option to simulate function importing for testing. This enables using
48 // llvm-link to simulate ThinLTO backend processes.
49 static cl::list Imports(
50 "import", cl::ZeroOrMore, cl::value_desc("function:filename"),
51 cl::desc("Pair of function name and filename, where function should be "
52 "imported from bitcode in filename"));
53
54 // Option to support testing of function importing. The function index
55 // must be specified in the case were we request imports via the -import
56 // option, as well as when compiling any module with functions that may be
57 // exported (imported by a different llvm-link -import invocation), to ensure
58 // consistent promotion and renaming of locals.
59 static cl::opt FunctionIndex("functionindex",
60 cl::desc("Function index filename"),
61 cl::init(""),
62 cl::value_desc("filename"));
4463
4564 static cl::opt
4665 OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
117136 errs() << '\n';
118137 }
119138
139 /// Load a function index if requested by the -functionindex option.
140 static ErrorOr>
141 loadIndex(LLVMContext &Context, const Module *ExportingModule = nullptr) {
142 assert(!FunctionIndex.empty());
143 ErrorOr> FileOrErr =
144 MemoryBuffer::getFileOrSTDIN(FunctionIndex);
145 std::error_code EC = FileOrErr.getError();
146 if (EC)
147 return EC;
148 MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef();
149 ErrorOr> ObjOrErr =
150 object::FunctionIndexObjectFile::create(BufferRef, Context,
151 ExportingModule);
152 EC = ObjOrErr.getError();
153 if (EC)
154 return EC;
155
156 object::FunctionIndexObjectFile &Obj = **ObjOrErr;
157 return Obj.takeIndex();
158 }
159
160 /// Import any functions requested via the -import option.
161 static bool importFunctions(const char *argv0, LLVMContext &Context,
162 Linker &L) {
163 for (const auto &Import : Imports) {
164 // Identify the requested function and its bitcode source file.
165 size_t Idx = Import.find(':');
166 if (Idx == std::string::npos) {
167 errs() << "Import parameter bad format: " << Import << "\n";
168 return false;
169 }
170 std::string FunctionName = Import.substr(0, Idx);
171 std::string FileName = Import.substr(Idx + 1, std::string::npos);
172
173 // Load the specified source module.
174 std::unique_ptr M = loadFile(argv0, FileName, Context);
175 if (!M.get()) {
176 errs() << argv0 << ": error loading file '" << FileName << "'\n";
177 return false;
178 }
179
180 if (verifyModule(*M, &errs())) {
181 errs() << argv0 << ": " << FileName
182 << ": error: input module is broken!\n";
183 return false;
184 }
185
186 Function *F = M->getFunction(FunctionName);
187 if (!F) {
188 errs() << "Ignoring import request for non-existent function "
189 << FunctionName << " from " << FileName << "\n";
190 continue;
191 }
192 // We cannot import weak_any functions without possibly affecting the
193 // order they are seen and selected by the linker, changing program
194 // semantics.
195 if (F->hasWeakAnyLinkage()) {
196 errs() << "Ignoring import request for weak-any function " << FunctionName
197 << " from " << FileName << "\n";
198 continue;
199 }
200
201 if (Verbose)
202 errs() << "Importing " << FunctionName << " from " << FileName << "\n";
203
204 std::unique_ptr Index;
205 if (!FunctionIndex.empty()) {
206 ErrorOr> IndexOrErr =
207 loadIndex(Context);
208 std::error_code EC = IndexOrErr.getError();
209 if (EC) {
210 errs() << EC.message() << '\n';
211 return false;
212 }
213 Index = std::move(IndexOrErr.get());
214 }
215
216 // Link in the specified function.
217 if (L.linkInModule(M.get(), false, Index.get(), F))
218 return false;
219 }
220 return true;
221 }
222
120223 static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
121224 const cl::list &Files,
122225 unsigned Flags) {
134237 return false;
135238 }
136239
240 // If a function index is supplied, load it so linkInModule can treat
241 // local functions/variables as exported and promote if necessary.
242 std::unique_ptr Index;
243 if (!FunctionIndex.empty()) {
244 ErrorOr> IndexOrErr =
245 loadIndex(Context, &*M);
246 std::error_code EC = IndexOrErr.getError();
247 if (EC) {
248 errs() << EC.message() << '\n';
249 return false;
250 }
251 Index = std::move(IndexOrErr.get());
252 }
253
137254 if (Verbose)
138255 errs() << "Linking in '" << File << "'\n";
139256
140 if (L.linkInModule(M.get(), ApplicableFlags))
257 if (L.linkInModule(M.get(), ApplicableFlags, Index.get()))
141258 return false;
142259 // All linker flags apply to linking of subsequent files.
143260 ApplicableFlags = Flags;
173290 Flags | Linker::Flags::OverrideFromSrc))
174291 return 1;
175292
293 // Import any functions requested via -import
294 if (!importFunctions(argv[0], Context, L))
295 return 1;
296
176297 if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
177298
178299 std::error_code EC;