Index: libunwind/cmake/config-ix.cmake =================================================================== --- libunwind/cmake/config-ix.cmake +++ libunwind/cmake/config-ix.cmake @@ -11,7 +11,11 @@ # --unwindlib=none is supported, and use that if possible. llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) -check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB) +if (HAIKU) + check_library_exists(root fopen "" LIBUNWIND_HAS_ROOT_LIB) +else() + check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB) +endif() if (NOT LIBUNWIND_USE_COMPILER_RT) if (ANDROID) @@ -45,6 +49,9 @@ if (LIBUNWIND_HAS_C_LIB) list(APPEND CMAKE_REQUIRED_LIBRARIES c) endif () + if (LIBUNWIND_HAS_ROOT_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES root) + endif () if (LIBUNWIND_USE_COMPILER_RT) include(HandleCompilerRT) find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY @@ -111,3 +118,7 @@ check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB) check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB) endif() + +if(HAIKU) + check_library_exists(bsd dl_iterate_phdr "" LIBUNWIND_HAS_BSD_LIB) +endif() Index: libunwind/include/__libunwind_config.h =================================================================== --- libunwind/include/__libunwind_config.h +++ libunwind/include/__libunwind_config.h @@ -36,6 +36,9 @@ # if defined(__linux__) # define _LIBUNWIND_TARGET_LINUX 1 # endif +# if defined(__HAIKU__) +# define _LIBUNWIND_TARGET_HAIKU 1 +# endif # if defined(__i386__) # define _LIBUNWIND_TARGET_I386 # define _LIBUNWIND_CONTEXT_SIZE 8 Index: libunwind/src/CMakeLists.txt =================================================================== --- libunwind/src/CMakeLists.txt +++ libunwind/src/CMakeLists.txt @@ -102,6 +102,16 @@ endif () endif () +if (HAIKU) + add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root) + + add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd) + add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1) + + add_compile_flags("-D_DEFAULT_SOURCE") + add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME") +endif () + string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}") string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}") Index: libunwind/src/config.h =================================================================== --- libunwind/src/config.h +++ libunwind/src/config.h @@ -46,6 +46,12 @@ #elif defined(_AIX) // The traceback table at the end of each function is used for unwinding. #define _LIBUNWIND_SUPPORT_TBTAB_UNWIND 1 +#elif defined(__HAIKU__) + #if defined(_LIBUNWIND_USE_HAIKU_BSD_LIB) + #define _LIBUNWIND_USE_DL_ITERATE_PHDR 1 + #endif + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 #else // Assume an ELF system with a dl_iterate_phdr function. #define _LIBUNWIND_USE_DL_ITERATE_PHDR 1 Index: libunwind/test/configs/llvm-libunwind-shared.cfg.in =================================================================== --- libunwind/test/configs/llvm-libunwind-shared.cfg.in +++ libunwind/test/configs/llvm-libunwind-shared.cfg.in @@ -13,6 +13,9 @@ if '@CMAKE_SYSTEM_NAME@' == 'Linux': link_flags.append('-Wl,--export-dynamic') +if '@CMAKE_DL_LIBS@': + link_flags.append('-l@CMAKE_DL_LIBS@') + # Stack unwinding tests need unwinding tables and these are not generated by default on all targets. compile_flags.append('-funwind-tables') @@ -24,7 +27,7 @@ '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags)) )) config.substitutions.append(('%{link_flags}', - '-L %{{lib}} -Wl,-rpath,%{{lib}} -lunwind -ldl {}'.format(' '.join(link_flags)) + '-L %{{lib}} -Wl,-rpath,%{{lib}} -lunwind {}'.format(' '.join(link_flags)) )) config.substitutions.append(('%{exec}', '%{executor} --execdir %T -- '