Skip to content

Commit

Permalink
Add Open XL toolchain and config changes for zos
Browse files Browse the repository at this point in the history
Adds the initial set of changes to support compilation with
Open XL on z/OS. This will define the alternative flags and
configuration that needs to be used by the wyvern compiler
while running on z/OS.
  • Loading branch information
Deigue committed May 6, 2024
1 parent 1bcf969 commit 3ccf780
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 24 deletions.
6 changes: 6 additions & 0 deletions cmake/modules/OmrDetectSystemInformation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,18 @@ macro(omr_detect_system_information)
# In CMake 3.14 and prior, XLClang uses CMAKE_C_COMPILER_ID "XL"
# In CMake 3.15 and beyond, XLClang uses CMAKE_C_COMPILER_ID "XLClang"
set(_OMR_TOOLCONFIG "xlc")
message(STATUS "CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}")
if(CMAKE_C_COMPILER MATCHES ".*xlclang$")
# Checking the CMAKE_C_COMPILER command is necessary to determine if XLClang is
# the compiler, since XLClang might have CMAKE_C_COMPILER_ID "XL" or "XLClang"
# depending on the CMake version. Without this check, it's ambiguous whether the
# compiler is XLC or XLClang.
set(CMAKE_C_COMPILER_IS_XLCLANG TRUE CACHE BOOL "XLClang is the C compiler")
elseif(CMAKE_C_COMPILER MATCHES ".*ibm-clang.*")
set(CMAKE_C_COMPILER_IS_OPENXL ON CACHE BOOL "ibm-clang is the C compiler")
set(_OMR_TOOLCONFIG "openxl")
else()
message(STATUS "NO MATCH")
endif()
else()
message(FATAL_ERROR "OMR: Unknown compiler ID: '${CMAKE_CXX_COMPILER_ID}'")
Expand Down
262 changes: 262 additions & 0 deletions cmake/modules/platform/toolcfg/openxl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
###############################################################################

# Copyright (c) 2017, 2024 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at http://eclipse.org/legal/epl-2.0
# or the Apache License, Version 2.0 which accompanies this distribution
# and is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the
# Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
# version 2 with the GNU Classpath Exception [1] and GNU General Public
# License, version 2 with the OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] http://openjdk.java.net/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
###############################################################################

if(CMAKE_C_COMPILER_IS_XLCLANG)
macro(omr_toolconfig_global_setup)
# For XLClang, remove any usages of -qhalt=e or -qhalt=s provided by default
# in the CMAKE CXX/C/ASM FLAGS, since xlclang/xlclang++ are not compatible
# with the e or s options.
omr_remove_flags(CMAKE_ASM_FLAGS -qhalt=e)
omr_remove_flags(CMAKE_CXX_FLAGS -qhalt=s)
omr_remove_flags(CMAKE_C_FLAGS -qhalt=e)
endmacro(omr_toolconfig_global_setup)
endif()

if(OMR_HOST_ARCH STREQUAL "ppc")
set(OMR_C_WARNINGS_AS_ERROR_FLAG -qhalt=w)
set(OMR_CXX_WARNINGS_AS_ERROR_FLAG -qhalt=w)

# There is no enhanced warning for XLC right now
set(OMR_C_ENHANCED_WARNINGS_FLAG )
set(OMR_CXX_ENHANCED_WARNINGS_FLAG )

list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
#-qalias=noansi # no openxl equivalent
-qxflag=LTOL:LTOL0
)

list(APPEND OMR_PLATFORM_CXX_COMPILE_OPTIONS -qlanglvl=extended0x)

if(OMR_ENV_DATA64)
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
-m64
)
else()
# -qarch should be there for 32 and 64 C/CXX flags but the C compiler is used for the assembler and it has trouble with some assembly files if it is specified
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
#-q32 # no equivalent in openxl
-march=ppc
)
endif()

# Testarossa build variables. Longer term the distinction between TR and the rest
# of the OMR code should be heavily reduced. In the mean time, we keep
# the distinction

