diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 519db782..69601c6c 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -85,13 +85,6 @@ int find_dynamic_unwind_sections(uintptr_t addr, typedef int (*unw_find_dynamic_unwind_sections)( uintptr_t addr, struct unw_dynamic_unwind_sections* info); -void removeFindDynamicUnwindSections() { - if (auto* unw_remove_find_dynamic_unwind_sections = (int (*)( - unw_find_dynamic_unwind_sections find_dynamic_unwind_sections)) - dlsym(RTLD_DEFAULT, "__unw_remove_find_dynamic_unwind_sections")) - unw_remove_find_dynamic_unwind_sections(find_dynamic_unwind_sections); -} - #endif // __APPLE__ namespace Cpp { @@ -109,7 +102,10 @@ namespace Cpp { struct InterpDeleter { ~InterpDeleter() { #ifdef __APPLE__ - removeFindDynamicUnwindSections(); + if (auto* unw_remove_find_dynamic_unwind_sections = (int (*)( + unw_find_dynamic_unwind_sections find_dynamic_unwind_sections)) + dlsym(RTLD_DEFAULT, "__unw_remove_find_dynamic_unwind_sections")) + unw_remove_find_dynamic_unwind_sections(find_dynamic_unwind_sections); #endif sInterpreter.release(); } @@ -2652,6 +2648,14 @@ namespace Cpp { // FIXME: Enable this assert once we figure out how to fix the multiple // calls to CreateInterpreter. //assert(!sInterpreter && "Interpreter already set."); +#ifdef __APPLE__ + // Add a handler to support exceptions from interpreted code. + // See llvm/llvm-project#49036 + if (auto* unw_add_find_dynamic_unwind_sections = (int (*)( + unw_find_dynamic_unwind_sections find_dynamic_unwind_sections)) + dlsym(RTLD_DEFAULT, "__unw_add_find_dynamic_unwind_sections")) + unw_add_find_dynamic_unwind_sections(find_dynamic_unwind_sections); +#endif // __APPLE__ sInterpreter.reset(I); return I; }