Index: lib/ExecutionEngine/MCJIT/MCJIT.h =================================================================== --- lib/ExecutionEngine/MCJIT/MCJIT.h +++ lib/ExecutionEngine/MCJIT/MCJIT.h @@ -121,6 +121,10 @@ (FinalizedModules.count(M) != 0); } + bool allModulesAreFinalized() { + return (AddedModules.size() == 0) && (LoadedModules.size() == 0); + } + void markModuleAsLoaded(Module *M) { // This checks against logic errors in the MCJIT implementation. // This function should never be called with either a Module that MCJIT Index: lib/ExecutionEngine/MCJIT/MCJIT.cpp =================================================================== --- lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -231,6 +231,9 @@ void MCJIT::finalizeLoadedModules() { MutexGuard locked(lock); + if (OwnedModules.allModulesAreFinalized()) + return; + // Resolve any outstanding relocations. Dyld.resolveRelocations();