Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial CoreCLR compilation support for Apple Silicon #40435

Merged
merged 100 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
1c1083e
Add initial CoreCLR compilation support for Apple Silicon
sdmaclea Aug 3, 2020
83a45b8
Remove compact unwind entries from assembly files
sdmaclea Aug 5, 2020
af1acc4
Disable FEATURE_WRITEBARRIER_COPY
sdmaclea Aug 5, 2020
37d29f8
CONTEXT_SEGMENTS feedback
sdmaclea Aug 6, 2020
8d21b27
Revert incidental change
sdmaclea Aug 6, 2020
e72e45c
Revise StepWithCompactEncoding
sdmaclea Aug 6, 2020
657a57b
Fix CLR_CMAKE_HOST_* arch
sdmaclea Aug 8, 2020
7457f37
Workaround using dotnet/msbuild with rosetta
sdmaclea Aug 8, 2020
f3dcdf3
Feedback on OSX does not support X86
sdmaclea Aug 10, 2020
96d4787
Feedback fix typo
sdmaclea Aug 10, 2020
ba2f9ae
Fix init-os-and-arch.sh
sdmaclea Aug 10, 2020
6cb8ceb
Fix cmake closing conditonal mismatch
sdmaclea Aug 10, 2020
27ebc7a
Fix crossgen2 by adding HostArchitecture
sdmaclea Aug 10, 2020
02423a1
Merge branch 'master' into dev/Arm64MacOS
sdmaclea Aug 10, 2020
b80e9c0
Fix typo
sdmaclea Aug 12, 2020
bca94f7
Fix HostArchitecture Condition
sdmaclea Aug 12, 2020
0e7b3c8
Fix libraries native build
sdmaclea Aug 13, 2020
06eef47
Fix typo
sdmaclea Aug 14, 2020
d13d6bc
Reenable FEATURE_WRITEBARRIER_COPY
sdmaclea Aug 14, 2020
0a827d5
Add crude os-arm64 generate layout script
sdmaclea Aug 14, 2020
7d202fa
First Write^Execute patch
sdmaclea Aug 14, 2020
69d14ed
Fix comment typos
sdmaclea Aug 15, 2020
8f678c0
Fix IsRunningOnMojaveHardenedRuntime()
sdmaclea Aug 17, 2020
d8935a7
Add comment
sdmaclea Aug 17, 2020
061ecc4
Set CMAKE_OSX_ARCHITECTURES in configureplatform.cmake
sdmaclea Aug 17, 2020
3c1a830
Fix threadSP initialization order
sdmaclea Aug 20, 2020
cdd5da3
Add PAL_JITWriteEnable()
sdmaclea Aug 20, 2020
59e9888
Fix JIT_WriteBarrier
sdmaclea Aug 20, 2020
7ffe655
Prefer arm_thread_state64_get_*_fptr() form
sdmaclea Aug 20, 2020
e588304
Strip libunwind pointer authentication bits
sdmaclea Aug 20, 2020
c6658cd
Disable RunStartupHooks()
sdmaclea Aug 20, 2020
a051fe7
Remove incorrect consistency check
sdmaclea Aug 20, 2020
7404605
Fix Windows compilation
sdmaclea Aug 21, 2020
7ca8f3e
Set OSX_ARCHITECTURES to fix 41164
sdmaclea Aug 21, 2020
82ff768
Fix Windows compilation+
sdmaclea Aug 21, 2020
757ee92
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Aug 21, 2020
c38cd7c
Add HOST_OSX
sdmaclea Aug 22, 2020
8aa1381
Fix JIT_WriteBarrier_Loc usage
sdmaclea Aug 22, 2020
26ff8a3
Revise generate-osx-arm64-layout.sh
sdmaclea Aug 22, 2020
2564ebd
Reenable RunStartupHooks()
sdmaclea Aug 22, 2020
325d184
Rework CMAKE_OSX_ARCHITECTURES again
sdmaclea Aug 25, 2020
8b4fd1f
Set clang -arch flag
sdmaclea Aug 26, 2020
e48b63b
Remove workarounds from generate-osx-arm64-layout.sh
sdmaclea Aug 26, 2020
1a87f7d
Remove generate-osx-arm64-layout.sh
sdmaclea Aug 26, 2020
79ee527
More CMAKE_OSX_ARCH rework
sdmaclea Aug 26, 2020
9d2d5dd
Handle osx-arm64 uname parsing
sdmaclea Aug 26, 2020
0a89117
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Aug 26, 2020
ab869de
Fix arm64/stubs.cpp W^X
sdmaclea Aug 26, 2020
45788c5
Fix TheUMEntryPrestubWorker
sdmaclea Aug 26, 2020
5440278
Fix GetCapturedRegister
sdmaclea Aug 27, 2020
8015a0c
Revert "Fix TheUMEntryPrestubWorker"
sdmaclea Aug 27, 2020
389c9cb
Fix kRunTimeInited write
sdmaclea Aug 27, 2020
af4db13
Fix more W^X issues
sdmaclea Aug 27, 2020
49eb289
Add/use PAL_JITWriteEnableHolder
sdmaclea Aug 31, 2020
af0d7eb
Restore constistency check
sdmaclea Aug 31, 2020
6677bce
Use fpAddress name
sdmaclea Aug 31, 2020
bf2ae4f
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 1, 2020
6a884d0
Add HAVE_SYSCTLBYNAME to PAL_GetJitCpuCapabilityFlags
sdmaclea Sep 1, 2020
29edb16
Rename SafeUpdateWriteBarrierState
sdmaclea Sep 1, 2020
1747d55
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 1, 2020
012febf
Fix LazyMachState::setLazyStateFromUnwind(...)
sdmaclea Sep 2, 2020
b06e8b3
Flush NONPAL_TRACE messages
sdmaclea Sep 3, 2020
b725312
Fix PAL_JITWriteEnableHolder::JITWriteEnable
sdmaclea Sep 3, 2020
923ecbb
Fix exception handling
sdmaclea Sep 3, 2020
ad5eabc
Fix assertion when crossgen prints an empty string
sdmaclea Sep 3, 2020
7eced9d
Fix EventPipe::InvokeCallback
sdmaclea Sep 3, 2020
d94eba5
Fix GcInfoDecoder::ReportRegisterToGC
sdmaclea Sep 3, 2020
05214ef
Disable JITWrite on Activation
sdmaclea Sep 4, 2020
03af208
Only activate for ESR.EC == SVC
sdmaclea Sep 4, 2020
24532ac
Fix HostCodeHeap::AddToFreeList
sdmaclea Sep 4, 2020
c291613
Fix comment
sdmaclea Sep 4, 2020
60ac6e5
Fix NONPAL_TRACING induced deadlock
sdmaclea Sep 4, 2020
6ba565a
Use MachSetThreadContext for RtlRestoreContext
sdmaclea Sep 5, 2020
7651eb5
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 5, 2020
59682d3
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 8, 2020
80b9126
Revert "Use MachSetThreadContext for RtlRestoreContext"
sdmaclea Sep 8, 2020
62575e2
Use MachSetThreadContext in ActivationHandler
sdmaclea Sep 8, 2020
68a08bf
Remove unnecessary PAL_JITWriteEnable
sdmaclea Sep 8, 2020
1025180
Fix configurecompiler.cmake typo
sdmaclea Sep 8, 2020
44eeb38
Fix foreign thread callbacks to managed code
sdmaclea Sep 9, 2020
ef69659
Fix corehost build
sdmaclea Sep 9, 2020
50c931c
Fix more dllimportcallback W^X issues
sdmaclea Sep 9, 2020
7e525b3
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 9, 2020
93d8866
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 11, 2020
5c725ce
Enable cross-build of coreclr on OSX x64
janvorli Sep 17, 2020
0e61103
Fix JIT bug
janvorli Sep 17, 2020
ef57726
Fix shell build scripts
janvorli Sep 18, 2020
e641d6a
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Sep 21, 2020
9667e8c
Remove stray comment
sdmaclea Sep 21, 2020
c5cee94
Fix SSLSetEnabledCiphers call
sdmaclea Sep 21, 2020
bcdc032
Fix test build script
sdmaclea Sep 22, 2020
260b5dd
Fix x64 cross compile
sdmaclea Sep 24, 2020
271d396
Move remote-unwind to coreclrpal_dac library for Unix
sdmaclea Sep 24, 2020
78d00a2
Disable coreclrpal_dac in cross bit compiles
sdmaclea Sep 28, 2020
fcf3424
Fix Windows build
sdmaclea Sep 29, 2020
e186f01
Fix arm64 crossdac build
sdmaclea Sep 29, 2020
6817c64
Merge remote-tracking branch 'origin/master' into dev/Arm64MacOS
sdmaclea Oct 1, 2020
f9b9fff
Review feedback
sdmaclea Oct 1, 2020
d3e49f0
Add missing semicolon
sdmaclea Oct 6, 2020
0d4eba8
PR Feedback
sdmaclea Oct 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<!-- Used for launchSettings.json and runtime config files. -->
<AppDesignerFolder>Properties</AppDesignerFolder>
<!-- Determine what architecture we are building on. -->
<BuildArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant())</BuildArchitecture>
<BuildArchitecture Condition="'$(BuildArchitecture)' == ''">$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant())</BuildArchitecture>
</PropertyGroup>