# TR_COMPILE_OPTIONS are variables appended to CMAKE_{C,CXX}_FLAGS, and so
# apply to both C and C++ compilations.
list(APPEND TR_COMPILE_OPTIONS
-march=pwr7
-qtls
-qfuncsect
-qsuppress=1540-1087:1540-1088:1540-1090:1540-029:1500-029
-qdebug=nscrep
)

if(NOT CMAKE_C_COMPILER_IS_XLCLANG)
# xlc/xlc++ options
list(APPEND TR_COMPILE_OPTIONS
-qnotempinc
-qenum=small
-qmbcs
)
endif()

# Configure the platform dependent library for multithreading
set(OMR_PLATFORM_THREAD_LIBRARY -lpthread)
endif()

if(OMR_OS_AIX)
list(APPEND OMR_PLATFORM_C_COMPILE_OPTIONS -qlanglvl=extended)
list(APPEND OMR_PLATFORM_CXX_COMPILE_OPTIONS -qlanglvl=extended0x)

if(CMAKE_C_COMPILER_IS_XLCLANG)
# xlclang/xlclang++ options
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS -qxlcompatmacros)
else()
# xlc/xlc++ options
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS -qinfo=pro)
endif()

set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lm -liconv -ldl -lperfstat")

if(OMR_ENV_DATA64)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -q64")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -q64")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -q64")

set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -X64 cr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -X64 cr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -X64 <TARGET>")
endif()

elseif(OMR_OS_LINUX)
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
-qxflag=selinux
)
elseif(OMR_OS_ZOS)
set(OMR_ZOS_COMPILE_ARCHITECTURE "arch10" CACHE STRING "z/OS compile machine architecture")
set(OMR_ZOS_COMPILE_TARGET "ZOSV2R4" CACHE STRING "z/OS compile target operating system")
set(OMR_ZOS_COMPILE_TUNE "12" CACHE STRING "z/OS compile machine architecture tuning")
set(OMR_ZOS_LINK_COMPAT "ZOSV2R4" CACHE STRING "z/OS link compatible operating system")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "--shared")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "--shared")


set(CMAKE_ASM_FLAGS "-fno-integrated-as")
string(APPEND CMAKE_ASM_FLAGS " \"-Wa,-mgoff\"")
string(APPEND CMAKE_ASM_FLAGS " \"-Wa,-mSYSPARM(BIT64)\"")

# commenting out options progressively as they are not needed with Open XL, can remove in cleanup later.
list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
#"\"-Wc,xplink\"" # link with xplink calling convention
#"\"-Wc,rostring\"" # place string literals in read only storage
#"\"-Wc,FLOAT(IEEE,FOLD,AFP)\"" # Use IEEE (instead of IBM Hex Format) style floats
#"\"-Wc,enum(4)\"" # Specifies how many bytes of storage enums occupy
#"\"-Wa,goff\"" # Assemble into GOFF object files
#"\"-Wc,NOANSIALIAS\"" # Do not generate ALIAS binder control statements
"-fstrict-aliasing"
#"\"-Wc,TARGET(${OMR_ZOS_COMPILE_TARGET})\"" # Generate code for the target operating system
"-mzos-target=${OMR_ZOS_COMPILE_TARGET}"
"-m64"
)

list(APPEND OMR_PLATFORM_C_COMPILE_OPTIONS
#"\"-Wc,ARCH(${OMR_ZOS_COMPILE_ARCHITECTURE})\""
-march=${OMR_ZOS_COMPILE_ARCHITECTURE}
#"\"-Wc,TUNE(${OMR_ZOS_COMPILE_TUNE})\"" # not needed openxl
#"\"-Wl,compat=${OMR_ZOS_LINK_COMPAT}\""
#"\"-Wc,langlvl(extc99)\"" # best suggested to remove -std option altogether
)

