[caches] Restored the topological order of libraries' initializers

This commit is contained in:
Igor Chevdar
2020-08-04 18:48:35 +05:00
parent 7fc66d316d
commit 21e780101a
2 changed files with 10 additions and 3 deletions
@@ -437,7 +437,14 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
val allNonCachedDependencies = context.librariesWithDependencies.filter {
context.config.cachedLibraries.getLibraryCache(it) == null
}
(allNonCachedDependencies + allCachedBitcodeDependencies).distinct()
val set = (allNonCachedDependencies + allCachedBitcodeDependencies).toSet()
// This list is used in particular to build the libraries' initializers chain.
// The initializers must be called in the topological order, so make sure that the
// libraries list being returned is also toposorted.
context.config.resolvedLibraries
.getFullList(TopologicalLibraryOrder)
.cast<List<KonanLibrary>>()
.filter { it in set }
}
val bitcodeToLink: List<KonanLibrary> by lazy {
@@ -2369,8 +2369,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
//-------------------------------------------------------------------------//
fun appendStaticInitializers() {
// Null for "current" non-library module:
val libraries = (context.llvm.allBitcodeDependencies + listOf(null))
// Note: the list of libraries is topologically sorted (in order for initializers to be called correctly).
val libraries = (context.llvm.allBitcodeDependencies + listOf(null)/* Null for "current" non-library module */)
val libraryToInitializers = libraries.associateWith {
mutableListOf<LLVMValueRef>()