Index: libcxx/cmake/caches/zos.cmake =================================================================== --- /dev/null +++ libcxx/cmake/caches/zos.cmake @@ -0,0 +1,3 @@ +set(LIBCXXABI_USE_EXTERNAL_UNWINDER ON CACHE BOOL "") +set(LIBCXXABI_EXTERNAL_UNWIND_SOURCE_DIR "$ENV{LLVM_BASE}/zos-unwind" CACHE PATH "The path to the external unwind source directory.") +set(LIBCXXABI_EXTERNAL_UNWIND_LIB_NAME "libunwind.x" CACHE PATH "The filename of the built library.") Index: libcxx/docs/BuildingLibcxx.rst =================================================================== --- libcxx/docs/BuildingLibcxx.rst +++ libcxx/docs/BuildingLibcxx.rst @@ -358,6 +358,14 @@ Build and use the LLVM unwinder. Note: This option can only be used when libc++abi is the C++ ABI library used. +.. option:: LIBCXXABI_USE_EXTERNAL_UNWINDER:BOOL + + **Default**: ``OFF`` + + Build and use an external unwinder. Note: When ON, the path to the unwinder + source directory should be provided with ``LIBCXXABI_EXTERNAL_UNWIND_SOURCE_DIR``, and the + filename of the built library should be provided with ``LIBCXXABI_EXTERNAL_UNWIND_LIB_NAME``. + The external unwinder is built to the library output directory. libc++ Feature Options ---------------------- Index: libcxxabi/CMakeLists.txt =================================================================== --- libcxxabi/CMakeLists.txt +++ libcxxabi/CMakeLists.txt @@ -46,6 +46,7 @@ option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) +option(LIBCXXABI_USE_EXTERNAL_UNWINDER "Build and use an external unwinder." OFF) option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON) @@ -99,6 +100,9 @@ result in the library being named libc++abi.x.y.dylib, along with the \ usual symlinks pointing to that.") +set(LIBCXXABI_EXTERNAL_UNWIND_SOURCE_DIR "" CACHE PATH "The path to the external unwind source directory.") +set(LIBCXXABI_EXTERNAL_UNWIND_LIB_NAME "" CACHE PATH "The filename of the built library.") + # Default to building a shared library so that the default options still test # the libc++abi that is being built. The problem with testing a static libc++abi # is that libc++ will prefer a dynamic libc++abi from the system over a static Index: libcxxabi/src/CMakeLists.txt =================================================================== --- libcxxabi/src/CMakeLists.txt +++ libcxxabi/src/CMakeLists.txt @@ -151,6 +151,29 @@ message(STATUS "Could not find ParallelSTL, libc++abi will not attempt to use it but the build may fail if the libc++ in use needs it to be available.") endif() +if (LIBCXXABI_USE_EXTERNAL_UNWINDER) + # The unwinder library is built as an external project. + if (LIBCXXABI_USE_LLVM_UNWINDER) + message(WARNING "Use either the external unwinder or LLVM unwinder, but not both.") + endif() + + include_directories("${LIBCXXABI_EXTERNAL_UNWIND_SOURCE_DIR}") + + set(LIBUNWIND_BUILD_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIBCXXABI_EXTERNAL_UNWIND_LIB_NAME}") + + include(ExternalProject) + ExternalProject_Add(external-unwind-project + SOURCE_DIR ${LIBCXXABI_EXTERNAL_UNWIND_SOURCE_DIR} + BUILD_BYPRODUCTS ${LIBUNWIND_BUILD_PATH} + CMAKE_ARGS -DOUTPUT_DIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + INSTALL_COMMAND "" + ) + + add_library(external-unwind STATIC IMPORTED) + set_property(TARGET external-unwind PROPERTY IMPORTED_LOCATION ${LIBUNWIND_BUILD_PATH}) + add_dependencies(external-unwind external-unwind-project) +endif() + # Build the shared library. add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) if (LIBCXXABI_USE_LLVM_UNWINDER) @@ -187,6 +210,18 @@ target_link_libraries(cxxabi_shared PUBLIC cxxabi_shared_objects PRIVATE ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES}) + + if (LIBCXXABI_USE_EXTERNAL_UNWINDER) + add_dependencies(cxxabi_shared external-unwind) + if (ZOS) + target_link_libraries(cxxabi_shared PRIVATE + "-Wl,${LIBUNWIND_BUILD_PATH}") + else() + target_link_libraries(cxxabi_shared PRIVATE + "${LIBUNWIND_BUILD_PATH}") + endif() + endif() + if (TARGET pstl::ParallelSTL) target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL) endif() @@ -264,6 +299,18 @@ if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) target_link_libraries(cxxabi_static PUBLIC unwind_static) endif() + + if (LIBCXXABI_USE_EXTERNAL_UNWINDER) + add_dependencies(cxxabi_static external-unwind) + if (ZOS) + target_link_libraries(cxxabi_static PRIVATE + "-Wl,${LIBUNWIND_BUILD_PATH}") + else() + target_link_libraries(cxxabi_static PRIVATE + "${LIBUNWIND_BUILD_PATH}") + endif() + endif() + set_target_properties(cxxabi_static PROPERTIES LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"