summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 74ca197ddb3..010c5611949 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -440,6 +440,11 @@ class ModuleLinker {
/// as part of a different backend compilation process.
bool HasExportedFunctions;
+ /// Set to true when all global value body linking is complete (including
+ /// lazy linking). Used to prevent metadata linking from creating new
+ /// references.
+ bool DoneLinkingBodies;
+
public:
ModuleLinker(Module *dstM, Linker::IdentifiedStructTypeSet &Set, Module *srcM,
DiagnosticHandlerFunction DiagnosticHandler, unsigned Flags,
@@ -448,7 +453,8 @@ public:
: DstM(dstM), SrcM(srcM), TypeMap(Set),
ValMaterializer(TypeMap, DstM, LazilyLinkGlobalValues, this),
DiagnosticHandler(DiagnosticHandler), Flags(Flags), ImportIndex(Index),
- ImportFunction(FuncToImport), HasExportedFunctions(false) {
+ ImportFunction(FuncToImport), HasExportedFunctions(false),
+ DoneLinkingBodies(false) {
assert((ImportIndex || !ImportFunction) &&
"Expect a FunctionInfoIndex when importing");
// If we have a FunctionInfoIndex but no function to import,
@@ -475,6 +481,9 @@ public:
/// Check if we should promote the given local value to global scope.
bool doPromoteLocalToGlobal(const GlobalValue *SGV);
+ /// Check if all global value body linking is complete.
+ bool doneLinkingBodies() { return DoneLinkingBodies; }
+
private:
bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest,
const GlobalValue &Src);
@@ -888,6 +897,12 @@ Value *ValueMaterializerTy::materializeValueFor(Value *V) {
if (!SGV)
return nullptr;
+ // If we are done linking global value bodies (i.e. we are performing
+ // metadata linking), don't link in the global value due to this
+ // reference, simply map it to null.
+ if (ModLinker->doneLinkingBodies())
+ return nullptr;
+
GlobalValue *DGV = ModLinker->copyGlobalValueProto(TypeMap, SGV);
if (Comdat *SC = SGV->getComdat()) {
@@ -1918,6 +1933,10 @@ bool ModuleLinker::run() {
return true;
}
+ // Note that we are done linking global value bodies. This prevents
+ // metadata linking from creating new references.
+ DoneLinkingBodies = 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.
OpenPOWER on IntegriCloud