<Import Project="$(RepositoryEngineeringDir)Analyzers.props" />
Expand Down
8 changes: 5 additions & 3 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ initDistroRid()
local isCrossBuild="$3"
local isPortableBuild="$4"

# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified.
if (( isCrossBuild == 1 )); then
# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not OSX that doesn't use rootfs
if [[ $isCrossBuild == 1 && "$targetOs" != "OSX" ]]; then
passedRootfsDir=${ROOTFS_DIR}
fi
initDistroRidGlobal ${targetOs} ${buildArch} ${isPortableBuild} ${passedRootfsDir}
Expand All @@ -153,6 +153,8 @@ portableBuild=1

source $scriptroot/native/init-os-and-arch.sh

hostArch=$arch

# Check if an action is passed in
declare -a actions=("b" "build" "r" "restore" "rebuild" "testnobuild" "sign" "publish" "clean")
actInt=($(comm -12 <(printf '%s\n' "${actions[@]/#/-}" | sort) <(printf '%s\n' "${@/#--/-}" | sort)))
Expand Down Expand Up @@ -436,6 +438,6 @@ initDistroRid $os $arch $crossBuild $portableBuild
# URL-encode space (%20) to avoid quoting issues until the msbuild call in /eng/common/tools.sh.
# In *proj files (XML docs), URL-encoded string are rendered in their decoded form.
cmakeargs="${cmakeargs// /%20}"
arguments="$arguments /p:TargetArchitecture=$arch"
arguments="$arguments /p:TargetArchitecture=$arch /p:BuildArchitecture=$hostArch"
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
arguments="$arguments /p:CMakeArgs=\"$cmakeargs\" $extraargs"
"$scriptroot/common/build.sh" $arguments
34 changes: 24 additions & 10 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ initTargetDistroRid()

