- if (L.linkInModule(*M, Linker::Flags::None, Index.get(), F))
+ DenseSet<const GlobalValue *> FunctionsToImport;
+ FunctionsToImport.insert(F);
+ if (L.linkInModule(std::move(M), Linker::Flags::None, Index.get(),
+ &FunctionsToImport, TempMDVals.get()))
+ return false;
+ }
+
+ // Now link in metadata for all modules from which we imported functions.
+ for (StringMapEntry<std::unique_ptr<DenseMap<unsigned, MDNode *>>> &SME :
+ ModuleToTempMDValsMap) {
+ // Load the specified source module.
+ std::unique_ptr<Module> M = loadFile(argv0, SME.getKey(), Context, true);
+ if (!M.get()) {
+ errs() << argv0 << ": error loading file '" << SME.getKey() << "'\n";
+ return false;
+ }
+
+ if (verifyModule(*M, &errs())) {
+ errs() << argv0 << ": " << SME.getKey()
+ << ": error: input module is broken!\n";
+ return false;
+ }
+
+ // Link in all necessary metadata from this module.
+ if (L.linkInMetadata(*M, SME.getValue().get()))