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() 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,15 @@ +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_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_site.in b/libcxx/include/__config_site.in --- a/libcxx/include/__config_site.in +++ b/libcxx/include/__config_site.in @@ -10,7 +10,18 @@ #define _LIBCPP___CONFIG_SITE #cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ +#if defined(__MVS__) +#include // for __NATIVE_ASCII_F +#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y +#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) +#ifdef __NATIVE_ASCII_F +#cmakedefine _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(@_LIBCPP_ABI_NAMESPACE@,_a) +#else +#cmakedefine _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(@_LIBCPP_ABI_NAMESPACE@,_e) +#endif // __NATIVE_ASCII_F +#else #cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ +#endif #cmakedefine _LIBCPP_ABI_FORCE_ITANIUM #cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT #cmakedefine _LIBCPP_HAS_NO_THREADS diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -218,6 +218,26 @@ cxx_add_common_build_flags(cxx_shared) cxx_set_common_defines(cxx_shared) + if(ZOS) + if(${CMAKE_CXX_COMPILER_TARGET} STREQUAL "s390x-ibm-zos") + # 64 bit + set(dll_name "CRTEQCXE") + set(dll_name_a "CRTEQCXS") + else() + # 32 bit + 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}" + COMMENT "Rename dll name inside the side deck file" + WORKING_DIRECTORY $ + ) + endif() + # Link against LLVM libunwind # Note that we do need to link against libunwind directly to ensure that the correct # dependencies are recorded when creating a linker script. @@ -274,6 +294,40 @@ 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}" + 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. 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,57 @@ +#!/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 + +if ((padding_len=$old_len-$new_len )); then + pad=$(printf "%*s" $padding_len "") +fi + +# Touch the temp. file and set the tag to 1047 first so the redirecting statement +# will write in 1047 and not 819 encoding. +touch $sidedeck.tmp; chtag -tc1047 $sidedeck.tmp +sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck > $sidedeck.tmp +mv $sidedeck.tmp $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 @@ -238,6 +238,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()