Skip to content

Commit

Permalink
Modifications for OpenXL Compatibility on AIX
Browse files Browse the repository at this point in the history
To ensure that OpenJ9 can be built on AIX with both OpenXL and xlC, make
modifications to compiler flags, macros, and linked libraries.

Signed-off-by: midronij <[email protected]>
  • Loading branch information
midronij committed Dec 11, 2024
1 parent 3817e9b commit 6f5c2cf
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 31 deletions.
9 changes: 7 additions & 2 deletions runtime/cmake/platform/os/aix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
# Override cmake default of ".a" for shared libs on aix
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-G,-brtl,-bernotok,-bnoentry,-bnolibpath")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-brtl")
if(CMAKE_C_COMPILER_IS_OPENXL)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-G,-brtl,-bernotok,-bnoentry,-bnolibpath -latomic -lperfstat -liconv")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-brtl -latomic -lperfstat -liconv")
else()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-G,-brtl,-bernotok,-bnoentry,-bnolibpath")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-brtl")
endif()
5 changes: 3 additions & 2 deletions runtime/cmake/platform/toolcfg/gnu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ list(APPEND OMR_PLATFORM_CXX_COMPILE_OPTIONS -fno-threadsafe-statics)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")

# Raise an error if a shared library has any unresolved symbols.
# This flag isn't supported on OSX, but it has this behaviour by default
if(NOT OMR_OS_OSX)
# This flag isn't supported on OSX or AIX with OpenXL,
# but it has this behaviour by default.
if(NOT OMR_OS_OSX AND (NOT OMR_OS_AIX OR NOT CMAKE_C_COMPILER_IS_OPENXL))
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,defs ${CMAKE_SHARED_LINKER_FLAGS}")
endif()

Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ elseif(OMR_OS_AIX)
-DSUPPORTS_THREAD_LOCAL
)
if(OMR_ENV_DATA64)
list(APPEND J9_SHAREDFLAGS -q64)
if(CMAKE_C_COMPILER_IS_OPENXL)
list(APPEND J9_SHAREDFLAGS -m64)
else()
list(APPEND J9_SHAREDFLAGS -q64)
endif()
if(OMR_TOOLCONFIG STREQUAL "xlc")
# Modify the arch tuning value we inherit from OMR.
list(REMOVE_ITEM TR_COMPILE_OPTIONS "-qarch=pwr7")
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/J9KnownObjectTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*******************************************************************************/

#include "compile/Compilation.hpp"
#include "env/alloca_openxl.h"
#include "env/j9fieldsInfo.h"
#include "env/KnownObjectTable.hpp"
#include "env/StackMemoryRegion.hpp"
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif /* defined(J9VM_OPT_JITSERVER) */

#include "env/VMJ9.h"
#include "env/alloca_openxl.h"

#include <algorithm>
#include <ctype.h>
Expand Down
25 changes: 25 additions & 0 deletions runtime/compiler/env/alloca_openxl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright IBM Corp. and others 2024
*
* 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 https://www.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] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/

#if defined(__open_xl__)
#define alloca(size) __builtin_alloca(size)
#endif /* defined(__open_xl__) */
1 change: 1 addition & 0 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*******************************************************************************/

#include "env/j9method.h"
#include "env/alloca_openxl.h"

#include <stddef.h>
#include "bcnames.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/p/runtime/Emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#ifdef __GNUC__
#define trailingZeroes(x) __builtin_ctzl(x)
#elif defined(__IBMC__) || defined(__ibmxl__)
#elif defined(__IBMC__) || defined(__ibmxl__) || defined(__open_xl__)
#define trailingZeroes(x) __cnttz8(x)
#endif

Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/p/runtime/PPCHWProfilerPrivate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ extern "C" void ebbHandler(void);
#define BHRBE_POWER_MASK 1L

/* Any changes to MTSPR should be copied to runtime/port/linuxppc/j9ri.c. */
#if defined(__xlC__) || defined(__ibmxl__)
#if defined(__xlC__) || defined(__ibmxl__) || defined(__open_xl__)
#define MTSPR(spr, src) __mtspr(spr, src)
#define MFSPR(dst, spr) ((dst) = __mfspr(spr))
#elif defined(__GNUC__)
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/runtime/JitRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "control/Options_inlines.hpp"
#include "control/Recompilation.hpp"
#include "control/CompilationStrategy.hpp"
#include "env/alloca_openxl.h"
#include "env/CompilerEnv.hpp"
#include "env/IO.hpp"
#include "env/J2IThunk.hpp"
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#endif /* defined(J9VM_OPT_JITSERVER) */

