https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/84509
>From c7aa9678d9d9df752490c635810428ae37766fd3 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan <yifan...@rochester.edu> Date: Fri, 8 Mar 2024 11:14:39 -0500 Subject: [PATCH] [libc][libunwind] support build libunwind with libc --- libunwind/CMakeLists.txt | 13 ++++++++++++- libunwind/src/CMakeLists.txt | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index b22ade0a7d71e..386c69e4728ee 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -47,6 +47,7 @@ option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX register option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON) option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF) option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) +option(LIBUNWIND_USE_LLVM_LIBC "Build libunwind with LLVM's libc headers" OFF) option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS}) option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS}) option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF) @@ -65,6 +66,10 @@ cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY "Install the shared libunwind library." ON "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF) +if (LIBUNWIND_USE_LLVM_LIBC AND LIBUNWIND_ENABLE_SHARED) + message(FATAL_ERROR "Cannot build libunwind as a shared library with LLVM's libc headers.") +endif() + if(MINGW) set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in") elseif (LIBUNWIND_ENABLE_SHARED) @@ -175,6 +180,11 @@ if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt") endif() +if (LIBUNWIND_USE_LLVM_LIBC) + include_directories(SYSTEM ${LIBUNWIND_BINARY_DIR}/../libc/include/) + add_compile_flags_if_supported(-ffreestanding) +endif() + add_compile_flags_if_supported(-Werror=return-type) if (LIBUNWIND_ENABLE_CET) @@ -286,7 +296,8 @@ if (LIBUNWIND_ENABLE_ARM_WMMX) add_compile_flags(-D__ARM_WMMX) endif() -if(LIBUNWIND_IS_BAREMETAL) +# for now, libc does not have dlsym; enable baremetal mode to avoid using dlsym +if(LIBUNWIND_IS_BAREMETAL OR LIBUNWIND_USE_LLVM_LIBC) add_compile_definitions(_LIBUNWIND_IS_BAREMETAL) endif() diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index 780430ba70ba6..fbec7d4b5296b 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -182,6 +182,9 @@ endif() # Build the static library. add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) +if (LIBUNWIND_USE_LLVM_LIBC) + add_dependencies(unwind_static_objects libc-headers) +endif() cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC}) if(CMAKE_C_COMPILER_ID STREQUAL MSVC) target_compile_options(unwind_static_objects PRIVATE /GR-) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits