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 1 commit
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
21 changes: 5 additions & 16 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,12 @@ 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(CLR_CROSS_COMPONENTS_BUILD)
# CMAKE_HOST_SYSTEM_PROCESSOR returns the value of `uname -p` on host.
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
else()
clr_unknown_arch()
endif()
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_OSX_ARCHITECTURES STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
else()
if(CMAKE_OSX_ARCHITECTURES STREQUAL x86_64)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
else()
clr_unknown_arch()
endif()
clr_unknown_arch()
endif()
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CLR_CMAKE_HOST_OS STREQUAL Darwin)
Expand Down
18 changes: 17 additions & 1 deletion src/coreclr/src/pal/src/exception/machexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,22 @@ extern "C" void ActivationHandlerWrapper();
extern "C" int ActivationHandlerReturnOffset;
extern "C" unsigned int XmmYmmStateSupport();

#ifdef HOST_ARM64
bool isHardwareException(uint64_t esr)
sdmaclea marked this conversation as resolved.
Show resolved Hide resolved
{
// Infer exception state from the ESR_EL* register value.
// Bits 31-26 represent the ESR.EC field
const int ESR_EC_SHIFT = 26;
const int ESR_EC_MASK = 0x3f;
const int esr_ec = (esr >> ESR_EC_SHIFT) & ESR_EC_MASK;

const int ESR_EC_SVC = 0x15; // Supervisor Call exception from aarch64.

// Assume only supervisor calls from aarch64 are not hardware exceptions
return (esr_ec != ESR_EC_SVC)
}
#endif

/*++
Function :
InjectActivationInternal
Expand Down Expand Up @@ -1497,7 +1513,7 @@ InjectActivationInternal(CPalThread* pThread)
#elif defined(HOST_ARM64)
// Inject the activation only if the last ESR.EC was an SVC and therefore the thread doesn't have
// a pending hardware exception
if ((ExceptionState.__esr >> 26) == 0x15)
if (!isHardwareException(ExceptionState.__esr))
#else
#error Unexpected architecture
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/pal/src/exception/machmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ using namespace CorUnix;

// Debug-only output with printf-style formatting.
#define NONPAL_TRACE(_format, ...) do { \
if (NONPAL_TRACE_ENABLED) { printf("NONPAL_TRACE: " _format, ## __VA_ARGS__); fflush(stdout); } \
if (NONPAL_TRACE_ENABLED) printf("NONPAL_TRACE: " _format, ## __VA_ARGS__); \
} while (false)

#else // _DEBUG
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/src/pal/src/libunwind_mac/src/missing-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ unw_get_accessors_int (unw_addr_space_t as)
return unw_get_accessors(as);
}

#if defined(TARGET_AMD64) && !defined(HOST_AMD64)
#define X86_64_SCF_NONE 0
#endif

#if defined(TARGET_ARM64) && !defined(HOST_ARM64)
#define AARCH64_SCF_NONE 0
#endif

int
unw_is_signal_frame (unw_cursor_t *cursor)
{
struct cursor *c = (struct cursor *) cursor;
#ifdef HOST_AMD64
#ifdef TARGET_AMD64
return c->sigcontext_format != X86_64_SCF_NONE;
#elif defined(HOST_ARM64)
#elif defined(TARGET_ARM64)
return c->sigcontext_format != AARCH64_SCF_NONE;
#else
#error Unexpected target
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/src/vm/arm64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ void JIT_TailCall()
#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
EXTERN_C void JIT_UpdateWriteBarrierState(bool skipEphemeralCheck);

static void UpdateWriteBarrierState (bool skipEphemeralCheck)
static void UpdateWriteBarrierState(bool skipEphemeralCheck)
{
#if defined(HOST_OSX) && defined(HOST_ARM64)
auto jitWriteEnableHolder = PAL_JITWriteEnable(true);
Expand Down Expand Up @@ -1104,12 +1104,12 @@ void InitJITHelpers1()
}
}

UpdateWriteBarrierState (GCHeapUtilities::IsServerHeap());
UpdateWriteBarrierState(GCHeapUtilities::IsServerHeap());
}


#else
void UpdateWriteBarrierState (bool) {}
void UpdateWriteBarrierState(bool) {}
#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)

PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext)
Expand Down Expand Up @@ -1278,26 +1278,26 @@ void FlushWriteBarrierInstructionCache()
#ifndef CROSSGEN_COMPILE
int StompWriteBarrierEphemeral(bool isRuntimeSuspended)
{
UpdateWriteBarrierState (GCHeapUtilities::IsServerHeap());
UpdateWriteBarrierState(GCHeapUtilities::IsServerHeap());
return SWB_PASS;
}

int StompWriteBarrierResize(bool isRuntimeSuspended, bool bReqUpperBoundsCheck)
{
UpdateWriteBarrierState (GCHeapUtilities::IsServerHeap());
UpdateWriteBarrierState(GCHeapUtilities::IsServerHeap());
return SWB_PASS;
}

#ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
int SwitchToWriteWatchBarrier(bool isRuntimeSuspended)
{
UpdateWriteBarrierState (GCHeapUtilities::IsServerHeap());
UpdateWriteBarrierState(GCHeapUtilities::IsServerHeap());
return SWB_PASS;
}

int SwitchToNonWriteWatchBarrier(bool isRuntimeSuspended)
{
UpdateWriteBarrierState (GCHeapUtilities::IsServerHeap());
UpdateWriteBarrierState(GCHeapUtilities::IsServerHeap());
return SWB_PASS;
}
#endif // FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/vm/gcinfodecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,11 +1709,11 @@ OBJECTREF* GcInfoDecoder::GetCapturedRegister(
_ASSERTE(regNum >= 0 && regNum <= 30);
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear to me why should this be different from Linux. The CONTEXT should be the same for ARM64 no matter what the platform is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I am not sure here....
In the debugger, the pRD->pCurrentContextPointers->Fp was null so get stack slot forwarded here. The code didn't support that case, so the assert made sense.

In the case I was observing, the pRD->pCurrentContext->Fp looked valid, so it seemed reasonable and harmless to support it here.

However, this did not fix any of the tests hitting this assert.... So perhaps another fix is needed... This still seemed functionally correct to me, so I committed it anyway (at least to trigger discussion). If you know why we should never have to support this case, it might help me find the true root cause of the issue....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Root cause. For MacOS HAVE_UNW_GET_SAVE_LOC is not defined. This is because macos libunwind.h has this.

//extern int       unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);

_ASSERTE(regNum != 18);

if(regNum == 29)
if (regNum == 29)
{
return (OBJECTREF*) &pRD->pCurrentContext->Fp;
}
else if(regNum == 30)
else if (regNum == 30)
{
return (OBJECTREF*) &pRD->pCurrentContext->Lr;
}
Expand Down