// TODO: move this someplace common for RuntimeAssumptions.cpp and here
#if defined(__IBMCPP__) && !defined(AIXPPC) && !defined(LINUXPPC)
#if (defined(__IBMCPP__) || defined(__open_xl__)) && !defined(AIXPPC) && !defined(LINUXPPC)
#define ASM_CALL __cdecl
#else
#define ASM_CALL
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/runtime/SymbolValidationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string.h>
#include "env/VMJ9.h"
#include "env/alloca_openxl.h"
#include "env/ClassLoaderTable.hpp"
#include "env/JSR292Methods.h"
#include "env/PersistentCHTable.hpp"
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/asmprotos.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#endif


#if (defined(__IBMCPP__) || defined(__IBMC__) && !defined(MVS)) && !defined(J9ZOS390) && !defined(LINUXPPC64)
#if (defined(__IBMCPP__) || defined(__IBMC__) && !defined(__MVS__) || defined(__open_xl__)) && !defined(J9ZOS390) && !defined(LINUXPPC64)
#if defined(AIXPPC)
#define JIT_HELPER(x) extern "C" void * x
#else
Expand Down
10 changes: 7 additions & 3 deletions runtime/gc_glue_java/configure_includes/configure_aix_ppc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ CONFIGURE_ARGS += 'OMR_HOST_OS=aix'
CONFIGURE_ARGS += 'OMR_HOST_ARCH=ppc'
CONFIGURE_ARGS += 'OMR_TARGET_DATASIZE=$(TEMP_TARGET_DATASIZE)'
CONFIGURE_ARGS += 'OMR_TOOLCHAIN=xlc'

CONFIGURE_ARGS+= 'GLOBAL_CFLAGS=-qstackprotect'
CONFIGURE_ARGS+= 'GLOBAL_CXXFLAGS=-qstackprotect'
ifeq ($(OMR_ENV_OPENXL),1)
CONFIGURE_ARGS += 'GLOBAL_CFLAGS=-fstack-protector'
CONFIGURE_ARGS += 'GLOBAL_CXXFLAGS=-fstack-protector'
else
CONFIGURE_ARGS += 'GLOBAL_CFLAGS=-qstackprotect'
CONFIGURE_ARGS += 'GLOBAL_CXXFLAGS=-qstackprotect'
endif
8 changes: 4 additions & 4 deletions runtime/j9vm/jvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4544,11 +4544,11 @@ JVM_Lseek(jint descriptor, jlong bytesToSeek, jint origin)
}

#if defined(WIN32)
#ifdef __IBMC__
#if defined(__IBMC__)
result = lseek(descriptor, (long) bytesToSeek, origin);
#else
#else /* defined(__IBMC__) */
result = _lseeki64(descriptor, bytesToSeek, origin);
#endif
#endif /* defined(__IBMC__) */
#elif defined(J9UNIX) || defined(J9ZOS390) /* defined(WIN32) */
#if defined(LINUX) && !defined(J9VM_ENV_DATA64)

Expand Down Expand Up @@ -4644,7 +4644,7 @@ JVM_Open(const char* filename, jint flags, jint mode)
#define JVM_EEXIST -100

#ifdef WIN32
#ifdef __IBMC__
#if defined(__IBMC__)
#define EXTRA_OPEN_FLAGS O_NOINHERIT | O_BINARY
#else
#define EXTRA_OPEN_FLAGS _O_NOINHERIT | _O_BINARY
Expand Down
54 changes: 43 additions & 11 deletions runtime/makelib/targets.mk.aix.inc.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ endif
ifeq ($(j9vm_env_data64),1)
UMA_ASPP_DEBUG += -g
UMA_LIB_LINKER_FLAGS += -X64
UMA_CC_MODE += -q64
ifeq ($(OMR_ENV_OPENXL),1)
UMA_CC_MODE += -m64
else
UMA_CC_MODE += -q64
endif
else
UMA_ASPP_DEBUG += $(VMASMDEBUG)
UMA_LIB_LINKER_FLAGS += -X32
Expand Down Expand Up @@ -98,13 +102,22 @@ else
endif

ifeq (,$(findstring xlclang,$(notdir $(CC))))
# xlc options
CFLAGS += -q mbcs -qinfo=pro
ifeq ($(OMR_ENV_OPENXL),1)
# for openxl do nothing
else
# xlc options
CFLAGS += -q mbcs -qinfo=pro
endif
else
# xlclang options
# xlclang options
CFLAGS += -qxlcompatmacros
endif
CFLAGS += -qlanglvl=extended -qarch=ppc -qalias=noansi -qxflag=LTOL:LTOL0 -qsuppress=1506-1108 -qstackprotect
ifeq ($(OMR_ENV_OPENXL),1)
#openxl options
CFLAGS += -std=c89 -qarch=ppc -fno-strict-aliasing -fstack-protector
else
CFLAGS += -qlanglvl=extended -qarch=ppc -qalias=noansi -qxflag=LTOL:LTOL0 -qsuppress=1506-1108 -qstackprotect
endif
CFLAGS += -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE -DRS6000 -DAIXPPC -D_LARGE_FILES

ifdef I5_VERSION
Expand All @@ -114,13 +127,23 @@ else
endif

