Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -47,6 +47,7 @@ option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON) option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS}) +option(LIBUNWIND_ENABLE_DYNAMIC_LINKER "Query the dynamic linker for finding exception frames." ON) set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)") @@ -226,6 +227,11 @@ list(APPEND LIBUNWIND_COMPILE_FLAGS -D__ARM_WMMX) endif() +# Ability to disable the use of the dynamic linker +if (NOT LIBUNWIND_ENABLE_DYNAMIC_LINKER) + list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_DISABLE_DYNAMIC_LINKER) +endif() + # This is the _ONLY_ place where add_definitions is called. if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) Index: src/AddressSpace.hpp =================================================================== --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -377,19 +377,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, UnwindInfoSections &info) { -#ifdef __APPLE__ - dyld_unwind_sections dyldInfo; - if (_dyld_find_unwind_sections((void *)targetAddr, &dyldInfo)) { - info.dso_base = (uintptr_t)dyldInfo.mh; - #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) - info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section; - info.dwarf_section_length = dyldInfo.dwarf_section_length; - #endif - info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section; - info.compact_unwind_section_length = dyldInfo.compact_unwind_section_length; - return true; - } -#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL) +#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL) // Bare metal is statically linked, so no need to ask the dynamic loader info.dwarf_section_length = (uintptr_t)(&__eh_frame_end - &__eh_frame_start); info.dwarf_section = (uintptr_t)(&__eh_frame_start); @@ -411,6 +399,19 @@ (void *)info.arm_section, (void *)info.arm_section_length); if (info.arm_section && info.arm_section_length) return true; +#elif !defined(_LIBUNWIND_DISABLE_DYNAMIC_LINKER) +#ifdef __APPLE__ + dyld_unwind_sections dyldInfo; + if (_dyld_find_unwind_sections((void *)targetAddr, &dyldInfo)) { + info.dso_base = (uintptr_t)dyldInfo.mh; + #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) + info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section; + info.dwarf_section_length = dyldInfo.dwarf_section_length; + #endif + info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section; + info.compact_unwind_section_length = dyldInfo.compact_unwind_section_length; + return true; + } #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) HMODULE mods[1024]; HANDLE process = GetCurrentProcess(); @@ -557,6 +558,7 @@ &cb_data); return static_cast(found); #endif +#endif // !_LIBUNWIND_DISABLE_DYNAMIC_LINKER return false; }