diff -ru include/llvm/ExecutionEngine/ExecutionEngine.h.orig include/llvm/ExecutionEngine/ExecutionEngine.h --- include/llvm/ExecutionEngine/ExecutionEngine.h.orig 2010-09-23 09:03:59.000000000 +0300 +++ include/llvm/ExecutionEngine/ExecutionEngine.h 2010-09-23 10:45:11.000000000 +0300 @@ -129,7 +129,9 @@ /// ExceptionTableRegister - If Exception Handling is set, the JIT will /// register dwarf tables with this function typedef void (*EERegisterFn)(void*); - static EERegisterFn ExceptionTableRegister; + EERegisterFn ExceptionTableRegister; + EERegisterFn ExceptionTableDeregister; + std::vector AllExceptionTables; public: /// lock - This lock is protects the ExecutionEngine, JIT, JITResolver and @@ -373,17 +375,26 @@ /// InstallExceptionTableRegister - The JIT will use the given function /// to register the exception tables it generates. - static void InstallExceptionTableRegister(void (*F)(void*)) { + void InstallExceptionTableRegister(EERegisterFn F) { ExceptionTableRegister = F; } + void InstallExceptionTableDeregister(EERegisterFn F) { + ExceptionTableDeregister = F; + } /// RegisterTable - Registers the given pointer as an exception table. It uses /// the ExceptionTableRegister function. - static void RegisterTable(void* res) { - if (ExceptionTableRegister) + void RegisterTable(void* res) { + if (ExceptionTableRegister) { ExceptionTableRegister(res); + AllExceptionTables.push_back(res); + } } + /// DeregisterAllTables - Deregisters all previously registered pointers to an + /// exception tables. It uses the ExceptionTableoDeregister function. + void DeregisterAllTables(); + protected: explicit ExecutionEngine(Module *M); diff -ru lib/ExecutionEngine/ExecutionEngine.cpp.orig lib/ExecutionEngine/ExecutionEngine.cpp --- lib/ExecutionEngine/ExecutionEngine.cpp.orig 2010-09-23 09:05:27.000000000 +0300 +++ lib/ExecutionEngine/ExecutionEngine.cpp 2010-09-23 10:45:26.000000000 +0300 @@ -47,12 +47,12 @@ const SmallVectorImpl& MAttrs) = 0; ExecutionEngine *(*ExecutionEngine::InterpCtor)(Module *M, std::string *ErrorStr) = 0; -ExecutionEngine::EERegisterFn ExecutionEngine::ExceptionTableRegister = 0; - ExecutionEngine::ExecutionEngine(Module *M) : EEState(*this), - LazyFunctionCreator(0) { + LazyFunctionCreator(0), + ExceptionTableRegister(0), + ExceptionTableDeregister(0) { CompilingLazily = false; GVCompilationDisabled = false; SymbolSearchingDisabled = false; @@ -66,6 +66,18 @@ delete Modules[i]; } +void ExecutionEngine::DeregisterAllTables() { + if (ExceptionTableDeregister) { + std::vector::iterator it = AllExceptionTables.begin(); + std::vector::iterator ite = AllExceptionTables.end(); + for (; it != ite; it++) { + void *et = *it; + ExceptionTableDeregister(et); + } + AllExceptionTables.clear(); + } +} + namespace { // This class automatically deletes the memory block when the GlobalVariable is // destroyed. diff -ru lib/ExecutionEngine/JIT/JIT.cpp.orig lib/ExecutionEngine/JIT/JIT.cpp --- lib/ExecutionEngine/JIT/JIT.cpp.orig 2010-09-23 09:05:27.000000000 +0300 +++ lib/ExecutionEngine/JIT/JIT.cpp 2010-09-23 22:09:16.000000000 +0300 @@ -93,6 +93,7 @@ // values of an opaque key, used by libgcc to find dwarf tables. extern "C" void __register_frame(void*); +extern "C" void __deregister_frame(void*); #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= 1050 # define USE_KEYMGR 1 @@ -324,8 +325,10 @@ LOI = (LibgccObjectInfo*)calloc(sizeof(struct LibgccObjectInfo), 1); _keymgr_set_and_unlock_processwide_ptr(KEYMGR_GCC3_DW2_OBJ_LIST, LOI); InstallExceptionTableRegister(DarwinRegisterFrame); + // not sure about how to deregister on Darwin #else InstallExceptionTableRegister(__register_frame); + InstallExceptionTableDeregister(__deregister_frame); #endif // __APPLE__ #endif // __GNUC__ @@ -334,6 +337,9 @@ } JIT::~JIT() { + // unregister all registered by this JIT exception tables + DeregisterAllTables(); + // cleanup AllJits->Remove(this); delete jitstate; delete JCE;