Fix a couple issues with the JIT and multiple modules:

1. The "JITState" object creates a PassManager with the ModuleProvider that the
   jit is created with.  If the ModuleProvider is removed and deleted, the
   PassManager is invalid.

2. The Global maps in the JIT were not invalidated with a ModuleProvider was 
   removed.  This could lead to a case where the Module would be freed, and a 
   new Module with Globals at the same addresses could return invalid results.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51384 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nate Begeman
2008-05-21 16:34:48 +00:00
parent a3f334362f
commit f049e07eb8
4 changed files with 82 additions and 10 deletions

View File

@@ -59,6 +59,7 @@ Module* ExecutionEngine::removeModuleProvider(ModuleProvider *P,
ModuleProvider *MP = *I;
if (MP == P) {
Modules.erase(I);
clearGlobalMappingsFromModule(MP->getModule());
return MP->releaseModule(ErrInfo);
}
}
@@ -106,6 +107,22 @@ void ExecutionEngine::clearAllGlobalMappings() {
state.getGlobalAddressReverseMap(locked).clear();
}
/// clearGlobalMappingsFromModule - Clear all global mappings that came from a
/// particular module, because it has been removed from the JIT.
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
MutexGuard locked(lock);
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) {
state.getGlobalAddressMap(locked).erase(FI);
state.getGlobalAddressReverseMap(locked).erase(FI);
}
for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
GI != GE; ++GI) {
state.getGlobalAddressMap(locked).erase(GI);
state.getGlobalAddressReverseMap(locked).erase(GI);
}
}
/// updateGlobalMapping - Replace an existing mapping for GV with a new
/// address. This updates both maps as required. If "Addr" is null, the
/// entry for the global is removed from the mappings.