Skip to content

Commit

Permalink
Add support for AArch64 macOS
Browse files Browse the repository at this point in the history
This commit adds changes for supporting AArch64 macOS.

Signed-off-by: KONNO Kazuhiro <konno@jp.ibm.com>
  • Loading branch information
knn-k committed Oct 21, 2021
1 parent 894a1ff commit 59b030d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
10 changes: 5 additions & 5 deletions cmake/modules/OmrDetectSystemInformation.cmake
Expand Up @@ -93,16 +93,16 @@ macro(omr_detect_system_information)
set(OMR_ARCH_X86 ON)
set(OMR_ENV_LITTLE_ENDIAN ON)
set(OMR_TEMP_DATA_SIZE "32")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(OMR_HOST_ARCH "aarch64")
set(OMR_ARCH_AARCH64 ON)
set(OMR_ENV_LITTLE_ENDIAN ON)
set(OMR_TEMP_DATA_SIZE "64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
set(OMR_HOST_ARCH "arm")
set(OMR_ARCH_ARM ON)
set(OMR_ENV_LITTLE_ENDIAN ON)
set(OMR_TEMP_DATA_SIZE "32")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(OMR_HOST_ARCH "aarch64")
set(OMR_ARCH_AARCH64 ON)
set(OMR_ENV_LITTLE_ENDIAN ON)
set(OMR_TEMP_DATA_SIZE "64")
elseif(CMAKE_SYSTEM_NAME MATCHES "OS390")
set(OMR_HOST_ARCH "s390")
set(OMR_ARCH_S390 ON)
Expand Down
11 changes: 8 additions & 3 deletions cmake/modules/platform/arch/aarch64.cmake
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2018, 2018 IBM Corp. and others
# Copyright (c) 2018, 2021 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
Expand All @@ -22,12 +22,17 @@
list(APPEND OMR_PLATFORM_DEFINITIONS
-DAARCH64
-DJ9AARCH64
-DAARCH64GNU
-DFIXUP_UNALIGNED
-march=armv8-a+simd
-Wno-unused-but-set-variable
)

# Apple clang does not support the following option.
if(NOT (CMAKE_C_COMPILER_ID MATCHES "^(Apple)?Clang$"))
list(APPEND OMR_PLATFORM_DEFINITIONS
-Wno-unused-but-set-variable
)
endif()

set(TR_HOST_ARCH aarch64)
set(TR_HOST_BITS 64)

Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/platform/os/osx.cmake
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2021 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
Expand Down Expand Up @@ -29,7 +29,7 @@ list(APPEND OMR_PLATFORM_DEFINITIONS
# the distinction
list(APPEND TR_COMPILE_DEFINITIONS -DSUPPORTS_THREAD_LOCAL -DOSX)

if(OMR_ENV_DATA64)
if(OMR_ENV_DATA64 AND NOT OMR_ARCH_AARCH64)
# Set page zero size to 4KB for mapping memory below 4GB.
list(APPEND OMR_PLATFORM_EXE_LINKER_OPTIONS
-pagezero_size 0x1000
Expand Down
12 changes: 9 additions & 3 deletions compiler/aarch64/runtime/CodeSync.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2021 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
Expand All @@ -19,15 +19,21 @@
* 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 defined(__clang__) && defined(__APPLE__)
#include <libkern/OSCacheControl.h>
#endif

// make sure the code gets from the data cache to the instruction cache
void arm64CodeSync(unsigned char *codeStart, unsigned int codeSize)
{
#if defined(TR_HOST_ARM64)
#if defined(__GNUC__)
#if defined(__clang__) && defined(__APPLE__)
sys_icache_invalidate(codeStart, codeSize);
#elif defined(__GNUC__)
// GCC built-in function
__builtin___clear_cache(codeStart, codeStart+codeSize);
#else
#error Not supported yet
#error Unsupported platform
#endif
#endif
}
4 changes: 2 additions & 2 deletions omrmakefiles/rules.linux.mk
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2015, 2020 IBM Corp. and others
# Copyright (c) 2015, 2021 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
Expand Down Expand Up @@ -211,7 +211,7 @@ else ifeq (riscv,$(OMR_HOST_ARCH))
else ifeq (aarch64,$(OMR_HOST_ARCH))
GLOBAL_CFLAGS+=-march=armv8-a+simd -Wno-unused-but-set-variable
GLOBAL_CXXFLAGS+=-march=armv8-a+simd -Wno-unused-but-set-variable
GLOBAL_CPPFLAGS+=-DJ9AARCH64 -DAARCH64GNU -DAARCH64 -DFIXUP_UNALIGNED -Wno-unused-but-set-variable
GLOBAL_CPPFLAGS+=-DJ9AARCH64 -DAARCH64 -DFIXUP_UNALIGNED -Wno-unused-but-set-variable
else
ifeq (arm,$(OMR_HOST_ARCH))
GLOBAL_CFLAGS+=$(ARM_ARCH_FLAGS) -Wno-unused-but-set-variable
Expand Down
8 changes: 8 additions & 0 deletions port/osx/omrosdump.c
Expand Up @@ -51,9 +51,11 @@
struct thread_command_full_64 {
uint32_t cmd;
uint32_t cmdsize;
#if defined(OMR_ARCH_X86)
x86_thread_state_t thread_state;
x86_float_state_t float_state;
x86_exception_state_t exceptions;
#endif /* defined(OMR_ARCH_X86) */
};

static char corefile_name[PATH_MAX];
Expand Down Expand Up @@ -131,6 +133,7 @@ coredump_to_file(mach_port_t task_port, pid_t pid)
goto done;
}
file_off += sizeof(uint32_t);
#if defined(OMR_ARCH_X86)
written = pwrite(corefile_fd, &threads[i].thread_state, sizeof(x86_thread_state_t), file_off);
if (written < 0) {
perror("pwrite() error writing threads:");
Expand All @@ -152,6 +155,7 @@ coredump_to_file(mach_port_t task_port, pid_t pid)
goto done;
}
file_off += sizeof(x86_exception_state_t);
#endif /* defined(OMR_ARCH_X86) */
mh64.sizeofcmds += threads[i].cmdsize;
}
mh64.ncmds += thread_count;
Expand Down Expand Up @@ -221,6 +225,7 @@ coredump_to_file(mach_port_t task_port, pid_t pid)
static kern_return_t
list_thread_commands(mach_port_t task_port, struct thread_command_full_64 **thread_commands, natural_t *thread_count)
{
#if defined(OMR_ARCH_X86)
kern_return_t kr = KERN_SUCCESS;
thread_act_array_t thread_info;
struct thread_command_full_64 *threads = NULL;
Expand Down Expand Up @@ -279,6 +284,9 @@ list_thread_commands(mach_port_t task_port, struct thread_command_full_64 **thre
}
mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)thread_info, (*thread_count) * sizeof(thread_act_t));
return kr;
#else /* defined(OMR_ARCH_X86) */
return KERN_FAILURE;
#endif /* defined(OMR_ARCH_X86) */
}

