diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -471,6 +471,7 @@ # 'config-ix' use them during feature checks. It also adds them to both # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' if(ZOS) + # Make sure EBCDIC encoding is used by default on z/OS. add_target_flags_if_supported("-fzos-le-char-mode=ebcdic") endif() if(LIBCXX_TARGET_TRIPLE) 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,16 @@ +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_ASCII_ZOS_BUILD ON CACHE BOOL + "Build ascii version of libcxx library on z/OS.") +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 @@ -165,7 +165,16 @@ #define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) #ifndef _LIBCPP_ABI_NAMESPACE -# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) +# if defined(__MVS__) +# include // for __NATIVE_ASCII_F +# ifdef __NATIVE_ASCII_F +# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(_LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION),_a) +# else +# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(_LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION),_e) +# endif // __NATIVE_ASCII_F +# else +# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) +# endif #endif #if __cplusplus < 201103L diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -225,6 +225,37 @@ cxx_add_common_build_flags(cxx_shared) cxx_set_common_defines(cxx_shared) + if(ZOS) + set_target_properties(cxx_shared + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + ) + + if(${LIBCXX_TARGET_TRIPLE} STREQUAL "s390x-ibm-zos") + # 64 bit + set (ZOS_BUILD_32_BITS OFF) + set(dll_name "CRTEQCXE") + set(dll_name_a "CRTEQCXS") + else() + # 32 bit + set (ZOS_BUILD_32_BITS ON) + set(dll_name "CRTEHCXE") + set(dll_name_a "CRTEHCXS") + endif() + + add_custom_command(TARGET cxx_shared POST_BUILD + COMMAND + ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh + $ $ "${dll_name}" + > $.tmp + COMMAND + mv $.tmp + $ + COMMENT "Rename dll name inside the side deck file" + WORKING_DIRECTORY $ + ) + endif() + # Link against LLVM libunwind if (LIBCXXABI_USE_LLVM_UNWINDER) if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) @@ -283,6 +314,44 @@ endif() endif() +# Build the ascii shared library for z/OS. +if (LIBCXX_ASCII_ZOS_BUILD) + + add_library(cxx_ascii SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + target_include_directories(cxx_ascii PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(cxx_ascii PUBLIC cxx-headers + PRIVATE ${LIBCXX_LIBRARIES}) + set_target_properties(cxx_ascii + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS} -fzos-le-char-mode=ascii" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++_a" + VERSION "${LIBCXX_ABI_VERSION}.0" + SOVERSION "${LIBCXX_ABI_VERSION}" + DEFINE_SYMBOL "" + POSITION_INDEPENDENT_CODE ON + ) + cxx_add_common_build_flags(cxx_ascii) + cxx_set_common_defines(cxx_ascii) + + add_custom_command(TARGET cxx_ascii POST_BUILD + COMMAND + ${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh + $ $ "${dll_name_a}" + > $.tmp + COMMAND + mv $.tmp + $ + COMMENT "Rename dll name inside the side deck file" + WORKING_DIRECTORY $ + ) + + # Link against libc++abi + target_link_libraries(cxx_ascii PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") + + list(APPEND LIBCXX_BUILD_TARGETS "cxx_ascii") +endif() + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # Build the static library. @@ -396,7 +465,9 @@ target_link_libraries(cxx_external_threads PRIVATE cxx-headers) endif() -if (LIBCXX_INSTALL_SHARED_LIBRARY) +# On z/OS the install for the shared library is performed +# by external script thus, this step is not needed. +if (NOT ZOS AND LIBCXX_INSTALL_SHARED_LIBRARY) install(TARGETS cxx_shared ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx @@ -419,7 +490,9 @@ # NOTE: This install command must go after the cxx install command otherwise # it will not be executed after the library symlinks are installed. -if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) +# On z/OS the install for the shared library is performed +# by external script thus, this step is not needed. +if (NOT ZOS AND LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) install(FILES "$" DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT libcxx) 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++_a'] else: if self.cxx_library_root: libname = self.make_static_lib_name('c++') diff --git a/libcxx/utils/zos_rename_dll_side_deck.sh b/libcxx/utils/zos_rename_dll_side_deck.sh new file mode 100755 --- /dev/null +++ b/libcxx/utils/zos_rename_dll_side_deck.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Script to rename DLL name within side deck. +# + +# Stops execution if a command or pipeline has an error. +set -e + +sidedeck=$1 +old_dll_name=$2 +new_dll_name=$3 + +function error() { + printf "ERROR: %s\n" "$*" + exit 1 +} + +function usage() { +cat < : + [-h|--help] Display this help and exit. +EOF +} + +rename_dll_name_inside_side_deck() { + +if [[ -z "$sidedeck" || -z "$old_dll_name" || -z "$new_dll_name" ]]; then + usage + error "All 3 parameters must be specified." +fi + +[[ -f "$sidedeck" ]] || error "The '$sidedeck' file must exists." + +old_len=${#old_dll_name} +new_len=${#new_dll_name} + +if (( $new_len > $old_len )); then + error "New DLL name $new_dll_name must have $old_len characters or less." +fi + +((padding_len=$old_len-$new_len)) +pad=$(printf "%*s" $padding_len "") +sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck +} + +function main() { + rename_dll_name_inside_side_deck +} + +main "$@" + diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -268,6 +268,7 @@ # Configure target flags if(ZOS) + # Make sure EBCDIC encoding is used by default on z/OS. add_target_flags_if_supported("-fzos-le-char-mode=ebcdic") endif() if(LIBCXXABI_TARGET_TRIPLE)