diff --git a/libcxx/cmake/Modules/HandleExceptionLibrary.cmake b/libcxx/cmake/Modules/HandleExceptionLibrary.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/Modules/HandleExceptionLibrary.cmake @@ -0,0 +1,39 @@ +#=============================================================================== +# Define targets for linking against the selected ABI library +# +# After including this file, the following targets are defined: +# - cxx_exception: A target representing the shared c++_exception library. +# constituting the split from c++ shared library. +# The LIBCXX_EXCEPTION_ZOS_BUILD, which can be defined in +# cache, determines if the library will be built or not. +#=============================================================================== + + +if (LIBCXX_EXCEPTION_ZOS_BUILD) + add_library(cxx_exception SHARED ${exclude_from_all} ${LIBCXX_EXCEPTION_SOURCES} ${LIBCXX_HEADERS}) + target_link_libraries(cxx_exception PUBLIC cxx-headers + PRIVATE ${LIBCXX_LIBRARIES}) + set_target_properties(cxx_exception + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS} -D_LIBCPP_BUILD_EXCEPTION_STANDALONE" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++_exception" + VERSION "${LIBCXX_ABI_VERSION}.0" + SOVERSION "${LIBCXX_ABI_VERSION}" + DEFINE_SYMBOL "" + POSITION_INDEPENDENT_CODE ON + ) + cxx_add_common_build_flags(cxx_exception) + cxx_set_common_defines(cxx_exception) + + add_custom_command(TARGET cxx_exception POST_BUILD + COMMAND + ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh + $ $ "${LIBCXX_EXCEPTION_DLL_NAME}" + COMMENT "Rename dll name inside the side deck file" + WORKING_DIRECTORY $ + ) + + target_link_libraries(cxx_exception PUBLIC libcxx-abi-shared) + list(APPEND LIBCXX_BUILD_TARGETS "cxx_exception") +endif() diff --git a/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake b/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake --- a/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake +++ b/libcxx/cmake/caches/s390x-ibm-zos-ascii.cmake @@ -16,6 +16,8 @@ set(LIBCXX_DLL_NAME CRTEQCXS CACHE STRING "") set(LIBCXX_SHARED_OUTPUT_NAME "c++_a" CACHE STRING "Output name for the shared libc++ runtime library.") +set(LIBCXX_EXCEPTION_ZOS_BUILD OFF CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") set(LIBCXX_CXX_ABI system-libcxxabi CACHE STRING "") set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "-fzos-le-char-mode=ascii" CACHE STRING "") diff --git a/libcxx/cmake/caches/s390x-ibm-zos.cmake b/libcxx/cmake/caches/s390x-ibm-zos.cmake --- a/libcxx/cmake/caches/s390x-ibm-zos.cmake +++ b/libcxx/cmake/caches/s390x-ibm-zos.cmake @@ -12,6 +12,9 @@ # Target Specific set(LIBCXX_DLL_NAME CRTEQCXE CACHE STRING "") +set(LIBCXX_EXCEPTION_DLL_NAME CRTEQCXP CACHE STRING "") +set(LIBCXX_EXCEPTION_ZOS_BUILD ON CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") set(LIBCXXABI_DLL_NAME CRTEQCXA CACHE STRING "") set(LIBCXXABI_ADDITIONAL_LIBRARIES "-Wl,lib/libunwind.x" CACHE STRING "") diff --git a/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake b/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake --- a/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake +++ b/libcxx/cmake/caches/s390x32-ibm-zos-ascii.cmake @@ -16,6 +16,8 @@ set(LIBCXX_DLL_NAME CRTEHCXS CACHE STRING "") set(LIBCXX_SHARED_OUTPUT_NAME "c++_a" CACHE STRING "Output name for the shared libc++ runtime library.") +set(LIBCXX_EXCEPTION_ZOS_BUILD OFF CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") set(LIBCXX_CXX_ABI system-libcxxabi CACHE STRING "") set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "-fzos-le-char-mode=ascii" CACHE STRING "") diff --git a/libcxx/cmake/caches/s390x32-ibm-zos.cmake b/libcxx/cmake/caches/s390x32-ibm-zos.cmake --- a/libcxx/cmake/caches/s390x32-ibm-zos.cmake +++ b/libcxx/cmake/caches/s390x32-ibm-zos.cmake @@ -12,6 +12,9 @@ # Target Specific set(LIBCXX_DLL_NAME CRTEHCXE CACHE STRING "") +set(LIBCXX_EXCEPTION_DLL_NAME CRTEHCXP CACHE STRING "") +set(LIBCXX_EXCEPTION_ZOS_BUILD ON CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") set(LIBCXXABI_DLL_NAME CRTEHCXA CACHE STRING "") diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -637,6 +637,13 @@ # define _VSTD std _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD +#if defined(__MVS__) +#define _LIBCPP_BEGIN_NAMESPACE_EXCEPTION namespace std { +#define _LIBCPP_END_NAMESPACE_EXCEPTION } +#else +#define _LIBCPP_BEGIN_NAMESPACE_EXCEPTION _LIBCPP_BEGIN_NAMESPACE_STD +#define _LIBCPP_END_NAMESPACE_EXCEPTION _LIBCPP_END_NAMESPACE_STD +#endif # if _LIBCPP_STD_VER > 14 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -47,6 +47,20 @@ # pragma GCC system_header #endif +_LIBCPP_BEGIN_NAMESPACE_EXCEPTION + +class _LIBCPP_EXCEPTION_ABI bad_weak_ptr + : public std::exception +{ +public: + bad_weak_ptr() _NOEXCEPT = default; + bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; + virtual ~bad_weak_ptr() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +_LIBCPP_END_NAMESPACE_EXCEPTION + _LIBCPP_BEGIN_NAMESPACE_STD template @@ -125,16 +139,6 @@ #endif } -class _LIBCPP_EXCEPTION_ABI bad_weak_ptr - : public std::exception -{ -public: - bad_weak_ptr() _NOEXCEPT = default; - bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; - ~bad_weak_ptr() _NOEXCEPT override; - const char* what() const _NOEXCEPT override; -}; - _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY void __throw_bad_weak_ptr() { diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -59,7 +59,6 @@ typeinfo.cpp utility.cpp valarray.cpp - variant.cpp vector.cpp verbose_abort.cpp ) @@ -132,6 +131,17 @@ endif() endif() +set(LIBCXX_EXCEPTION_SOURCES + exceptions/memory.cpp + exceptions/any.cpp + exceptions/optional.cpp + exceptions/variant.cpp + ) + +if (NOT ZOS) + list(APPEND LIBCXX_SOURCES ${LIBCXX_EXCEPTION_SOURCES}) +endif() + # Add all the headers to the project for IDEs. if (LIBCXX_CONFIGURE_IDE) file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) @@ -286,6 +296,8 @@ endif() endif() +include(HandleExceptionLibrary) + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # Build the static library. diff --git a/libcxx/src/any.cpp b/libcxx/src/any.cpp --- a/libcxx/src/any.cpp +++ b/libcxx/src/any.cpp @@ -8,13 +8,6 @@ #include -namespace std { -const char* bad_any_cast::what() const noexcept { - return "bad any cast"; -} -} - - #include // Preserve std::experimental::any_bad_cast for ABI compatibility diff --git a/libcxx/src/exceptions/any.cpp b/libcxx/src/exceptions/any.cpp new file mode 100644 --- /dev/null +++ b/libcxx/src/exceptions/any.cpp @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +//// +//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +//// See https://llvm.org/LICENSE.txt for license information. +//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//// +////===----------------------------------------------------------------------===// + +#include "any" + +namespace std { +const char* bad_any_cast::what() const noexcept { return "bad any cast"; } +} diff --git a/libcxx/src/exceptions/memory.cpp b/libcxx/src/exceptions/memory.cpp new file mode 100644 --- /dev/null +++ b/libcxx/src/exceptions/memory.cpp @@ -0,0 +1,19 @@ + +//===----------------------------------------------------------------------===// +//// +//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +//// See https://llvm.org/LICENSE.txt for license information. +//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//// +////===----------------------------------------------------------------------===// +// + +#include "memory" + +_LIBCPP_BEGIN_NAMESPACE_EXCEPTION + +bad_weak_ptr::~bad_weak_ptr() noexcept {} + +const char* bad_weak_ptr::what() const noexcept { return "bad_weak_ptr"; } + +_LIBCPP_END_NAMESPACE_EXCEPTION diff --git a/libcxx/src/exceptions/optional.cpp b/libcxx/src/exceptions/optional.cpp new file mode 100644 --- /dev/null +++ b/libcxx/src/exceptions/optional.cpp @@ -0,0 +1,19 @@ + +//===----------------------------------------------------------------------===// +//// +//// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +//// See https://llvm.org/LICENSE.txt for license information. +//// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//// +////===----------------------------------------------------------------------===// + +#include "optional" + +namespace std +{ + +bad_optional_access::~bad_optional_access() noexcept = default; + +const char* bad_optional_access::what() const noexcept { return "bad_optional_access"; } + +} // std diff --git a/libcxx/src/variant.cpp b/libcxx/src/exceptions/variant.cpp rename from libcxx/src/variant.cpp rename to libcxx/src/exceptions/variant.cpp diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -27,14 +27,6 @@ const allocator_arg_t allocator_arg = allocator_arg_t(); -bad_weak_ptr::~bad_weak_ptr() noexcept {} - -const char* -bad_weak_ptr::what() const noexcept -{ - return "bad_weak_ptr"; -} - __shared_count::~__shared_count() { } diff --git a/libcxx/src/optional.cpp b/libcxx/src/optional.cpp --- a/libcxx/src/optional.cpp +++ b/libcxx/src/optional.cpp @@ -9,18 +9,6 @@ #include <__availability> #include -namespace std -{ - -bad_optional_access::~bad_optional_access() noexcept = default; - -const char* bad_optional_access::what() const noexcept { - return "bad_optional_access"; -} - -} // std - - #include // Preserve std::experimental::bad_optional_access for ABI compatibility