diff --git a/dmd/dsymbolsem.d b/dmd/dsymbolsem.d
index 50652485a6c..7c8d4100c6a 100644
--- a/dmd/dsymbolsem.d
+++ b/dmd/dsymbolsem.d
@@ -5971,6 +5971,17 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, Expressions*
     {
         tempinst.minst = null;
     }
+    // https://issues.dlang.org/show_bug.cgi?id=21299
+    // If not speculative, this instance should have the same instantiating
+    // root module as its enclosing template symbol. This can differ when
+    // the enclosing template gets changed from non-root to a root instance
+    // in the instantiation graph. When that occurs, this instance also
+    // needs to be appended to the root module, otherwise there will be
+    // undefined references at link-time.
+    if (tempinst.minst && tempinst.tinst)
+    {
+        tempinst.minst = tempinst.tinst.minst;
+    }
 
     tempinst.gagged = (global.gag > 0);
 
diff --git a/runtime/druntime b/runtime/druntime
index 173ad989dac..619795a630a 160000
--- a/runtime/druntime
+++ b/runtime/druntime
@@ -1 +1 @@
-Subproject commit 173ad989dac8fcfc8e73f39528294fa8aaa6a579
+Subproject commit 619795a630ab79dca02d29ecade0907ebc60ad76
diff --git a/tests/d2/dmd-testsuite b/tests/d2/dmd-testsuite
index c33555aa499..de24822e010 160000
--- a/tests/d2/dmd-testsuite
+++ b/tests/d2/dmd-testsuite
@@ -1 +1 @@
-Subproject commit c33555aa499ccb39ac77db01fc0e56355a1a4736
+Subproject commit de24822e010072f4ea6a674d948fe11c2cb5a0d1