Index: llvm/CMakeLists.txt =================================================================== --- llvm/CMakeLists.txt +++ llvm/CMakeLists.txt @@ -354,7 +354,12 @@ option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON) -option(LLVM_ENABLE_THREADS "Use threads if available." ON) +# On z/OS, threads cannot be used because TLS is not supported. +if (CMAKE_SYSTEM_NAME MATCHES "OS390") + option(LLVM_ENABLE_THREADS "Use threads if available." OFF) +else() + option(LLVM_ENABLE_THREADS "Use threads if available." ON) +endif() set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON") @@ -932,6 +937,13 @@ string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared") endif() +# Build with _XOPEN_SOURCE on z/OS. +if (CMAKE_SYSTEM_NAME MATCHES "OS390") + add_definitions("-D_XOPEN_SOURCE=600") + add_definitions("-D_OPEN_SYS") # Needed for process information. + add_definitions("-D_OPEN_SYS_FILE_EXT") # Needed for EBCDIC I/O. +endif() + # Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9. if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") add_definitions("-D_FILE_OFFSET_BITS=64") @@ -942,7 +954,7 @@ # check its symbols. This is wasteful (the check was done when foo.so # was created) and can fail since it is not the dynamic linker and # doesn't know how to handle search paths correctly. -if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX") +if (UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "SunOS|AIX|OS390") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined") endif() Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -221,7 +221,7 @@ # Pass -O3 to the linker. This enabled different optimizations on different # linkers. - if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32)) + if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|SunOS|AIX|OS390" OR WIN32)) set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-O3") endif() @@ -249,7 +249,7 @@ LINK_FLAGS " -Wl,-z,discard-unused=sections") endif() elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND - NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD|AIX") + NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD|AIX|OS390") # Object files are compiled with -ffunction-data-sections. # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks # tools that use plugins. Always pass --gc-sections once we require Index: llvm/cmake/modules/GetHostTriple.cmake =================================================================== --- llvm/cmake/modules/GetHostTriple.cmake +++ llvm/cmake/modules/GetHostTriple.cmake @@ -14,6 +14,8 @@ else() set( value "i686-pc-windows-gnu" ) endif() + elseif( CMAKE_SYSTEM_NAME MATCHES "OS390" ) + set( value "s390x-ibm-zos" ) elseif( CMAKE_HOST_SYSTEM_NAME STREQUAL AIX ) # We defer to dynamic detection of the host AIX version. if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -144,6 +144,10 @@ endif(FUCHSIA OR UNIX) endif(WIN32) +if (CMAKE_SYSTEM_NAME MATCHES "OS390") + set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) +endif() + set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX}) set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) @@ -207,7 +211,7 @@ # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO # build might work on ELF but fail on MachO/COFF. -if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS" OR +if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390" OR WIN32 OR CYGWIN) AND NOT LLVM_USE_SANITIZER) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")