list(APPEND OMR_PLATFORM_CXX_COMPILE_OPTIONS
#-+ # Compiles any file as a C++ language file
-march=${OMR_ZOS_COMPILE_ARCHITECTURE}
#"\"-Wc,TUNE(${OMR_ZOS_COMPILE_TUNE})\"" # not needed openxl
#"\"-Wl,compat=${OMR_ZOS_LINK_COMPAT}\""
#"\"-Wc,langlvl(extended)\""
"-std=c++14"
#-qlanglvl=extended0x
-fasm
#-fno-integrated-as # Ensure the clang integrated assembler is not used
)

list(APPEND OMR_PLATFORM_SHARED_COMPILE_OPTIONS
-fvisibility=default
)

if(OMR_ENV_DATA64)
list(APPEND OMR_PLATFORM_DEFINITIONS
-DJ9ZOS39064
)
else()
list(APPEND OMR_PLATFORM_DEFINITIONS
-D_LARGE_FILES
)
endif()

# Testarossa build variables. Longer term the distinction between TR and the rest
# of the OMR code should be heavily reduced. In the mean time, we keep
# the distinction

# TR_COMPILE_OPTIONS are variables appended to CMAKE_{C,CXX}_FLAGS, and so
# apply to both C and C++ compilations.
list(APPEND TR_COMPILE_OPTIONS
-DYYLMAX=1000
-Wa,asa
)

list(APPEND TR_CXX_COMPILE_OPTIONS
-Wc,EXH
-qhaltonmsg=CCN6102
-qnocsect
)

# Configure the platform dependent library for multithreading
set(OMR_PLATFORM_THREAD_LIBRARY "")
endif()

set(SPP_CMD ${CMAKE_C_COMPILER})

if(CMAKE_C_COMPILER_IS_XLCLANG)
# xlclang/xlclang++ options
# The -P option doesn't sit well with XLClang, so it's not included. It causes:
# "ld: 0711-317 ERROR: Undefined symbol: <SYMBOL>" when libj9jit29.so is getting linked.
set(SPP_FLAGS -E)
else()
# xlc/xlc++ options
set(SPP_FLAGS -E -P)
endif()

if(OMR_OS_ZOS)
function(_omr_toolchain_process_exports TARGET_NAME)
# Any type of target which says it has exports should get the DLL, and EXPORTALL
# compile flags
# Not needed for openxl
#target_compile_options(${TARGET_NAME}
# PRIVATE
# -Wc,DLL,EXPORTALL
#)

# only shared libraries will generate an export side deck
get_target_property(target_type ${TARGET_NAME} TYPE)
if(NOT target_type STREQUAL "SHARED_LIBRARY")
return()
endif()
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}"
"-DLIBRARY_FILE_NAME=$<TARGET_FILE_NAME:${TARGET_NAME}>"
"-DRUNTIME_DIR=$<TARGET_FILE_DIR:${TARGET_NAME}>"
"-DARCHIVE_DIR=$<TARGET_PROPERTY:${TARGET_NAME},ARCHIVE_OUTPUT_DIRECTORY>"
"-DOMR_TOOLCONFIG=${_OMR_TOOLCONFIG}"
-P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake"
)
endfunction()
else()
function(_omr_toolchain_process_exports TARGET_NAME)
# we only need to do something if we are dealing with a shared library
get_target_property(target_type ${TARGET_NAME} TYPE)
if(NOT target_type STREQUAL "SHARED_LIBRARY")
return()
endif()

set(exp_file "$<TARGET_PROPERTY:${TARGET_NAME},BINARY_DIR>/${TARGET_NAME}.exp")
omr_process_template(
"${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/xlc_exports.exp.in"
"${exp_file}"
)
set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-bE:${TARGET_NAME}.exp")
endfunction()

