From a9182d06f8589c96c18c4a8f0ab9bcef678e6b12 Mon Sep 17 00:00:00 2001 From: Igor Todorovski Date: Thu, 14 May 2026 17:34:18 -0400 Subject: [PATCH] Add z/OS support with clang Add the z/OS build-data entry, clang ABI flags, shared library linker handling, and s390x cycle counter support. Move z/OS feature macros into the OS configuration and leave clang.txt with clang-specific flags only. Disable the thread_local OS feature for z/OS and gate FFI exception storage on BOTAN_TARGET_OS_HAS_THREAD_LOCAL. Tested with diff checks, z/OS configure generation, native configure, and native compilation of ffi.o and utils_os_utils.o. --- src/build-data/cc/clang.txt | 4 +++- src/build-data/cc/gcc.txt | 5 +++-- src/build-data/os/zos.txt | 29 +++++++++++++++++++++++++++++ src/lib/ffi/ffi.cpp | 10 ++++++++-- src/lib/utils/os_utils/os_utils.cpp | 8 ++++++++ 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/build-data/os/zos.txt diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt index d89da5deb7c..ebb39322097 100644 --- a/src/build-data/cc/clang.txt +++ b/src/build-data/cc/clang.txt @@ -52,6 +52,7 @@ macos -> "{cxx} -dynamiclib -fPIC -install_name {libdir}/{soname_abi} -c # The default works for GNU ld and several other Unix linkers default -> "{cxx} -shared -fPIC -Wl,-soname,{soname_abi}" +zos -> "{cxx} -shared -fPIC" mingw -> "{cxx} -shared -Wl,--out-implib,{shared_lib_name}.a" @@ -105,11 +106,12 @@ llvm -> "-emit-llvm -fno-use-cxa-atexit" -all!haiku,llvm -> "-pthread" +all!haiku,llvm,zos -> "-pthread" x86_32 -> "-m32" x86_64 -> "-m64" ppc64 -> "-m64" +zos -> "-fzos-le-char-mode=ascii -mnocsect -fno-short-enums -m64 -mzos-target=zosv3r1" macos -> "-stdlib=libc++" ios -> "-stdlib=libc++" diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 6a650589086..5c57c560aea 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -57,8 +57,9 @@ macos -> "{cxx} -dynamiclib -fPIC -install_name {libdir}/{soname_abi}" hpux -> "{cxx} -shared -fPIC -Wl,+h,{soname_abi}" solaris -> "{cxx} -shared -fPIC -Wl,-h,{soname_abi}" -# AIX and OpenBSD don't use sonames at all +# These platforms don't use sonames at all aix -> "{cxx} -shared -fPIC" +zos -> "{cxx} -shared -fPIC" openbsd -> "{cxx} -shared -fPIC" mingw -> "{cxx} -shared -Wl,--out-implib,{shared_lib_name}.a" @@ -107,7 +108,7 @@ arm64:neon -> "" # Flags set here are included at compile and link time -all!haiku,qnx,none -> "-pthread" +all!haiku,qnx,zos,none -> "-pthread" s390 -> "-m31" s390x -> "-m64" diff --git a/src/build-data/os/zos.txt b/src/build-data/os/zos.txt new file mode 100644 index 00000000000..df1ed4b8687 --- /dev/null +++ b/src/build-data/os/zos.txt @@ -0,0 +1,29 @@ +soname_suffix "so" + +use_stack_protector no + + +_XOPEN_SOURCE=600 +_ALL_SOURCE +_OPEN_SYS_FILE_EXT=1 +_AE_BIMODAL=1 +_ENHANCED_ASCII_EXT=0xFFFFFFFF + + + +posix1 +clock_gettime +dev_random + +atomics +sockets +system_clock +threads +filesystem + + + +z/OS +os/390 +os390 + diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 30f25f11a20..5fd508e9b2f 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -22,8 +22,14 @@ namespace Botan_FFI { namespace { -// NOLINTNEXTLINE(*-avoid-non-const-global-variables) -thread_local std::string g_last_exception_what; + +#if defined(BOTAN_TARGET_OS_HAS_THREAD_LOCAL) + // NOLINTNEXTLINE(*-avoid-non-const-global-variables) + thread_local std::string g_last_exception_what; +#else + // NOLINTNEXTLINE(*-avoid-non-const-global-variables) + std::string g_last_exception_what; +#endif int ffi_map_error_type(Botan::ErrorType err) { switch(err) { diff --git a/src/lib/utils/os_utils/os_utils.cpp b/src/lib/utils/os_utils/os_utils.cpp index 97922a0c7a9..7ae6e5b6c0b 100644 --- a/src/lib/utils/os_utils/os_utils.cpp +++ b/src/lib/utils/os_utils/os_utils.cpp @@ -71,6 +71,10 @@ #include #endif +#if defined(BOTAN_TARGET_OS_IS_ZOS) + #include +#endif + namespace Botan { uint32_t OS::get_process_id() { @@ -220,7 +224,11 @@ uint64_t OS::get_cpu_cycle_counter() { asm volatile("mov %0=ar.itc" : "=r"(rtc)); #elif defined(BOTAN_TARGET_ARCH_IS_S390X) + #if defined(BOTAN_TARGET_OS_IS_ZOS) + __stckf(&rtc); + #else asm volatile("stck 0(%0)" : : "a"(&rtc) : "memory", "cc"); + #endif #elif defined(BOTAN_TARGET_ARCH_IS_HPPA) asm volatile("mfctl 16,%0" : "=r"(rtc)); // 64-bit only?