diff --git a/libcxx/cmake/caches/zos.cmake b/libcxx/cmake/caches/zos.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/zos.cmake @@ -0,0 +1,17 @@ +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_INCLUDE_TESTS ON CACHE BOOL "") +set(LIBCXX_STANDALONE_BUILD ON CACHE BOOL "") +set(LIBCXX_EXCEPTION_ZOS_BUILD ON CACHE BOOL + "Build libcxx exception library on z/OS as standalone.") +set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_INCLUDE_TESTS ON CACHE BOOL "") + +set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "") +set(LLVM_ENABLE_WERROR ON CACHE BOOL "") + diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -824,6 +824,14 @@ #define _VSTD std::_LIBCPP_ABI_NAMESPACE _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD +#if defined(__MVS__) +#define _LIBCPP_BEGIN_NAMESPACE_STD_EXCEPTION namespace std { +#define _LIBCPP_END_NAMESPACE_STD_EXCEPTION } +#else +#define _LIBCPP_BEGIN_NAMESPACE_STD_EXCEPTION _LIBCPP_BEGIN_NAMESPACE_STD +#define _LIBCPP_END_NAMESPACE_STD_EXCEPTION _LIBCPP_END_NAMESPACE_STD +#endif + #if _LIBCPP_STD_VER >= 17 #define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { 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 @@ -43,6 +43,20 @@ #pragma GCC system_header #endif +_LIBCPP_BEGIN_NAMESPACE_STD_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_STD_EXCEPTION + _LIBCPP_BEGIN_NAMESPACE_STD template @@ -121,16 +135,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; - virtual ~bad_weak_ptr() _NOEXCEPT; - virtual const char* what() const _NOEXCEPT; -}; - _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 ) @@ -136,6 +135,17 @@ endif() endif() +set(LIBCXX_EXCEPTION_SOURCES + exceptions/memory.cpp + exceptions/any.cpp + exceptions/optional.cpp + exceptions/variant.cpp + ) + +if (NOT LIBCXX_EXCEPTION_ZOS_BUILD) + 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/*) @@ -283,6 +293,27 @@ endif() endif() +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}" + 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) + + target_link_libraries(cxx_exception PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") + list(APPEND LIBCXX_BUILD_TARGETS "cxx_exception") +endif() + 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 "any" -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"; } +} // namespace std 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_STD_EXCEPTION + +bad_weak_ptr::~bad_weak_ptr() noexcept {} + +const char* bad_weak_ptr::what() const noexcept { return "bad_weak_ptr"; } + +_LIBCPP_END_NAMESPACE_STD_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,18 @@ + +//===----------------------------------------------------------------------===// +//// +//// 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"; } + +} // namespace 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 @@ -20,14 +20,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 "optional" #include "__availability" -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 diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py --- a/libcxx/utils/libcxx/test/config.py +++ b/libcxx/utils/libcxx/test/config.py @@ -378,6 +378,8 @@ def configure_link_flags_cxx_library(self): if self.link_shared: self.cxx.link_flags += ['-lc++'] + if self.target_info.is_zos(): + self.cxx.link_flags += ['-lc++_exception'] else: if self.cxx_library_root: libname = self.make_static_lib_name('c++')