static kern_return_t
Expand Down
16 changes: 16 additions & 0 deletions port/osx/omrsignal_context.c
Expand Up @@ -93,6 +93,7 @@ infoForSignal(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32
uint32_t
infoForFPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t index, const char **name, void **value)
{
#if defined(OMR_ARCH_X86)
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_X86_FLOAT_STATE64 *floatState = &(*context)->__fs;

Expand Down Expand Up @@ -165,11 +166,15 @@ infoForFPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#endif /* defined(OMR_ARCH_X86) */
}

uint32_t
infoForGPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t index, const char **name, void **value)
{
#if defined(OMR_ARCH_X86)
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_X86_THREAD_STATE64 *threadState = &(*context)->__ss;

Expand Down Expand Up @@ -248,11 +253,15 @@ infoForGPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#endif /* defined(OMR_ARCH_X86) */
}

uint32_t
infoForControl(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t index, const char **name, void **value)
{
#if defined(OMR_ARCH_X86)
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_X86_THREAD_STATE64 *threadState = &(*context)->__ss;
_STRUCT_X86_EXCEPTION_STATE64 *exceptionState = &(*context)->__es;
Expand Down Expand Up @@ -310,11 +319,15 @@ infoForControl(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int3
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#endif /* defined(OMR_ARCH_X86) */
}

uint32_t
infoForModule(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t index, const char **name, void **value)
{
#if defined(OMR_ARCH_X86)
Dl_info *dl_info = &(info->platformSignalInfo.dl_info);
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
int dl_result = dladdr((void *)(*context)->__ss.__rip, dl_info);
Expand Down Expand Up @@ -355,4 +368,7 @@ infoForModule(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#endif /* defined(OMR_ARCH_X86) */
}

0 comments on commit 59b030d

Please sign in to comment.