summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2015-11-06 17:50:53 +0000
committerTeresa Johnson <tejohnson@google.com>2015-11-06 17:50:53 +0000
commit1063293a892f8c2d5c089be25c175b25fccf2ea5 (patch)
tree831de3b721e6aaad9837079f3c4a296f0df4b29e /llvm/lib/Linker/LinkModules.cpp
parent189b2526527c02b9ef4234266b51807308d4662a (diff)
downloadbcm5719-llvm-1063293a892f8c2d5c089be25c175b25fccf2ea5.tar.gz
bcm5719-llvm-1063293a892f8c2d5c089be25c175b25fccf2ea5.zip
Restore "Move metadata linking after lazy global materialization/linking."
Summary: This reverts commit r251965. Restore "Move metadata linking after lazy global materialization/linking." This restores commit r251926, with fixes for the LTO bootstrapping bot failure. The bot failure was caused by references from debug metadata to otherwise unreferenced globals. Previously, this caused the lazy linking to link in their defs, which is unnecessary. With this patch, because lazy linking is complete when we encounter the metadata reference, the materializer created a declaration. For definitions such as aliases and comdats, it is illegal to have a declaration. Furthermore, metadata linking should not change code generation. Therefore, when linking of global value bodies is complete, the materializer will simply return nullptr as the new reference for the linked metadata. This change required fixing a different test to ensure there was a real reference to a linkonce global that was only being reference from metadata. Note that the new changes to the only-needed-named-metadata.ll test illustrate an issue with llvm-link -only-needed handling of comdat groups, whereby it may result in an incomplete comdat group. I note this in the test comments, but the issue is orthogonal to this patch (it can be reproduced without any metadata at head). Reviewers: dexonsmith, rafael, tra Subscribers: tobiasvk, joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D14447 llvm-svn: 252320
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