ifeq (,$(findstring xlclang++,$(notdir $(CXX))))
# xlc++ options
CXXFLAGS += -q mbcs -qinfo=pro
ifeq ($(OMR_ENV_OPENXL),1)
# openxl options
CXXFLAGS += -fno-rtti -fno-exceptions
else
# xlc++ options
CXXFLAGS += -q mbcs -qinfo=pro
endif
else
# xlclang++ options
CXXFLAGS += -qxlcompatmacros -fno-rtti -fno-exceptions
endif
CXXFLAGS += -qlanglvl=extended0x -qarch=ppc -qalias=noansi -qxflag=LTOL:LTOL0 -qsuppress=1506-1108 -qstackprotect
ifeq ($(OMR_ENV_OPENXL),1)
# openxl options
CXXFLAGS += -std=c++11 -qarch=ppc -fno-strict-aliasing -fstack-protector
else
CXXFLAGS += -qlanglvl=extended0x -qarch=ppc -qalias=noansi -qxflag=LTOL:LTOL0 -qsuppress=1506-1108 -qstackprotect
endif
CXXFLAGS += -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE -DRS6000 -DAIXPPC -D_LARGE_FILES
CPPFLAGS += -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE -DRS6000 -DAIXPPC -D_LARGE_FILES

Expand All @@ -143,7 +166,11 @@ endif
UMA_SYS_LINK_PATH := -L/usr/lib/threads

ifeq ($(j9vm_env_data64),1)
UMA_DLL_LINK_FLAGS += -q64
ifeq ($(OMR_ENV_OPENXL),1)
UMA_DLL_LINK_FLAGS += -m64
else
UMA_DLL_LINK_FLAGS += -q64
endif
else
UMA_DLL_LINK_FLAGS += -q32
endif
Expand Down Expand Up @@ -178,7 +205,12 @@ $(patsubst %.s,%.o,$(filter %.s,$(UMA_FILES_TO_PREPROCESS))) : %$(UMA_DOT_O) : %

ifdef UMA_TREAT_WARNINGS_AS_ERRORS
ifndef UMA_SUPPRESS_WARNINGS_AS_ERRORS
CFLAGS += -qhalt=w
CXXFLAGS += -qhalt=w
ifeq ($(OMR_ENV_OPENXL),1)
CFLAGS += -Werror
CXXFLAGS += -Werror
else
CFLAGS += -qhalt=w
CXXFLAGS += -qhalt=w
endif
endif
endif
4 changes: 2 additions & 2 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ typedef struct J9ExceptionHandler {
U_32 exceptionClassIndex;
} J9ExceptionHandler;

#if defined(__xlC__) || defined(J9ZOS390) /* Covers: Z/OS, AIX, Linux PPC*/
#if defined(__xlC__) || defined(J9ZOS390) || defined(__open_xl__) /* Covers: AIX, Linux PPC and z/OS. */
#pragma pack(1)
#elif defined(__ibmxl__) || defined(__GNUC__) || defined(_MSC_VER) /* Covers: Linux PPC LE, Windows, Linux x86 */
#pragma pack(push, 1)
Expand All @@ -1635,7 +1635,7 @@ typedef struct J9MethodParametersData {
J9MethodParameter parameters;
} J9MethodParametersData;

#if defined(__xlC__) || defined(__ibmxl__) || defined(__GNUC__) || defined(_MSC_VER) || defined(J9ZOS390) || defined(LINUX) || defined(AIXPPC) || defined(WIN32)
#if defined(__xlC__) || defined(__ibmxl__) || defined(__open_xl__) || defined(__GNUC__) || defined(_MSC_VER) || defined(J9ZOS390) || defined(LINUX) || defined(AIXPPC) || defined(WIN32)
#pragma pack(pop)
#else
#error "Unrecognized compiler. Cannot pack struct J9MethodParameter and J9MethodParametersData."
Expand Down
2 changes: 1 addition & 1 deletion runtime/port/linuxppc/j9ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define MMCR0_PMAE 0x04000000

/* Please keep this definition in sync with the one in PPCHWProfilerPrivate.hpp. */
#if defined(__xlC__) || defined(__ibmxl__)
#if defined(__xlC__) || defined(__ibmxl__) || defined(__open_xl__)
#define MTSPR(spr, src) __mtspr(spr, src)
#elif defined(__GNUC__)
#define MTSPR(spr, src) asm("mtspr %0,%1\n\t" : : "i" (spr), "r" (src))
Expand Down
6 changes: 5 additions & 1 deletion runtime/tests/redirector/jep178/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ if(OMR_OS_LINUX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
endif()
elseif(OMR_OS_AIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qpic -brtl -bexpall")
if(CMAKE_C_COMPILER_IS_OPENXL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -brtl -bexpall")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qpic -brtl -bexpall")
endif()
endif()

j9vm_add_executable(testjep178_static
Expand Down

0 comments on commit 6f5c2cf

Please sign in to comment.