// Vector of GlobalValues to lazily link in.
std::vector<GlobalValue *> LazilyLinkGlobalValues;
- /// Functions that have replaced other functions.
- SmallPtrSet<const Function *, 16> OverridingFunctions;
-
DiagnosticHandlerFunction DiagnosticHandler;
/// For symbol clashes, prefer those from Src.
const GlobalValue *DGV = nullptr);
void linkNamedMDNodes();
- void stripReplacedSubprograms();
};
}
assert(F);
NewGV = copyFunctionProto(TypeMap, F);
}
- // Set the linkage to ExternalWeak, see also comments in
- // ModuleLinker::getLinkage.
+ // Set the linkage to External or ExternalWeak (see comments in
+ // ModuleLinker::getLinkage for why WeakAny is converted to ExternalWeak).
if (SGA->hasWeakAnyLinkage())
NewGV->setLinkage(GlobalValue::ExternalWeakLinkage);
+ else
+ NewGV->setLinkage(GlobalValue::ExternalLinkage);
// Don't attempt to link body, needs to be a declaration.
DoNotLinkFromSource.insert(SGA);
return NewGV;
}
NewGV = copyGlobalValueProto(TypeMap, SGV, DGV);
-
- if (DGV && isa<Function>(DGV))
- if (auto *NewF = dyn_cast<Function>(NewGV))
- OverridingFunctions.insert(NewF);
}
NewGV->setUnnamedAddr(HasUnnamedAddr);
}
}
-/// Drop DISubprograms that have been superseded.
-///
-/// FIXME: this creates an asymmetric result: we strip functions from losing
-/// subprograms in DstM, but leave losing subprograms in SrcM.
-/// TODO: Remove this logic once the backend can correctly determine canonical
-/// subprograms.
-void ModuleLinker::stripReplacedSubprograms() {
- // Avoid quadratic runtime by returning early when there's nothing to do.
- if (OverridingFunctions.empty())
- return;
-
- // Move the functions now, so the set gets cleared even on early returns.
- auto Functions = std::move(OverridingFunctions);
- OverridingFunctions.clear();
-
- // Drop functions from subprograms if they've been overridden by the new
- // compile unit.
- NamedMDNode *CompileUnits = DstM->getNamedMetadata("llvm.dbg.cu");
- if (!CompileUnits)
- return;
- for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
- auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I));
- assert(CU && "Expected valid compile unit");
-
- for (DISubprogram *SP : CU->getSubprograms()) {
- if (!SP || !SP->getFunction() || !Functions.count(SP->getFunction()))
- continue;
-
- // Prevent DebugInfoFinder from tagging this as the canonical subprogram,
- // since the canonical one is in the incoming module.
- SP->replaceFunction(nullptr);
- }
- }
-}
-
/// Merge the linker flags in Src into the Dest module.
bool ModuleLinker::linkModuleFlagsMetadata() {
// If the source module has no module flags, we are done.
MapValue(GV, ValueMap, RF_MoveDistinctMDs, &TypeMap, &ValMaterializer);
}
- // Strip replaced subprograms before mapping any metadata -- so that we're
- // not changing metadata from the source module (note that
- // linkGlobalValueBody() eventually calls RemapInstruction() and therefore
- // MapMetadata()) -- but after linking global value protocols -- so that
- // OverridingFunctions has been built.
- stripReplacedSubprograms();
-
// Link in the function bodies that are defined in the source module into
// DstM.
for (Function &SF : *SrcM) {
linkGlobalValueBody(Src);
}
- // Remap all of the named MDNodes in Src into the DstM module. We do this
- // after linking GlobalValues so that MDNodes that reference GlobalValues
- // are properly remapped.
- linkNamedMDNodes();
-
- // Merge the module flags into the DstM module.
- if (linkModuleFlagsMetadata())
- return true;
-
// Update the initializers in the DstM module now that all globals that may
// be referenced are in DstM.
for (GlobalVariable &Src : SrcM->globals()) {
return true;
}
+ // Remap all of the named MDNodes in Src into the DstM module. We do this
+ // after linking GlobalValues so that MDNodes that reference GlobalValues
+ // are properly remapped.
+ linkNamedMDNodes();
+
+ // Merge the module flags into the DstM module.
+ if (linkModuleFlagsMetadata())
+ return true;
+
return false;
}