local passedRootfsDir=""

# Only pass ROOTFS_DIR if cross is specified.
if [[ "$__CrossBuild" == 1 ]]; then
# Only pass ROOTFS_DIR if cross is specified and the target platform is not Darwin that doesn't use rootfs
if [[ "$__CrossBuild" == 1 && "$platform" != "Darwin" ]]; then
passedRootfsDir="$ROOTFS_DIR"
fi

Expand Down Expand Up @@ -68,15 +68,28 @@ check_prereqs()

build_native()
{
platformArch="$1"
cmakeDir="$2"
tryrunDir="$3"
intermediatesDir="$4"
message="$5"
targetOS="$1"
platformArch="$2"
cmakeDir="$3"
tryrunDir="$4"
intermediatesDir="$5"
cmakeArgs="$6"
message="$7"

# All set to commence the build
echo "Commencing build of \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"

if [[ "$targetOS" == OSX ]]; then
if [[ "$platformArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
elif [[ "$platformArch" == arm64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $cmakeArgs"
else
echo "Error: Unknown OSX architecture $platformArch."
exit 1
fi
fi

if [[ "$__UseNinja" == 1 ]]; then
generator="ninja"
buildTool="$(command -v ninja || command -v ninja-build)"
Expand Down Expand Up @@ -134,8 +147,8 @@ EOF
fi

engNativeDir="$__RepoRootDir/eng/native"
__CMakeArgs="-DCLR_ENG_NATIVE_DIR=\"$engNativeDir\" $__CMakeArgs"
nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$cmakeDir\" \"$tryrunDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $__CMakeArgs"
cmakeArgs="-DCLR_ENG_NATIVE_DIR=\"$engNativeDir\" $cmakeArgs"
nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$cmakeDir\" \"$tryrunDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $cmakeArgs"
echo "Invoking $nextCommand"
eval $nextCommand

Expand Down Expand Up @@ -448,7 +461,8 @@ fi
if [[ "$__CrossBuild" == 1 ]]; then
CROSSCOMPILE=1
export CROSSCOMPILE
if [[ ! -n "$ROOTFS_DIR" ]]; then
# Darwin that doesn't use rootfs
if [[ ! -n "$ROOTFS_DIR" && "$platform" != "Darwin" ]]; then
ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch"
export ROOTFS_DIR
fi
Expand Down
12 changes: 11 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ if (CLR_CMAKE_HOST_UNIX)
add_definitions(-DHOST_UNIX)

if(CLR_CMAKE_HOST_OSX)
add_definitions(-DHOST_OSX)
if(CLR_CMAKE_HOST_UNIX_AMD64)
message("Detected OSX x86_64")
elseif(CLR_CMAKE_HOST_UNIX_ARM64)
Expand Down Expand Up @@ -374,7 +375,16 @@ if (CLR_CMAKE_HOST_UNIX)

# Specify the minimum supported version of macOS
if(CLR_CMAKE_HOST_OSX)
set(MACOS_VERSION_MIN_FLAGS -mmacosx-version-min=10.13)
if(CLR_CMAKE_HOST_ARCH_ARM64)
# 'pthread_jit_write_protect_np' is only available on macOS 11.0 or newer
set(MACOS_VERSION_MIN_FLAGS -mmacosx-version-min=11.0)
add_compile_options(-arch arm64)
elseif(CLR_CMAKE_HOST_ARCH_AMD64)
set(MACOS_VERSION_MIN_FLAGS -mmacosx-version-min=10.13)
add_compile_options(-arch x86_64)
else()
clr_unknown_arch()
endif()
add_compile_options(${MACOS_VERSION_MIN_FLAGS})
add_linker_flag(${MACOS_VERSION_MIN_FLAGS})
endif(CLR_CMAKE_HOST_OSX)
Expand Down
4 changes: 2 additions & 2 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ endif(CLR_CMAKE_HOST_OS STREQUAL Linux)
if(CLR_CMAKE_HOST_OS STREQUAL Darwin)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_OSX 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
if(CMAKE_OSX_ARCHITECTURES STREQUAL x86_64)
jkotas marked this conversation as resolved.
Show resolved Hide resolved
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
else()
clr_unknown_arch()
Expand Down
11 changes: 9 additions & 2 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ done

cmake_extra_defines=
if [[ "$CROSSCOMPILE" == "1" ]]; then
if ! [[ -n "$ROOTFS_DIR" ]]; then
platform="$(uname)"
# OSX doesn't use rootfs
if ! [[ -n "$ROOTFS_DIR" || "$platform" == "Darwin" ]]; then
echo "ROOTFS_DIR not set for crosscompile"
exit 1
fi
Expand All @@ -74,7 +76,12 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then
if [[ -n "$tryrun_dir" ]]; then
cmake_extra_defines="$cmake_extra_defines -C $tryrun_dir/tryrun.cmake"
fi
cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake"

if [[ "$platform" == "Darwin" ]]; then
cmake_extra_defines="$cmake_extra_defines -DCMAKE_SYSTEM_NAME=Darwin"
else
cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake"
fi
fi

if [[ "$build_arch" == "armel" ]]; then
Expand Down
11 changes: 11 additions & 0 deletions eng/native/init-os-and-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ if [ "$os" = "SunOS" ]; then
os="Solaris"
fi
CPUName=$(isainfo -n)
elif [ "$os" = "OSX" ]; 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
# For rest of the operating systems, use uname(1) to determine what the CPU is.
CPUName=$(uname -m)
Expand Down
8 changes: 2 additions & 6 deletions src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ build_cross_architecture_components()
export __CMakeBinDir CROSSCOMPILE

__CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CROSS_COMPONENTS_BUILD=1 $__CMakeArgs"
build_native "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "cross-architecture components"
build_native "$__TargetOS" "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "$__CMakeArgs" "cross-architecture components"

CROSSCOMPILE=1
export CROSSCOMPILE
Expand Down Expand Up @@ -198,10 +198,6 @@ __BuildRuntime=1

source "$__ProjectRoot"/_build-commons.sh

if [[ "${__BuildArch}" != "${__HostArch}" ]]; then
__CrossBuild=1
fi

# Set dependent variables

# Set the remaining variables based upon the determined build configuration
Expand Down Expand Up @@ -261,7 +257,7 @@ fi
if [[ "$__SkipNative" == 1 ]]; then
echo "Skipping CoreCLR component build."
else
build_native "$__BuildArch" "$__ProjectRoot" "$__ProjectRoot" "$__IntermediatesDir" "CoreCLR component"
build_native "$__TargetOS" "$__BuildArch" "$__ProjectRoot" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeArgs" "CoreCLR component"

# Build cross-architecture components
if [[ "$__SkipCrossArchNative" != 1 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/crosscomponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (CLR_CMAKE_HOST_OS STREQUAL CLR_CMAKE_TARGET_OS)
endif(CLR_CMAKE_TARGET_UNIX)
endif()

if(NOT CLR_CMAKE_HOST_LINUX AND NOT FEATURE_CROSSBITNESS)
if(NOT CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_OSX AND NOT FEATURE_CROSSBITNESS)
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
list (APPEND CLR_CROSS_COMPONENTS_LIST
mscordaccore
mscordbi
Expand Down
20 changes: 20 additions & 0 deletions src/coreclr/src/debug/createdump/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct elf64_note {
Elf64_Word n_type; /* Content type */
} Elf64_Nhdr;

#if defined(TARGET_AMD64)
struct user_fpregs_struct
{
unsigned short int cwd;
Expand Down Expand Up @@ -113,6 +114,25 @@ struct user_regs_struct
unsigned long long int fs;
unsigned long long int gs;
};
#elif defined(TARGET_ARM64)
struct user_fpsimd_struct
{
uint64_t vregs[2*32];
uint32_t fpcr;
uint32_t fpsr;
};

struct user_regs_struct
{
uint64_t regs[31];
uint64_t sp;
uint64_t pc;
uint32_t pstate;
};
#else
#error Unexpected architecture
#endif


typedef pid_t __pid_t;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/debug/createdump/memoryregion.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if defined(__arm__) || defined(__aarch64__)
#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__))
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
#endif

Expand Down
33 changes: 33 additions & 0 deletions src/coreclr/src/debug/createdump/threadinfomac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ThreadInfo::Initialize()
m_ppid = 0;
m_tgid = 0;

#if defined(TARGET_AMD64)
x86_thread_state64_t state;
mach_msg_type_number_t stateCount = x86_THREAD_STATE64_COUNT;
kern_return_t result = ::thread_get_state(Port(), x86_THREAD_STATE64, (thread_state_t)&state, &stateCount);
Expand Down Expand Up @@ -88,6 +89,38 @@ ThreadInfo::Initialize()

memcpy(m_fpRegisters.st_space, &fpstate.__fpu_stmm0, sizeof(m_fpRegisters.st_space));
memcpy(m_fpRegisters.xmm_space, &fpstate.__fpu_xmm0, sizeof(m_fpRegisters.xmm_space));
#elif defined(TARGET_ARM64)
arm_thread_state64_t state;
mach_msg_type_number_t stateCount = ARM_THREAD_STATE64_COUNT;
kern_return_t result = ::thread_get_state(Port(), ARM_THREAD_STATE64, (thread_state_t)&state, &stateCount);
if (result != KERN_SUCCESS)
{
fprintf(stderr, "thread_get_state(%x) FAILED %x %s\n", m_tid, result, mach_error_string(result));
return false;
}

memcpy(m_gpRegisters.regs, &state.__x, sizeof(state.__x));
m_gpRegisters.regs[29] = arm_thread_state64_get_fp(state);
m_gpRegisters.regs[30] = (uint64_t)arm_thread_state64_get_lr_fptr(state);

m_gpRegisters.sp = arm_thread_state64_get_sp(state);
m_gpRegisters.pc = (uint64_t)arm_thread_state64_get_pc_fptr(state);

arm_neon_state64_t fpstate;
stateCount = ARM_NEON_STATE64_COUNT;
result = ::thread_get_state(Port(), ARM_NEON_STATE64, (thread_state_t)&fpstate, &stateCount);
if (result != KERN_SUCCESS)
{
fprintf(stderr, "thread_get_state(%x) FAILED %x %s\n", m_tid, result, mach_error_string(result));
return false;
}

memcpy(m_fpRegisters.vregs, &fpstate.__v, sizeof(m_fpRegisters.vregs));
m_fpRegisters.fpsr = fpstate.__fpsr;
m_fpRegisters.fpcr = fpstate.__fpcr;
#else
#error Unexpected architecture
#endif

return true;
}
4 changes: 2 additions & 2 deletions src/coreclr/src/debug/ee/arm64/dbghelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NESTED_ENTRY FuncEvalHijack, _TEXT, UnhandledExceptionHandlerUnix
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -32
str x0, [sp, #16]
// FuncEvalHijackWorker returns the address we should jump to.
bl FuncEvalHijackWorker
bl C_FUNC(FuncEvalHijackWorker)

EPILOG_STACK_FREE 32
EPILOG_BRANCH_REG x0
Expand All @@ -33,7 +33,7 @@ NESTED_END FuncEvalHijack
NESTED_ENTRY ExceptionHijack, _TEXT, UnhandledExceptionHandlerUnix

// make the call
bl ExceptionHijackWorker
bl C_FUNC(ExceptionHijackWorker)

// effective NOP to terminate unwind
mov x3, x3
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ if(CLR_CMAKE_HOST_WIN32 AND CLR_CMAKE_TARGET_UNIX)
)
endif(CLR_CMAKE_HOST_WIN32 AND CLR_CMAKE_TARGET_UNIX)

if(CLR_CMAKE_HOST_OSX)
if(CLR_CMAKE_HOST_UNIX)
list(APPEND COREDAC_LIBRARIES
coreclrpal_dac
)
endif(CLR_CMAKE_HOST_OSX)
endif(CLR_CMAKE_HOST_UNIX)

target_link_libraries(mscordaccore PRIVATE ${COREDAC_LIBRARIES})

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/gc/unix/config.gc.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#cmakedefine01 HAVE_SWAPCTL
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
#cmakedefine01 HAVE_MACH_ABSOLUTE_TIME
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 HAVE_SCHED_GETAFFINITY
#cmakedefine01 HAVE_SCHED_SETAFFINITY
#cmakedefine01 HAVE_PTHREAD_SETAFFINITY_NP
Expand Down
20 changes: 9 additions & 11 deletions src/coreclr/src/gc/unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ check_cxx_source_runs("
check_library_exists(pthread pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK)

check_cxx_source_runs("
#include <stdlib.h>
#include <mach/mach_time.h>
int main()
{
int ret;
mach_timebase_info_data_t timebaseInfo;
ret = mach_timebase_info(&timebaseInfo);
mach_absolute_time();
exit(ret);
}
" HAVE_MACH_ABSOLUTE_TIME)
#include <stdlib.h>
#include <time.h>

int main()
{
int ret;
ret = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - what was wrong with mach_absolute_time ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't exist on aarch64 and Apple doc for mach_absolute_time recommends to replace it with clock_gettime_nsec_np

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed that HAVE_MACH_ABSOLUTE_TIME is still used under libraries. Do we need to fix it there as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the strange thing is that libraries compile for arm64 with it just fine. So maybe the failure due to which I've modified the usage of mach_absolute_time to clock_gettime_nsec_np was something temporary in the middle of the fixes I was making. Anyways, the change is good since the mach_absolute_time is deprecated, so we should change it in the libraries too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, opened #43320

exit((ret == 0) ? 1 : 0);
}" HAVE_CLOCK_GETTIME_NSEC_NP)


check_library_exists(c sched_getaffinity "" HAVE_SCHED_GETAFFINITY)
Expand Down
Loading