Enable building SOS on Apple Silicon (#1553)

This commit is contained in:
Steve MacLean 2020-09-14 12:50:48 -04:00 коммит произвёл GitHub
Родитель fa66386217
Коммит 813215ae4e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 84 добавлений и 21 удалений

Просмотреть файл

@ -191,7 +191,14 @@ endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
set(CLR_CMAKE_PLATFORM_UNIX_ARM64 1)
else()
message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES:'${CMAKE_OSX_ARCHITECTURES}'")
clr_unknown_arch()
endif()
set(CLR_CMAKE_PLATFORM_DARWIN 1)
if(CMAKE_VERSION VERSION_LESS "3.4.0")
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> -o <OBJECT> -c <SOURCE>")

Просмотреть файл

@ -72,15 +72,29 @@ to_lowercase() {
#
# Set the default arguments for build
# Use uname to determine what the CPU is.
CPUName=$(uname -p)
# Some Linux platforms report unknown for platform, but the arch for machine.
if [ "$CPUName" == "unknown" ]; then
CPUName=$(uname -m)
OSName=$(uname -s)
if [ "$OSName" = "Darwin" ]; then
# On OSX universal binaries make uname -m unreliable. The uname -m response changes
# based on what hardware is being emulated.
# Use sysctl instead
if [ "$(sysctl -q -n hw.optional.arm64)" = "1" ]; then
CPUName=arm64
elif [ "$(sysctl -q -n hw.optional.x86_64)" = "1" ]; then
CPUName=x86_64
else
CPUName=$(uname -m)
fi
else
# Use uname to determine what the CPU is.
CPUName=$(uname -p)
# Some Linux platforms report unknown for platform, but the arch for machine.
if [ "$CPUName" == "unknown" ]; then
CPUName=$(uname -m)
fi
fi
case $CPUName in
i686)
i686|i386)
echo "Unsupported CPU $CPUName detected, build might not succeed!"
__BuildArch=x86
__HostArch=x86
@ -97,7 +111,7 @@ case $CPUName in
__HostArch=arm
;;
aarch64)
aarch64|arm64)
__BuildArch=arm64
__HostArch=arm64
;;
@ -412,8 +426,8 @@ fi
if [ "$__HostOS" == "OSX" ]; then
export LLDB_H=$__ProjectRoot/src/SOS/lldbplugin/swift-4.0
export LLDB_LIB=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/LLDB
export LLDB_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
export LLDB_LIB=$(xcode-select -p)/../SharedFrameworks/LLDB.framework/LLDB
export LLDB_PATH=$(xcode-select -p)/usr/bin/lldb
export MACOSX_DEPLOYMENT_TARGET=10.12
@ -435,6 +449,15 @@ if [ "$__HostOS" == "OSX" ]; then
export PATH=/usr/bin:$PATH
which python
python --version
if [[ "$__BuildArch" == x64 ]]; then
__ExtraCmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $__ExtraCmakeArgs"
elif [[ "$__BuildArch" == arm64 ]]; then
__ExtraCmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $__ExtraCmakeArgs"
else
echo "Error: Unknown OSX architecture $__BuildArch."
exit 1
fi
fi
#

Просмотреть файл

@ -2122,6 +2122,8 @@ GetThreadTimes(
#define PAL_CS_NATIVE_DATA_SIZE 76
#elif defined(__APPLE__) && defined(__x86_64__)
#define PAL_CS_NATIVE_DATA_SIZE 120
#elif defined(__APPLE__) && defined(__arm64__)
#define PAL_CS_NATIVE_DATA_SIZE 120
#elif defined(__FreeBSD__) && defined(_X86_)
#define PAL_CS_NATIVE_DATA_SIZE 12
#elif defined(__FreeBSD__) && defined(__x86_64__)

Просмотреть файл

@ -5,7 +5,11 @@
.macro NESTED_ENTRY Name, Section, Handler
LEAF_ENTRY \Name, \Section
.ifnc \Handler, NoHandler
#if defined(__APPLE__)
.cfi_personality 0x9b, C_FUNC(\Handler) // 0x9b == DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4
#else
.cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
#endif
.endif
.endm
@ -20,13 +24,20 @@ C_FUNC(\Name):
.macro LEAF_ENTRY Name, Section
.global C_FUNC(\Name)
#if defined(__APPLE__)
.text
.p2align 2
#else
.type \Name, %function
#endif
C_FUNC(\Name):
.cfi_startproc
.endm
.macro LEAF_END Name, Section
#if !defined(__APPLE__)
.size \Name, .-\Name
#endif
.cfi_endproc
.endm
@ -37,8 +48,13 @@ C_FUNC(\Name\()_End):
.endm
.macro PREPARE_EXTERNAL_VAR Name, HelperReg
adrp \HelperReg, \Name
add \HelperReg, \HelperReg, :lo12:\Name
#if defined(__APPLE__)
adrp \HelperReg, C_FUNC(\Name)@GOTPAGE
ldr \HelperReg, [\HelperReg, C_FUNC(\Name)@GOTPAGEOFF]
#else
adrp \HelperReg, C_FUNC(\Name)
add \HelperReg, \HelperReg, :lo12:C_FUNC(\Name)
#endif
.endm
.macro PROLOG_STACK_ALLOC Size

Просмотреть файл

@ -50,7 +50,7 @@ else()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(PAL_CMAKE_PLATFORM_ARCH_ARM 1)
add_definitions(-D_ARM_)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(PAL_CMAKE_PLATFORM_ARCH_ARM64 1)
add_definitions(-D_ARM64_)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
@ -64,14 +64,6 @@ else()
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-D_TARGET_MAC64)
add_definitions(-DXSTATE_SUPPORTED)
set(PLATFORM_SOURCES
arch/amd64/context.S
)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-DPLATFORM_UNIX=1)
add_definitions(-DLP64COMPATIBLE=1)
add_definitions(-DFEATURE_PAL=1)
@ -98,6 +90,14 @@ elseif(PAL_CMAKE_PLATFORM_ARCH_MIPS64)
set(PAL_ARCH_SOURCES_DIR mips64)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_definitions(-D_TARGET_MAC64)
add_definitions(-DXSTATE_SUPPORTED)
set(PLATFORM_SOURCES
arch/${PAL_ARCH_SOURCES_DIR}/context.S
)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(PAL_CMAKE_PLATFORM_ARCH_AMD64 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CLR_CMAKE_PLATFORM_ALPINE_LINUX)
# Currently the _xstate is not available on Alpine Linux
add_definitions(-DXSTATE_SUPPORTED)

Просмотреть файл

@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "unixasmmacros.inc"
#if defined(_DEBUG)
NESTED_ENTRY DBG_CheckStackAlignment, _TEXT, NoHandler
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -16
// Reading from an unaligned stack pointer will trigger a stack alignment fault
ldr x0, [sp]
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 16
ret
NESTED_END _DBG_CheckStackAlignment, _TEXT
#endif