Author: Trung Nguyen
Date: 2023-09-06T00:56:09-04:00
New Revision: 976dbae2463804869004daef5a7effc72268204f

URL: 
https://github.com/llvm/llvm-project/commit/976dbae2463804869004daef5a7effc72268204f
DIFF: 
https://github.com/llvm/llvm-project/commit/976dbae2463804869004daef5a7effc72268204f.diff

LOG: [libunwind] Haiku: Initial support

Adds build support for Haiku.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D157866

Added: 
    

Modified: 
    libunwind/cmake/config-ix.cmake
    libunwind/include/__libunwind_config.h
    libunwind/src/CMakeLists.txt
    libunwind/src/config.h
    libunwind/test/configs/llvm-libunwind-merged.cfg.in
    libunwind/test/configs/llvm-libunwind-shared.cfg.in
    libunwind/test/configs/llvm-libunwind-static.cfg.in

Removed: 
    


################################################################################
diff  --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index d311477f02c690a..7df8974b0a92540 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -11,7 +11,11 @@ include(CheckCSourceCompiles)
 # --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 (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   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 @@ else()
   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()

diff  --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index a317a36677d3c0f..2444e7286b637f1 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/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

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index bb2ada94d939d4c..a9bf29a8b394a4c 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -102,6 +102,16 @@ if (APPLE)
   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}")

diff  --git a/libunwind/src/config.h b/libunwind/src/config.h
index ef6b8d67181b4e1..35262e5ce26b86a 100644
--- a/libunwind/src/config.h
+++ b/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

diff  --git a/libunwind/test/configs/llvm-libunwind-merged.cfg.in 
b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
index 218126073d401c3..10650f7edf66a2f 100644
--- a/libunwind/test/configs/llvm-libunwind-merged.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -14,6 +14,9 @@ if @LIBUNWIND_ENABLE_CET@:
 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')
 
@@ -25,7 +28,7 @@ config.substitutions.append(('%{compile_flags}',
     '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '-L %{{lib}} -Wl,-rpath,%{{lib}} -lc++ -ldl {}'.format(' 
'.join(link_flags))
+    '-L %{{lib}} -Wl,-rpath,%{{lib}} -lc++ {}'.format(' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}',
     '%{executor} --execdir %T -- '

diff  --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in 
b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index c779df906bf42ba..97185e57234ff7f 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -13,6 +13,9 @@ if @LIBUNWIND_ENABLE_CET@:
 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 @@ config.substitutions.append(('%{compile_flags}',
     '-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 -- '

diff  --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in 
b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index 739efd22b23e74f..fc6a18d057f3884 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -16,6 +16,9 @@ if @LIBUNWIND_ENABLE_CET@:
 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')
 
@@ -27,7 +30,7 @@ config.substitutions.append(('%{compile_flags}',
     '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '%{{lib}}/libunwind.a -ldl {}'.format(' '.join(link_flags))
+    '%{{lib}}/libunwind.a {}'.format(' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}',
     '%{executor} --execdir %T -- '


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to