function(_omr_toolchain_separate_debug_symbols tgt)
set(exe_file "$<TARGET_FILE:${tgt}>")
omr_get_target_output_genex(${tgt} output_name)
set(dbg_file "${output_name}${OMR_DEBUG_INFO_OUTPUT_EXTENSION}")
add_custom_command(
TARGET "${tgt}"
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy ${exe_file} ${dbg_file}
COMMAND "${CMAKE_STRIP}" -X32_64 -t ${exe_file}
)
set_target_properties(${tgt} PROPERTIES OMR_DEBUG_FILE "${dbg_file}")
endfunction()
endif()
1 change: 1 addition & 0 deletions cmake/modules/platform/toolcfg/xlc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ if(OMR_OS_ZOS)
"-DLIBRARY_FILE_NAME=$<TARGET_FILE_NAME:${TARGET_NAME}>"
"-DRUNTIME_DIR=$<TARGET_FILE_DIR:${TARGET_NAME}>"
"-DARCHIVE_DIR=$<TARGET_PROPERTY:${TARGET_NAME},ARCHIVE_OUTPUT_DIRECTORY>"
"-DOMR_TOOLCONFIG=${_OMR_TOOLCONFIG}"
-P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake"
)
endfunction()
Expand Down
5 changes: 4 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,8 @@ Some influential environment variables:
Specifies whether the package will run in 32- or 64-bit mode.
One of: 31,32,64
OMR_TOOLCHAIN
The toolchain used to build the package. One of: gcc,xlc,msvc
The toolchain used to build the package. One of:
gcc,xlc,msvc,openxl
OMR_TOOLS_CC
The C compiler to use for building tools (can differ from CC).
OMR_TOOLS_CXX
Expand Down Expand Up @@ -4679,6 +4680,8 @@ case $OMR_TOOLCHAIN in #(
;; #(
msvc) :
;; #(
openxl) :
;; #(
*) :
as_fn_error $? "An invalid value was provided for OMR_TOOLCHAIN: $OMR_TOOLCHAIN" "$LINENO" 5
;;
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AC_ARG_VAR([exe_output_dir], [The output directory for executables. (Default: $t
AC_ARG_VAR([OMR_HOST_OS], [The operating system where the package will run. One of: aix,linux,osx,win,zos])
AC_ARG_VAR([OMR_HOST_ARCH], [The architecture of the CPU where the package will run. One of: aarch64,arm,ppc,riscv,s390,x86])
AC_ARG_VAR([OMR_TARGET_DATASIZE], [Specifies whether the package will run in 32- or 64-bit mode. One of: 31,32,64])
AC_ARG_VAR([OMR_TOOLCHAIN], [The toolchain used to build the package. One of: gcc,xlc,msvc])
AC_ARG_VAR([OMR_TOOLCHAIN], [The toolchain used to build the package. One of: gcc,xlc,msvc,openxl])
AC_ARG_VAR([OMR_TOOLS_CC], [The C compiler to use for building tools (can differ from CC).])
AC_ARG_VAR([OMR_TOOLS_CXX], [The C++ compiler to use for building tools (can differ from CXX).])
AC_ARG_VAR([OMR_CROSS_CONFIGURE],
Expand Down Expand Up @@ -231,6 +231,7 @@ AS_CASE([$OMR_TOOLCHAIN],
[gcc],[],
[xlc],[],
[msvc],[],
[openxl],[],
[AC_MSG_ERROR([An invalid value was provided for OMR_TOOLCHAIN: $OMR_TOOLCHAIN])]
)
AC_MSG_RESULT([$OMR_TOOLCHAIN])
Expand Down
2 changes: 1 addition & 1 deletion ddr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include $(top_srcdir)/omrmakefiles/configure.mk

OMR_TOOLCHAIN ?= gcc

ifneq (,$(filter gcc xlc,$(OMR_TOOLCHAIN)))
ifneq (,$(filter gcc xlc openxl,$(OMR_TOOLCHAIN)))
DEBUG_FORMAT = dwo
else ifeq (msvc,$(OMR_TOOLCHAIN))
DEBUG_FORMAT = pdb
Expand Down
Loading

0 comments on commit 3ccf780

Please sign in to comment.