diff --git a/docs/workflow/building/coreclr/ios.md b/docs/workflow/building/coreclr/ios.md
new file mode 100644
index 0000000000000..9061fd17da438
--- /dev/null
+++ b/docs/workflow/building/coreclr/ios.md
@@ -0,0 +1,33 @@
+# Cross Compilation for iOS Simulator on macOS
+
+## Requirements
+
+Build requirements are the same as for building native CoreCLR on macOS. iPhone SDK has to be enabled in Xcode installation.
+
+## Cross compiling CoreCLR
+
+Build the runtime pack and tools with
+
+```
+./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
+```
+
+## Running the sample iOS app
+
+Build and run the sample app with
+
+```
+./dotnet.sh publish src/mono/sample/iOS/Program.csproj -c Release /p:TargetOS=iossimulator /p:TargetArchitecture=arm64 /p:DeployAndRun=true /p:UseMonoRuntime=false /p:RunAOTCompilation=false /p:MonoForceInterpreter=false
+```
+
+The command also produces an XCode project that can be opened with `open ./src/mono/sample/iOS/bin/iossimulator-arm64/Bundle/HelloiOS/HelloiOS.xcodeproj` and debugged in Xcode.
+
+## Running the runtime tests
+
+Build the runtime tests with
+
+```
+./src/tests/build.sh -os iossimulator arm64 Release -p:UseMonoRuntime=false
+```
+
+Running the tests is not implemented yet. It will likely need similar app bundle infrastructure as NativeAOT/iOS uses.
\ No newline at end of file
diff --git a/eng/Subsets.props b/eng/Subsets.props
index 6e511f716b6fb..05ca78de1b3c3 100644
--- a/eng/Subsets.props
+++ b/eng/Subsets.props
@@ -57,8 +57,8 @@
- Mono
- CoreCLR
+ CoreCLR
+ Mono
Mono
$(PrimaryRuntimeFlavor)
@@ -67,7 +67,7 @@
clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools+host.native
clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools
- clr.iltools+clr.packages
+ clr.iltools+clr.packages
clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime
diff --git a/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj b/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj
index b2945e2926015..0480327017db5 100644
--- a/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj
+++ b/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj
@@ -11,7 +11,7 @@
-
+
\lib\netstandard2.0\
diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt
index 107859ec58dc5..bc093f7270ccd 100644
--- a/src/coreclr/CMakeLists.txt
+++ b/src/coreclr/CMakeLists.txt
@@ -29,7 +29,7 @@ if(CORECLR_SET_RPATH)
set(MACOSX_RPATH ON)
endif(CORECLR_SET_RPATH)
-if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS)
+if(CLR_CMAKE_HOST_TVOS)
set(FEATURE_STANDALONE_GC 0)
endif()
@@ -59,7 +59,7 @@ include(components.cmake)
#---------------------------
# Build the single file host
#---------------------------
-if(NOT CLR_CROSS_COMPONENTS_BUILD)
+if(NOT CLR_CROSS_COMPONENTS_BUILD AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS)
set(CLR_SINGLE_FILE_HOST_ONLY 1)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static)
add_dependencies(runtime singlefilehost)
@@ -101,8 +101,10 @@ if(CLR_CMAKE_HOST_UNIX)
add_linker_flag(-Wl,-z,notext)
endif()
- if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
+ if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(pal)
+ endif()
+ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(hosts)
endif()
else()
@@ -129,7 +131,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)
-if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
+if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(debug/debug-pal)
endif()
@@ -246,7 +248,7 @@ if(CLR_CMAKE_HOST_UNIX)
add_subdirectory(nativeresources)
endif(CLR_CMAKE_HOST_UNIX)
-if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
+if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(utilcode)
add_subdirectory(inc)
@@ -260,15 +262,18 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H
add_subdirectory(binder)
add_subdirectory(classlibnative)
add_subdirectory(dlls)
- add_subdirectory(tools)
add_subdirectory(unwinder)
add_subdirectory(interop)
+endif()
- if(CLR_CMAKE_HOST_WIN32)
- add_subdirectory(hosts)
- endif(CLR_CMAKE_HOST_WIN32)
+if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
+ add_subdirectory(tools)
endif(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
+if(CLR_CMAKE_HOST_WIN32)
+ add_subdirectory(hosts)
+endif(CLR_CMAKE_HOST_WIN32)
+
#----------------------------------------------------
# Cross target Component install configuration
#----------------------------------------------------
diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt
index 9ed71521d4283..fa26f55cc37fa 100644
--- a/src/coreclr/debug/daccess/CMakeLists.txt
+++ b/src/coreclr/debug/daccess/CMakeLists.txt
@@ -47,10 +47,10 @@ target_link_libraries(daccess PRIVATE cdacreader_api)
add_dependencies(daccess eventing_headers)
-if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS)
+if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE)
add_definitions(-DUSE_DAC_TABLE_RVA)
- set(args $<$>:--dynamic> $ ${GENERATED_INCLUDE_DIR}/dactablerva.h)
+ set(args $<$>:--dynamic> $ ${GENERATED_INCLUDE_DIR}/dactablerva.h)
add_custom_command(
OUTPUT ${GENERATED_INCLUDE_DIR}/dactablerva.h
@@ -72,4 +72,4 @@ if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS)
)
add_dependencies(daccess dactablerva_header)
-endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS)
+endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE)
diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt
index ef91243448c51..2b33054129d62 100644
--- a/src/coreclr/dlls/mscordac/CMakeLists.txt
+++ b/src/coreclr/dlls/mscordac/CMakeLists.txt
@@ -31,9 +31,9 @@ else(CLR_CMAKE_HOST_WIN32)
# Add dependency on export file
add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE})
- if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU)
+ if(CLR_CMAKE_HOST_APPLE OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU)
generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE})
- endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU)
+ endif(CLR_CMAKE_HOST_APPLE OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU)
if(CORECLR_SET_RPATH AND CLR_CMAKE_HOST_OSX AND CLR_CMAKE_HOST_ARCH_ARM64)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
index 6dd42fe2b2538..2ee4c08e26f67 100644
--- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
+++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
@@ -228,6 +228,9 @@ endif(CLR_CMAKE_TARGET_WIN32)
# add the install targets
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
+if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
+ install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
+endif()
# Enable profile guided optimization
add_pgo(coreclr)
diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h
index 01eeac600a224..8c85a1b5276ba 100644
--- a/src/coreclr/hosts/inc/coreclrhost.h
+++ b/src/coreclr/hosts/inc/coreclrhost.h
@@ -14,13 +14,19 @@
#define CORECLR_CALLING_CONVENTION
#endif
+#ifdef __cplusplus
+#define CORECLR_HOSTING_API_LINKAGE extern "C"
+#else
+#define CORECLR_HOSTING_API_LINKAGE
+#endif
+
#include
// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
- extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
+ CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
//
diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h
index 50867accca1ac..496d1c0247533 100644
--- a/src/coreclr/inc/crosscomp.h
+++ b/src/coreclr/inc/crosscomp.h
@@ -17,7 +17,7 @@
#define MAKE_TARGET_DLLNAME_W(name) name W(".dll")
#define MAKE_TARGET_DLLNAME_A(name) name ".dll"
#else // TARGET_WINDOWS
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
#define MAKE_TARGET_DLLNAME_W(name) W("lib") name W(".dylib")
#define MAKE_TARGET_DLLNAME_A(name) "lib" name ".dylib"
#else
@@ -686,9 +686,9 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
#if defined(TARGET_OSX) && defined(TARGET_X86)
#define DAC_CS_NATIVE_DATA_SIZE 76
-#elif defined(TARGET_OSX) && defined(TARGET_AMD64)
+#elif defined(TARGET_APPLE) && defined(TARGET_AMD64)
#define DAC_CS_NATIVE_DATA_SIZE 120
-#elif defined(TARGET_OSX) && defined(TARGET_ARM64)
+#elif defined(TARGET_APPLE) && defined(TARGET_ARM64)
#define DAC_CS_NATIVE_DATA_SIZE 120
#elif defined(TARGET_FREEBSD) && defined(TARGET_X86)
#define DAC_CS_NATIVE_DATA_SIZE 12
diff --git a/src/coreclr/inc/executableallocator.h b/src/coreclr/inc/executableallocator.h
index 5b9c0d81dc5a2..11caf3a6857d2 100644
--- a/src/coreclr/inc/executableallocator.h
+++ b/src/coreclr/inc/executableallocator.h
@@ -285,7 +285,7 @@ class ExecutableWriterHolder
void Unmap()
{
-#if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
+#if defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
if (m_addressRX != NULL)
{
PAL_JitWriteProtect(false);
@@ -321,7 +321,7 @@ class ExecutableWriterHolder
ExecutableWriterHolder(T* addressRX, size_t size, ExecutableAllocator::CacheableMapping cacheMapping = ExecutableAllocator::AddToCache)
{
m_addressRX = addressRX;
-#if defined(HOST_OSX) && defined(HOST_ARM64)
+#if defined(HOST_APPLE) && defined(HOST_ARM64)
m_addressRW = addressRX;
PAL_JitWriteProtect(true);
#else
diff --git a/src/coreclr/inc/targetosarch.h b/src/coreclr/inc/targetosarch.h
index 06f22d8ee487b..00fe5b70647e7 100644
--- a/src/coreclr/inc/targetosarch.h
+++ b/src/coreclr/inc/targetosarch.h
@@ -22,7 +22,7 @@ class TargetOS
static bool OSSettingConfigured;
static bool IsApplePlatform;
#else
-#if defined(TARGET_OSX)
+#if defined(TARGET_APPLE)
static const bool IsApplePlatform = true;
#else
static const bool IsApplePlatform = false;
diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt
index 104a7be7f1820..c936b65a4a83c 100644
--- a/src/coreclr/jit/CMakeLists.txt
+++ b/src/coreclr/jit/CMakeLists.txt
@@ -624,7 +624,7 @@ set(JIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Creates a static library "clrjit_static" to link into the VM.
add_subdirectory(static)
-if (CLR_CMAKE_TARGET_OSX)
+if (CLR_CMAKE_TARGET_APPLE)
set(TARGET_OS_NAME unix_osx)
elseif (CLR_CMAKE_TARGET_UNIX)
set(TARGET_OS_NAME unix)
diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp
index ba43e72a0c673..35879fdc6b5ce 100644
--- a/src/coreclr/minipal/Unix/doublemapping.cpp
+++ b/src/coreclr/minipal/Unix/doublemapping.cpp
@@ -22,11 +22,11 @@
#include "minipal.h"
#include "minipal/cpufeatures.h"
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
#include
-#else // TARGET_OSX
+#else // TARGET_APPLE
#ifdef TARGET_64BIT
static const off_t MaxDoubleMappedSize = 2048ULL*1024*1024*1024;
@@ -34,7 +34,7 @@ static const off_t MaxDoubleMappedSize = 2048ULL*1024*1024*1024;
static const off_t MaxDoubleMappedSize = UINT_MAX;
#endif
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecutableCodeSize)
{
@@ -44,7 +44,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
return false;
}
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
#ifdef TARGET_FREEBSD
int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU);
@@ -78,25 +78,25 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
*pMaxExecutableCodeSize = MaxDoubleMappedSize;
*pHandle = (void*)(size_t)fd;
-#else // !TARGET_OSX
+#else // !TARGET_APPLE
*pMaxExecutableCodeSize = SIZE_MAX;
*pHandle = NULL;
-#endif // !TARGET_OSX
+#endif // !TARGET_APPLE
return true;
}
void VMToOSInterface::DestroyDoubleMemoryMapper(void *mapperHandle)
{
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
close((int)(size_t)mapperHandle);
#endif
}
extern "C" void* PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(const void* lpBeginAddress, const void* lpEndAddress, size_t dwSize, int fStoreAllocationInfo);
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
bool IsMapJitFlagNeeded()
{
static volatile int isMapJitFlagNeeded = -1;
@@ -127,7 +127,7 @@ bool IsMapJitFlagNeeded()
return (bool)isMapJitFlagNeeded;
}
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offset, size_t size, const void *rangeStart, const void* rangeEnd)
{
@@ -141,7 +141,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs
}
void* result = PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(rangeStart, rangeEnd, size, 0 /* fStoreAllocationInfo */);
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
int mmapFlags = MAP_SHARED;
#ifdef TARGET_HAIKU
mmapFlags |= MAP_NORESERVE;
@@ -156,7 +156,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs
result = NULL;
}
}
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
// For requests with limited range, don't try to fall back to reserving at any address
if ((result != NULL) || !isUnlimitedRange)
@@ -164,7 +164,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs
return result;
}
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
result = mmap(NULL, size, PROT_NONE, mmapFlags, fd, offset);
#else
int mmapFlags = MAP_ANON | MAP_PRIVATE;
@@ -194,20 +194,20 @@ void *VMToOSInterface::CommitDoubleMappedMemory(void* pStart, size_t size, bool
bool VMToOSInterface::ReleaseDoubleMappedMemory(void *mapperHandle, void* pStart, size_t offset, size_t size)
{
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
int fd = (int)(size_t)mapperHandle;
if (mmap(pStart, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset) == MAP_FAILED)
{
return false;
}
memset(pStart, 0, size);
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
return munmap(pStart, size) != -1;
}
void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t offset, size_t size)
{
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
int fd = (int)(size_t)mapperHandle;
void* result = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
if (result == MAP_FAILED)
@@ -215,7 +215,7 @@ void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t off
result = NULL;
}
return result;
-#else // TARGET_OSX
+#else // TARGET_APPLE
#ifdef TARGET_AMD64
vm_address_t startRW;
vm_prot_t curProtection, maxProtection;
@@ -240,7 +240,7 @@ void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t off
assert(false);
return NULL;
#endif // TARGET_AMD64
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
}
bool VMToOSInterface::ReleaseRWMapping(void* pStart, size_t size)
diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h
index 032b888863ef8..fdeba4572e469 100644
--- a/src/coreclr/pal/inc/pal.h
+++ b/src/coreclr/pal/inc/pal.h
@@ -2871,14 +2871,14 @@ VirtualFree(
IN DWORD dwFreeType);
-#if defined(HOST_OSX) && defined(HOST_ARM64)
+#if defined(HOST_APPLE) && defined(HOST_ARM64)
PALIMPORT
VOID
PALAPI
PAL_JitWriteProtect(bool writeEnable);
-#endif // defined(HOST_OSX) && defined(HOST_ARM64)
+#endif // defined(HOST_APPLE) && defined(HOST_ARM64)
PALIMPORT
diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt
index 07c81a0661352..a46316b56413e 100644
--- a/src/coreclr/pal/src/CMakeLists.txt
+++ b/src/coreclr/pal/src/CMakeLists.txt
@@ -1,8 +1,8 @@
-if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU)
+if(CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU)
# On OSX and *BSD, we use the libunwind that's part of the OS
# On Haiku, we used a special port of libunwind
set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1)
-endif(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU)
+endif(CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU)
if(NOT DEFINED ENV{ROOTFS_DIR})
include_directories(SYSTEM /usr/local/include)
@@ -17,7 +17,7 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
include_directories(${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind/include/tdep)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/external/libunwind_extras ${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind)
-elseif(NOT CLR_CMAKE_TARGET_OSX)
+elseif(NOT CLR_CMAKE_TARGET_APPLE)
find_unwind_libs(UNWIND_LIBS)
else()
add_subdirectory(${CLR_SRC_NATIVE_DIR}/external/libunwind_extras ${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind)
@@ -70,13 +70,16 @@ if(CLR_CMAKE_TARGET_OSX)
if(CLR_CMAKE_HOST_ARCH_AMD64)
add_definitions(-DXSTATE_SUPPORTED)
endif()
+endif()
+
+if(CLR_CMAKE_TARGET_APPLE)
set(PLATFORM_SOURCES
arch/${PAL_ARCH_SOURCES_DIR}/context.S
arch/${PAL_ARCH_SOURCES_DIR}/dispatchexceptionwrapper.S
exception/machexception.cpp
exception/machmessage.cpp
)
-endif(CLR_CMAKE_TARGET_OSX)
+endif(CLR_CMAKE_TARGET_APPLE)
if (FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
add_definitions(-DFEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
@@ -116,12 +119,12 @@ set(ARCH_SOURCES
arch/${PAL_ARCH_SOURCES_DIR}/exceptionhelper.S
)
-if(NOT CLR_CMAKE_TARGET_OSX)
+if(NOT CLR_CMAKE_TARGET_APPLE)
list(APPEND PLATFORM_SOURCES
arch/${PAL_ARCH_SOURCES_DIR}/callsignalhandlerwrapper.S
arch/${PAL_ARCH_SOURCES_DIR}/signalhandlerhelper.cpp
)
-endif(NOT CLR_CMAKE_TARGET_OSX)
+endif(NOT CLR_CMAKE_TARGET_APPLE)
if(CLR_CMAKE_HOST_ARCH_ARM)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -220,7 +223,7 @@ add_library(coreclrpal
)
# Build separate pal library for DAC (addition to regular pal library)
-if(CLR_CMAKE_TARGET_OSX)
+if(CLR_CMAKE_TARGET_APPLE)
set(LIBUNWIND_DAC_OBJECTS $)
add_library(coreclrpal_dac STATIC
@@ -242,7 +245,7 @@ else()
exception/remote-unwind.cpp
)
endif(NOT FEATURE_CROSSBITNESS)
-endif(CLR_CMAKE_TARGET_OSX)
+endif(CLR_CMAKE_TARGET_APPLE)
# There is only one function exported in 'tracepointprovider.cpp' namely 'PAL_InitializeTracing',
# which is guarded with '#if defined(__linux__)'. On macOS, Xcode issues the following warning:
diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake
index 8dd44c550ba5d..db41cc5f6a0f6 100644
--- a/src/coreclr/pal/src/configure.cmake
+++ b/src/coreclr/pal/src/configure.cmake
@@ -14,7 +14,7 @@ elseif(CLR_CMAKE_TARGET_SUNOS)
set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
endif()
-if(CLR_CMAKE_TARGET_OSX)
+if(CLR_CMAKE_TARGET_APPLE)
set(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE)
elseif(NOT CLR_CMAKE_TARGET_FREEBSD AND NOT CLR_CMAKE_TARGET_NETBSD)
set(CMAKE_REQUIRED_DEFINITIONS "-D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L")
@@ -904,7 +904,7 @@ if(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64)
set(CMAKE_REQUIRED_LIBRARIES)
endif()
-if(CLR_CMAKE_TARGET_OSX)
+if(CLR_CMAKE_TARGET_APPLE)
set(HAVE__NSGETENVIRON 1)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
@@ -943,7 +943,7 @@ else() # Anything else is Linux
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (void*)(addr), (data))")
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)
-endif(CLR_CMAKE_TARGET_OSX)
+endif(CLR_CMAKE_TARGET_APPLE)
check_struct_has_member(
"struct statfs"
diff --git a/src/coreclr/pal/src/debug/debug.cpp b/src/coreclr/pal/src/debug/debug.cpp
index 8783ff4860321..5f598a65494bb 100644
--- a/src/coreclr/pal/src/debug/debug.cpp
+++ b/src/coreclr/pal/src/debug/debug.cpp
@@ -60,7 +60,9 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do
#ifdef __APPLE__
#include
+#if defined(TARGET_OSX)
#include
+#endif
#endif // __APPLE__
#if HAVE_MACH_EXCEPTIONS
diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp
index 71e94f929cf33..1100c3159159c 100644
--- a/src/coreclr/pal/src/exception/seh-unwind.cpp
+++ b/src/coreclr/pal/src/exception/seh-unwind.cpp
@@ -44,7 +44,7 @@ Module Name:
#endif // HOST_UNIX
-#if defined(TARGET_OSX) && defined(HOST_ARM64) && !defined(HAVE_UNW_AARCH64_X19)
+#if defined(__APPLE__) && defined(HOST_ARM64) && !defined(HAVE_UNW_AARCH64_X19)
// MacOS uses ARM64 instead of AARCH64 to describe these registers
// Create aliases to reuse more code
enum
@@ -86,7 +86,7 @@ enum
UNW_AARCH64_V30 = UNW_ARM64_D30,
UNW_AARCH64_V31 = UNW_ARM64_D31
};
-#endif // defined(TARGET_OSX) && defined(HOST_ARM64)
+#endif // defined(__APPLE__) && defined(HOST_ARM64)
//----------------------------------------------------------------------
@@ -260,7 +260,7 @@ static void WinContextToUnwindContext(CONTEXT *winContext, unw_context_t *unwCon
{
unwContext->fpregs[i] = winContext->D[i];
}
-#elif defined(HOST_ARM64) && !defined(TARGET_OSX)
+#elif defined(HOST_ARM64) && !defined(__APPLE__)
unwContext->uc_mcontext.pc = winContext->Pc;
unwContext->uc_mcontext.sp = winContext->Sp;
unwContext->uc_mcontext.regs[29] = winContext->Fp;
@@ -302,7 +302,7 @@ static void WinContextToUnwindCursor(CONTEXT *winContext, unw_cursor_t *cursor)
unw_set_reg(cursor, UNW_X86_EBX, winContext->Ebx);
unw_set_reg(cursor, UNW_X86_ESI, winContext->Esi);
unw_set_reg(cursor, UNW_X86_EDI, winContext->Edi);
-#elif defined(HOST_ARM64) && defined(TARGET_OSX)
+#elif defined(HOST_ARM64) && defined(__APPLE__)
// unw_cursor_t is an opaque data structure on macOS
// As noted in WinContextToUnwindContext this didn't work for Linux
// TBD whether this will work for macOS.
@@ -426,12 +426,12 @@ void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_fpreg(cursor, UNW_AARCH64_V30, (unw_fpreg_t*)&winContext->V[30].Low);
unw_get_fpreg(cursor, UNW_AARCH64_V31, (unw_fpreg_t*)&winContext->V[31].Low);
-#if defined(TARGET_OSX) && defined(TARGET_ARM64)
+#if defined(__APPLE__) && defined(TARGET_ARM64)
// Strip pointer authentication bits which seem to be leaking out of libunwind
// Seems like ptrauth_strip() / __builtin_ptrauth_strip() should work, but currently
// errors with "this target does not support pointer authentication"
winContext->Pc = winContext->Pc & 0x7fffffffffffull;
-#endif // defined(TARGET_OSX) && defined(TARGET_ARM64)
+#endif // defined(__APPLE__) && defined(TARGET_ARM64)
#elif (defined(HOST_UNIX) && defined(HOST_S390X))
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->R15);
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->PSWAddr);
diff --git a/src/coreclr/pal/src/include/pal/context.h b/src/coreclr/pal/src/include/pal/context.h
index 5d515a1434e00..40f0e9b88990d 100644
--- a/src/coreclr/pal/src/include/pal/context.h
+++ b/src/coreclr/pal/src/include/pal/context.h
@@ -63,7 +63,7 @@ bool Xstate_IsAvx512Supported();
bool Xstate_IsApxSupported();
#endif // XSTATE_SUPPORTED || (HOST_AMD64 && HAVE_MACH_EXCEPTIONS)
-#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(TARGET_OSX)
+#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(__APPLE__)
#if !defined(SVE_MAGIC)
// Add the missing SVE defines
@@ -145,7 +145,7 @@ struct sve_context {
(SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq))
#endif // SVE_MAGIC
-#endif // HOST_64BIT && HOST_ARM64 && !TARGET_FREEBSD && !TARGET_OSX
+#endif // HOST_64BIT && HOST_ARM64 && !TARGET_FREEBSD && !__APPLE__
#ifdef HOST_S390X
@@ -740,7 +740,7 @@ const struct fpregs* GetConstNativeSigSimdContext(const native_context_t *mc)
return GetNativeSigSimdContext(const_cast(mc));
}
-#elif !defined(TARGET_OSX) // TARGET_FREEBSD
+#elif !defined(__APPLE__) // TARGET_FREEBSD
#define MCREG_X0(mc) ((mc).regs[0])
#define MCREG_X1(mc) ((mc).regs[1])
@@ -792,7 +792,7 @@ void GetConstNativeSigSimdContext(const native_context_t *mc, fpsimd_context con
GetNativeSigSimdContext(const_cast(mc), const_cast(fp_ptr), const_cast(sve_ptr));
}
-#else // TARGET_OSX
+#else // __APPLE__
#define MCREG_X0(mc) ((mc)->__ss.__x[0])
#define MCREG_X1(mc) ((mc)->__ss.__x[1])
@@ -842,7 +842,7 @@ const _STRUCT_ARM_NEON_STATE64* GetConstNativeSigSimdContext(const native_contex
return GetNativeSigSimdContext(const_cast(mc));
}
-#endif // TARGET_OSX
+#endif // __APPLE__
#elif defined(HOST_LOONGARCH64)
@@ -882,7 +882,7 @@ const _STRUCT_ARM_NEON_STATE64* GetConstNativeSigSimdContext(const native_contex
#else // HOST_ARM64
-#ifdef TARGET_OSX
+#ifdef __APPLE__
#define MCREG_Rbp(mc) ((mc)->__ss.__rbp)
#define MCREG_Rip(mc) ((mc)->__ss.__rip)
@@ -1002,7 +1002,7 @@ inline void *FPREG_Xstate_Hi16Zmm(const ucontext_t *uc, uint32_t *featureSize)
#define FPREG_Xmm(uc, index) *(M128A*) &(FPSTATE(uc).fp_fxsave.xmm[index])
#define FPREG_St(uc, index) *(M128A*) &(FPSTATE(uc).fp_fxsave.fp[index].value)
-#else //TARGET_OSX
+#else //__APPLE__
// For FreeBSD, as found in x86/ucontext.h
#define MCREG_Rbp(mc) ((mc).mc_rbp)
@@ -1039,7 +1039,7 @@ inline void *FPREG_Xstate_Hi16Zmm(const ucontext_t *uc, uint32_t *featureSize)
#define FPREG_Xmm(uc, index) *(M128A*) &(FPSTATE(uc)->sv_xmm[index])
#define FPREG_St(uc, index) *(M128A*) &(FPSTATE(uc)->sv_fp[index].fp_acc)
-#endif // TARGET_OSX
+#endif // __APPLE__
#endif // HOST_ARM64
#else // HOST_64BIT
diff --git a/src/coreclr/pal/src/include/pal/dbgmsg.h b/src/coreclr/pal/src/include/pal/dbgmsg.h
index ca8d1454de914..0d0c5e4aed4ce 100644
--- a/src/coreclr/pal/src/include/pal/dbgmsg.h
+++ b/src/coreclr/pal/src/include/pal/dbgmsg.h
@@ -494,7 +494,7 @@ if new_level is -1, the nesting level will not be modified
--*/
int DBG_change_entrylevel(int new_level);
-#ifdef __APPLE__
+#ifdef TARGET_OSX
/*++
Function :
PAL_DisplayDialog
@@ -514,10 +514,10 @@ Function :
--*/
void PAL_DisplayDialogFormatted(const char *szTitle, const char *szTextFormat, ...);
-#else // __APPLE__
+#else // TARGET_OSX
#define PAL_DisplayDialog(_szTitle, _szText)
#define PAL_DisplayDialogFormatted(_szTitle, _szTextFormat, args...)
-#endif // __APPLE__
+#endif // TARGET_OSX
#ifdef __cplusplus
}
diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp
index 16df9848d9b77..aa02c81a1514b 100644
--- a/src/coreclr/pal/src/map/virtual.cpp
+++ b/src/coreclr/pal/src/map/virtual.cpp
@@ -39,6 +39,7 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d
#include
#include
#include
+#include
#if HAVE_VM_ALLOCATE
#include
@@ -54,6 +55,11 @@ static PCMI pVirtualMemory;
static size_t s_virtualPageSize = 0;
+#if defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(HOST_OSX)
+void (*jit_write_protect_np)(int enabled);
+#define pthread_jit_write_protect_np jit_write_protect_np
+#endif // defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(HOST_OSX)
+
/* We need MAP_ANON. However on some platforms like HP-UX, it is defined as MAP_ANONYMOUS */
#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
#define MAP_ANON MAP_ANONYMOUS
@@ -178,6 +184,15 @@ VIRTUALInitialize(bool initializeExecutableMemoryAllocator)
g_executableMemoryAllocator.Initialize();
}
+#if defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(HOST_OSX)
+ jit_write_protect_np = (void (*)(int))dlsym(RTLD_DEFAULT, "pthread_jit_write_protect_np");
+ if (jit_write_protect_np == NULL)
+ {
+ ERROR("pthread_jit_write_protect_np not available.\n");
+ return FALSE;
+ }
+#endif // defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(HOST_OSX)
+
return TRUE;
}
@@ -1234,7 +1249,7 @@ VirtualProtect(
return bRetVal;
}
-#if defined(HOST_OSX) && defined(HOST_ARM64)
+#if defined(HOST_APPLE) && defined(HOST_ARM64)
PALAPI VOID PAL_JitWriteProtect(bool writeEnable)
{
thread_local int enabledCount = 0;
@@ -1254,7 +1269,7 @@ PALAPI VOID PAL_JitWriteProtect(bool writeEnable)
_ASSERTE(enabledCount >= 0);
}
}
-#endif // HOST_OSX && HOST_ARM64
+#endif // HOST_APPLE && HOST_ARM64
#if HAVE_VM_ALLOCATE
//---------------------------------------------------------------------------------------
diff --git a/src/coreclr/pal/src/misc/dbgmsg.cpp b/src/coreclr/pal/src/misc/dbgmsg.cpp
index 4c22dfb4e4716..3a1da44c9b79c 100644
--- a/src/coreclr/pal/src/misc/dbgmsg.cpp
+++ b/src/coreclr/pal/src/misc/dbgmsg.cpp
@@ -733,7 +733,7 @@ bool DBG_ShouldCheckStackAlignment()
}
#endif // _DEBUG && __APPLE__
-#ifdef __APPLE__
+#if defined(TARGET_OSX)
#include "CoreFoundation/CFUserNotification.h"
#include "CoreFoundation/CFString.h"
#include "Security/AuthSession.h"
@@ -853,4 +853,4 @@ void PAL_DisplayDialogFormatted(const char *szTitle, const char *szTextFormat, .
va_end(args);
}
-#endif // __APPLE__
+#endif // TARGET_OSX
diff --git a/src/coreclr/pal/src/misc/sysinfo.cpp b/src/coreclr/pal/src/misc/sysinfo.cpp
index d2d5af184f2fc..f4fef6977f3d6 100644
--- a/src/coreclr/pal/src/misc/sysinfo.cpp
+++ b/src/coreclr/pal/src/misc/sysinfo.cpp
@@ -58,12 +58,12 @@ Revision History:
#include
#endif // HAVE_MACHINE_VMPARAM_H
-#if defined(TARGET_OSX)
+#if defined(__APPLE__)
#include
#include
#include
#include
-#endif // defined(TARGET_OSX)
+#endif // defined(__APPLE__)
#ifdef __HAIKU__
#include
@@ -217,6 +217,8 @@ GetSystemInfo(
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47);
#elif defined(__sun)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) 0xfffffd7fffe00000ul;
+#elif defined(VM_MAX_PAGE_ADDRESS)
+ lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAX_PAGE_ADDRESS;
#elif defined(__HAIKU__)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) 0x7fffffe00000ul;
#elif defined(USERLIMIT)
diff --git a/src/coreclr/pal/src/thread/context.cpp b/src/coreclr/pal/src/thread/context.cpp
index ecd252936299d..feff4b8915f7f 100644
--- a/src/coreclr/pal/src/thread/context.cpp
+++ b/src/coreclr/pal/src/thread/context.cpp
@@ -29,6 +29,9 @@ SET_DEFAULT_DEBUG_CHANNEL(THREAD); // some headers have code with asserts, so do
#endif
#include
#include
+#if defined(HOST_APPLE) && !defined(HOST_OSX)
+#include
+#endif
extern PGET_GCMARKER_EXCEPTION_CODE g_getGcMarkerExceptionCode;
@@ -722,7 +725,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X && !HOST_LOONGARCH64 && !HOST_RISCV64 && !HOST_POWERPC64
#endif // !HAVE_FPREGS_WITH_CW
-#if defined(HOST_ARM64) && !defined(TARGET_OSX) && !defined(TARGET_FREEBSD)
+#if defined(HOST_ARM64) && !defined(__APPLE__) && !defined(TARGET_FREEBSD)
sve_context* sve = nullptr;
fpsimd_context* fp = nullptr;
if (((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) ||
@@ -730,7 +733,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
{
GetNativeSigSimdContext(native, &fp, &sve);
}
-#endif // HOST_ARM64 && !TARGET_OSX && !TARGET_FREEBSD
+#endif // HOST_ARM64 && !__APPLE__ && !TARGET_FREEBSD
if ((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
{
@@ -760,7 +763,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
FPREG_Xmm(native, i) = lpContext->FltSave.XmmRegisters[i];
}
#elif defined(HOST_ARM64)
-#ifdef TARGET_OSX
+#ifdef __APPLE__
_STRUCT_ARM_NEON_STATE64* fp = GetNativeSigSimdContext(native);
fp->__fpsr = lpContext->Fpsr;
fp->__fpcr = lpContext->Fpcr;
@@ -779,7 +782,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
*(NEON128*) &fp->fp_q[i] = lpContext->V[i];
}
}
-#else // TARGET_OSX
+#else // __APPLE__
if (fp)
{
fp->fpsr = lpContext->Fpsr;
@@ -789,7 +792,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
*(NEON128*) &fp->vregs[i] = lpContext->V[i];
}
}
-#endif // TARGET_OSX
+#endif // __APPLE__
#elif defined(HOST_ARM)
VfpSigFrame* fp = GetNativeSigSimdContext(native);
if (fp)
@@ -917,7 +920,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
}
-#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(TARGET_OSX)
+#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(__APPLE__)
/*++
Function :
_GetNativeSigSimdContext
@@ -1007,7 +1010,7 @@ void _GetNativeSigSimdContext(uint8_t *data, uint32_t size, fpsimd_context **fp_
*sve_ptr = sve;
}
}
-#endif // HOST_64BIT && HOST_ARM64 && !TARGET_FREEBSD && !TARGET_OSX
+#endif // HOST_64BIT && HOST_ARM64 && !TARGET_FREEBSD && !__APPLE__
/*++
Function :
@@ -1074,7 +1077,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X && !HOST_LOONGARCH64 && !HOST_RISCV64 && !HOST_POWERPC64 && !HOST_POWERPC64
#endif // !HAVE_FPREGS_WITH_CW
-#if defined(HOST_ARM64) && !defined(TARGET_OSX) && !defined(TARGET_FREEBSD)
+#if defined(HOST_ARM64) && !defined(__APPLE__) && !defined(TARGET_FREEBSD)
const fpsimd_context* fp = nullptr;
const sve_context* sve = nullptr;
if (((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) ||
@@ -1082,7 +1085,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
{
GetConstNativeSigSimdContext(native, &fp, &sve);
}
-#endif // HOST_ARM64 && !TARGET_OSX && !TARGET_FREEBSD
+#endif // HOST_ARM64 && !__APPLE__ && !TARGET_FREEBSD
if ((contextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
{
@@ -1111,7 +1114,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
lpContext->FltSave.XmmRegisters[i] = FPREG_Xmm(native, i);
}
#elif defined(HOST_ARM64)
-#ifdef TARGET_OSX
+#ifdef __APPLE__
const _STRUCT_ARM_NEON_STATE64* fp = GetConstNativeSigSimdContext(native);
lpContext->Fpsr = fp->__fpsr;
lpContext->Fpcr = fp->__fpcr;
@@ -1130,7 +1133,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
lpContext->V[i] = *(NEON128*) &fp->fp_q[i];
}
}
-#else // TARGET_OSX
+#else // __APPLE__
if (fp)
{
lpContext->Fpsr = fp->fpsr;
@@ -1140,7 +1143,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
lpContext->V[i] = *(NEON128*) &fp->vregs[i];
}
}
-#endif // TARGET_OSX
+#endif // __APPLE__
#elif defined(HOST_ARM)
const VfpSigFrame* fp = GetConstNativeSigSimdContext(native);
if (fp)
@@ -2181,6 +2184,8 @@ DBG_FlushInstructionCache(
#endif
syscall(__NR_riscv_flush_icache, (char *)lpBaseAddress, (char *)((INT_PTR)lpBaseAddress + dwSize), 0 /* all harts */);
+#elif defined(HOST_APPLE) && !defined(HOST_OSX)
+ sys_icache_invalidate((void *)lpBaseAddress, dwSize);
#else
__builtin___clear_cache((char *)lpBaseAddress, (char *)((INT_PTR)lpBaseAddress + dwSize));
#endif
diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp
index ef7d00f43ba05..1c8b048abb943 100644
--- a/src/coreclr/pal/src/thread/process.cpp
+++ b/src/coreclr/pal/src/thread/process.cpp
@@ -84,10 +84,8 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d
#endif
#ifdef __APPLE__
-#include
#include
#include
-#include
#include
#include
extern "C"
@@ -232,7 +230,7 @@ PathCharString* gSharedFilesPath = nullptr;
#if defined(__NetBSD__)
#define CLR_SEM_MAX_NAMELEN 15
#elif defined(__APPLE__)
-#define CLR_SEM_MAX_NAMELEN PSEMNAMLEN
+#define CLR_SEM_MAX_NAMELEN 31
#elif defined(NAME_MAX)
#define CLR_SEM_MAX_NAMELEN (NAME_MAX - 4)
#else
@@ -2217,6 +2215,9 @@ PROCCreateCrashDump(
INT cbErrorMessageBuffer,
bool serialize)
{
+#if defined(TARGET_IOS)
+ return FALSE;
+#else
_ASSERTE(argv.size() > 0);
_ASSERTE(errorMessageBuffer == nullptr || cbErrorMessageBuffer > 0);
@@ -2344,6 +2345,7 @@ PROCCreateCrashDump(
}
}
return true;
+#endif // !TARGET_IOS
}
/*++
@@ -2614,7 +2616,7 @@ InitializeFlushProcessWriteBuffers()
}
}
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
return TRUE;
#else
s_helperPage = static_cast(mmap(0, GetVirtualPageSize(), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
@@ -2644,7 +2646,7 @@ InitializeFlushProcessWriteBuffers()
}
return status == 0;
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
}
#define FATAL_ASSERT(e, msg) \
@@ -2694,7 +2696,7 @@ FlushProcessWriteBuffers()
status = pthread_mutex_unlock(&flushProcessWriteBuffersMutex);
FATAL_ASSERT(status == 0, "Failed to unlock the flushProcessWriteBuffersMutex lock");
}
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
else
{
mach_msg_type_number_t cThreads;
@@ -2723,7 +2725,7 @@ FlushProcessWriteBuffers()
machret = vm_deallocate(mach_task_self(), (vm_address_t)pThreads, cThreads * sizeof(thread_act_t));
CHECK_MACH("vm_deallocate()", machret);
}
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
}
/*++
diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs
index 59a0567d790f2..ef76a9abcce5b 100644
--- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs
+++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs
@@ -112,6 +112,11 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t
return MachineOSOverride.Linux;
case TargetOS.OSX:
+ case TargetOS.MacCatalyst:
+ case TargetOS.iOS:
+ case TargetOS.iOSSimulator:
+ case TargetOS.tvOS:
+ case TargetOS.tvOSSimulator:
return MachineOSOverride.Apple;
case TargetOS.FreeBSD:
diff --git a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs
index 0f24eceeed0eb..6265d0df45b65 100644
--- a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs
+++ b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs
@@ -295,7 +295,7 @@ public static IEnumerable> GetExtendedHelp(HelpContext _
Console.WriteLine();
string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64"};
- string[] ValidOS = new string[] {"windows", "linux", "osx"};
+ string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "maccatalyst"};
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()));
Console.WriteLine();
diff --git a/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp b/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp
index 8fd38d192f84e..48cf7ece4a12b 100644
--- a/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp
+++ b/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp
@@ -55,5 +55,9 @@ DLL_EXPORT void JitProcessShutdownWork(ICorJitCompiler * pJit)
DLL_EXPORT int JitGetProcessorFeatures()
{
+#ifndef CROSS_COMPILE
return minipal_getcpufeatures();
+#else
+ return 0;
+#endif
}
diff --git a/src/coreclr/utilcode/executableallocator.cpp b/src/coreclr/utilcode/executableallocator.cpp
index 8ee089c4ccfb0..eb20b6ab4668b 100644
--- a/src/coreclr/utilcode/executableallocator.cpp
+++ b/src/coreclr/utilcode/executableallocator.cpp
@@ -124,7 +124,7 @@ bool ExecutableAllocator::IsDoubleMappingEnabled()
{
LIMITED_METHOD_CONTRACT;
-#if defined(HOST_OSX) && defined(HOST_ARM64)
+#if defined(HOST_APPLE) && defined(HOST_ARM64)
return false;
#else
return g_isWXorXEnabled;
@@ -135,7 +135,7 @@ bool ExecutableAllocator::IsWXORXEnabled()
{
LIMITED_METHOD_CONTRACT;
-#if defined(HOST_OSX) && defined(HOST_ARM64)
+#if defined(HOST_APPLE) && defined(HOST_ARM64)
return true;
#else
return g_isWXorXEnabled;
diff --git a/src/coreclr/vm/amd64/asmhelpers.S b/src/coreclr/vm/amd64/asmhelpers.S
index 8d83938246a2c..a02959566b881 100644
--- a/src/coreclr/vm/amd64/asmhelpers.S
+++ b/src/coreclr/vm/amd64/asmhelpers.S
@@ -271,7 +271,7 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT, NoHandler
ret
NESTED_END ProfileTailcallNaked, _TEXT
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
# EXTERN_C void* GetThreadVarsAddress()
#
# Helper to calculate the address of relevant __thread_vars section that holds the address of symbol tlv_get_address for thread
@@ -283,9 +283,9 @@ LEAF_ENTRY GetThreadVarsAddress, _TEXT
ret
LEAF_END GetThreadVarsAddress, _TEXT
// ------------------------------------------------------------------
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
# EXTERN_C void* GetTlsIndexObjectDescOffset();
#
diff --git a/src/coreclr/vm/amd64/jithelpers_fast.S b/src/coreclr/vm/amd64/jithelpers_fast.S
index 96195353db290..b4b1df87c73bd 100644
--- a/src/coreclr/vm/amd64/jithelpers_fast.S
+++ b/src/coreclr/vm/amd64/jithelpers_fast.S
@@ -215,7 +215,7 @@ LEAF_END_MARKED JIT_ByRefWriteBarrier, _TEXT
// When JIT_WriteBarrier is copied into an allocated page,
// helpers use this global variable to jump to it. This variable is set in InitThreadManager.
.global C_FUNC(JIT_WriteBarrier_Loc)
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
.zerofill __DATA,__common,C_FUNC(JIT_WriteBarrier_Loc),8,3
#else
.data
diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S
index 65c1eaec4121a..c6b7728702a23 100644
--- a/src/coreclr/vm/arm64/asmhelpers.S
+++ b/src/coreclr/vm/arm64/asmhelpers.S
@@ -757,7 +757,7 @@ LEAF_ENTRY JIT_DispatchIndirectCall, _TEXT
br x9
LEAF_END JIT_DispatchIndirectCall, _TEXT
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
// ------------------------------------------------------------------
// void* GetThreadVarsAddress()
@@ -771,9 +771,9 @@ LEAF_ENTRY GetThreadVarsAddress, _TEXT
ret
LEAF_END GetThreadVarsAddress, _TEXT
// ------------------------------------------------------------------
-#endif // TARGET_OSX
+#endif // TARGET_APPLE
-#ifndef TARGET_OSX
+#ifndef TARGET_APPLE
// ------------------------------------------------------------------
// size_t GetThreadStaticsVariableOffset()
@@ -805,4 +805,4 @@ LEAF_ENTRY GetTLSResolverAddress, _TEXT
EPILOG_RETURN
LEAF_END GetTLSResolverAddress, _TEXT
// ------------------------------------------------------------------
-#endif // !TARGET_OSX
+#endif // !TARGET_APPLE
diff --git a/src/coreclr/vm/arm64/stubs.cpp b/src/coreclr/vm/arm64/stubs.cpp
index 825d2e0e4fd81..8e338ddbf555c 100644
--- a/src/coreclr/vm/arm64/stubs.cpp
+++ b/src/coreclr/vm/arm64/stubs.cpp
@@ -1374,7 +1374,7 @@ VOID StubLinkerCPU::EmitShuffleThunk(ShuffleEntry *pShuffleEntryArray)
_ASSERTE(!(pEntry->dstofs & ShuffleEntry::FPREGMASK));
-#if !defined(TARGET_OSX)
+#if !defined(TARGET_APPLE)
EmitLoadStoreRegImm(eLOAD, IntReg(pEntry->dstofs & ShuffleEntry::OFSREGMASK), RegSp, pEntry->srcofs * sizeof(void*));
#else
int log2Size = (pEntry->srcofs >> 12);
@@ -1390,7 +1390,7 @@ VOID StubLinkerCPU::EmitShuffleThunk(ShuffleEntry *pShuffleEntryArray)
// dest must be on the stack
_ASSERTE(!(pEntry->dstofs & ShuffleEntry::REGMASK));
-#if !defined(TARGET_OSX)
+#if !defined(TARGET_APPLE)
EmitLoadStoreRegImm(eLOAD, IntReg(9), RegSp, pEntry->srcofs * sizeof(void*));
EmitLoadStoreRegImm(eSTORE, IntReg(9), RegSp, pEntry->dstofs * sizeof(void*));
#else
diff --git a/src/coreclr/vm/cdacplatformmetadata.cpp b/src/coreclr/vm/cdacplatformmetadata.cpp
index b89c90fae7ed8..0c9c1233e9487 100644
--- a/src/coreclr/vm/cdacplatformmetadata.cpp
+++ b/src/coreclr/vm/cdacplatformmetadata.cpp
@@ -11,7 +11,7 @@ void CDacPlatformMetadata::Init()
PrecodeMachineDescriptor::Init(&g_cdacPlatformMetadata.precode);
#if defined(TARGET_ARM)
g_cdacPlatformMetadata.codePointerFlags = CDacCodePointerFlags::HasArm32ThumbBit;
-#elif defined(TARGET_ARM64) && defined(TARGET_OSX)
+#elif defined(TARGET_ARM64) && defined(TARGET_APPLE)
// TODO set HasArm64PtrAuth if arm64e
g_cdacPlatformMetadata.codePointerFlags = CDacCodePointerFlags::None;
#else
diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp
index 18fb1f1e10328..3f5f598956d27 100644
--- a/src/coreclr/vm/comdelegate.cpp
+++ b/src/coreclr/vm/comdelegate.cpp
@@ -211,7 +211,7 @@ class ShuffleIterator
{
const unsigned byteIndex = m_argLocDesc->m_byteStackIndex + m_currentByteStackIndex;
-#if !defined(TARGET_OSX) || !defined(TARGET_ARM64)
+#if !defined(TARGET_APPLE) || !defined(TARGET_ARM64)
index = byteIndex / TARGET_POINTER_SIZE;
m_currentByteStackIndex += TARGET_POINTER_SIZE;
diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp
index ff5cf24a4ac01..803ff8df6aca6 100644
--- a/src/coreclr/vm/jitinterface.cpp
+++ b/src/coreclr/vm/jitinterface.cpp
@@ -10151,7 +10151,7 @@ void InlinedCallFrame::GetEEInfo(CORINFO_EE_INFO::InlinedCallFrameInfo *pInfo)
CORINFO_OS getClrVmOs()
{
-#ifdef TARGET_OSX
+#ifdef TARGET_APPLE
return CORINFO_APPLE;
#elif defined(TARGET_UNIX)
return CORINFO_UNIX;
diff --git a/src/coreclr/vm/threads.h b/src/coreclr/vm/threads.h
index 40b182b728ef7..c8c4b1373838b 100644
--- a/src/coreclr/vm/threads.h
+++ b/src/coreclr/vm/threads.h
@@ -5669,7 +5669,7 @@ inline BOOL IsWriteBarrierCopyEnabled()
#ifdef DACCESS_COMPILE
return FALSE;
#else // DACCESS_COMPILE
-#ifdef HOST_OSX
+#ifdef HOST_APPLE
return TRUE;
#else
return ExecutableAllocator::IsWXORXEnabled();
diff --git a/src/coreclr/vm/threadstatics.cpp b/src/coreclr/vm/threadstatics.cpp
index d7a0a70ed99d8..98d81986d53f3 100644
--- a/src/coreclr/vm/threadstatics.cpp
+++ b/src/coreclr/vm/threadstatics.cpp
@@ -804,7 +804,7 @@ void FreeTLSIndicesForLoaderAllocator(LoaderAllocator *pLoaderAllocator)
static void* GetTlsIndexObjectAddress();
-#if !defined(TARGET_OSX) && defined(TARGET_UNIX) && (defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64))
+#if !defined(TARGET_APPLE) && defined(TARGET_UNIX) && (defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64))
extern "C" size_t GetTLSResolverAddress();
// Check if the resolver address retrieval code is expected. We verify the exact
@@ -903,7 +903,7 @@ static bool IsValidTLSResolver()
return false;
}
-#endif // !TARGET_OSX && TARGET_UNIX && (TARGET_ARM64 || TARGET_LOONGARCH64)
+#endif // !TARGET_APPLE && TARGET_UNIX && (TARGET_ARM64 || TARGET_LOONGARCH64)
bool CanJITOptimizeTLSAccess()
{
@@ -924,7 +924,7 @@ bool CanJITOptimizeTLSAccess()
// Optimization is disabled for FreeBSD/arm64
#elif defined(FEATURE_INTERPRETER)
// Optimization is disabled when interpreter may be used
-#elif !defined(TARGET_OSX) && defined(TARGET_UNIX) && defined(TARGET_ARM64)
+#elif !defined(TARGET_APPLE) && defined(TARGET_UNIX) && defined(TARGET_ARM64)
bool tlsResolverValid = IsValidTLSResolver();
if (tlsResolverValid)
{
@@ -960,12 +960,12 @@ bool CanJITOptimizeTLSAccess()
}
#else
optimizeThreadStaticAccess = true;
-#if !defined(TARGET_OSX) && defined(TARGET_UNIX) && defined(TARGET_AMD64)
+#if !defined(TARGET_APPLE) && defined(TARGET_UNIX) && defined(TARGET_AMD64)
// For linux/x64, check if compiled coreclr as .so file and not single file.
// For single file, the `tls_index` might not be accurate.
// Do not perform this optimization in such case.
optimizeThreadStaticAccess = GetTlsIndexObjectAddress() != nullptr;
-#endif // !TARGET_OSX && TARGET_UNIX && TARGET_AMD64
+#endif // !TARGET_APPLE && TARGET_UNIX && TARGET_AMD64
#endif
return optimizeThreadStaticAccess;
@@ -987,7 +987,7 @@ static uint32_t ThreadLocalOffset(void* p)
uint8_t* pOurTls = pTls[_tls_index];
return (uint32_t)((uint8_t*)p - pOurTls);
}
-#elif defined(TARGET_OSX)
+#elif defined(TARGET_APPLE)
extern "C" void* GetThreadVarsAddress();
static void* GetThreadVarsSectionAddressFromDesc(uint8_t* p)
@@ -1081,7 +1081,7 @@ void GetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo)
pInfo->offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer);
threadStaticBaseOffset = ThreadLocalOffset(&t_ThreadStatics);
-#elif defined(TARGET_OSX)
+#elif defined(TARGET_APPLE)
pInfo->threadVarsSection = GetThreadVarsSectionAddress();
diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
index b0984084685b2..86ea8a85efdf5 100644
--- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
+++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
@@ -101,6 +101,7 @@
+
diff --git a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets
index 3d982701bf8b6..bf0b75fc060b0 100644
--- a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets
+++ b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets
@@ -12,6 +12,15 @@
+
+
+
+
+
+
+
diff --git a/src/mono/msbuild/apple/build/AppleBuild.props b/src/mono/msbuild/apple/build/AppleBuild.props
index 22984e921c968..6625f122c63ef 100644
--- a/src/mono/msbuild/apple/build/AppleBuild.props
+++ b/src/mono/msbuild/apple/build/AppleBuild.props
@@ -1,7 +1,7 @@
- true
+ true
@@ -12,7 +12,7 @@
true
$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())
- true
+ true
true
false
@@ -24,7 +24,7 @@
<_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' == 'true'">_AppleNativeAotCompile
<_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_AppleAotCompile
ComputeIlcCompileInputs;SetupOSSpecificProps;PrepareForILLink
- <_ReadRuntimeComponentsManifestTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_MonoReadAvailableComponentsManifest
+ <_ReadRuntimeComponentsManifestTargetName Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' != 'false'">_MonoReadAvailableComponentsManifest
Publish
@@ -44,6 +44,6 @@
<_CommonTargetsDir Condition="'$(_CommonTargetsDir)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', '..', 'common'))
-
-
+
+
\ No newline at end of file
diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets
index a136da379cced..0aafe5b5612d0 100644
--- a/src/mono/msbuild/apple/build/AppleBuild.targets
+++ b/src/mono/msbuild/apple/build/AppleBuild.targets
@@ -54,12 +54,12 @@
$([MSBuild]::NormalizeDirectory('$(OutDir)', 'Bundle'))
$(AppleBundleDir)
- <_MonoHeaderPath Condition="'$(UseNativeAOTRuntime)' != 'true'">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include', 'mono-2.0'))
+ <_MonoHeaderPath Condition="'$(UseMonoRuntime)' != 'false' and '$(UseNativeAOTRuntime)' != 'true'">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include', 'mono-2.0'))
<_AotModuleTablePath>$(AppleBundleDir)\modules.m
$(AssemblyName)
-
+
@@ -298,8 +298,15 @@
+
+
+ NativeAOT
+ CoreCLR
+ MonoVM
+
+ UseConsoleUITemplate="$(UseConsoleUITemplate)">
diff --git a/src/native/eventpipe/ds-ipc-pal-socket.c b/src/native/eventpipe/ds-ipc-pal-socket.c
index 7ad0b0f5d4859..104879298e92a 100644
--- a/src/native/eventpipe/ds-ipc-pal-socket.c
+++ b/src/native/eventpipe/ds-ipc-pal-socket.c
@@ -123,6 +123,27 @@ ep_rt_object_array_free (void *ptr)
if (ptr)
free (ptr);
}
+
+static
+inline
+ep_char8_t *
+ep_rt_utf8_string_dup (const ep_char8_t *str)
+{
+ if (!str)
+ return NULL;
+
+ return strdup (str);
+}
+
+static
+inline
+void
+ep_rt_utf8_string_free (ep_char8_t *str)
+{
+ if (str)
+ free (str);
+}
+
#endif
static bool _ipc_pal_socket_init = false;
diff --git a/src/native/external/libunwind.cmake b/src/native/external/libunwind.cmake
index 5dcca157e23ae..6d4a03fdff4da 100644
--- a/src/native/external/libunwind.cmake
+++ b/src/native/external/libunwind.cmake
@@ -447,7 +447,7 @@ if(CLR_CMAKE_HOST_UNIX)
list(APPEND libunwind_setjmp_la_SOURCES riscv/siglongjmp.S)
endif()
- if(CLR_CMAKE_HOST_OSX)
+ if(CLR_CMAKE_HOST_APPLE)
set(LIBUNWIND_SOURCES_BASE
remote/mac/missing-functions.c
${libunwind_remote_la_SOURCES}
@@ -463,7 +463,7 @@ if(CLR_CMAKE_HOST_UNIX)
${libunwind_dwarf_generic_la_SOURCES}
${libunwind_elf_la_SOURCES}
)
- endif(CLR_CMAKE_HOST_OSX)
+ endif(CLR_CMAKE_HOST_APPLE)
else(CLR_CMAKE_HOST_UNIX)
if(CLR_CMAKE_TARGET_ARCH_ARM64)
diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt
index 2bfd2194c969e..b08325f09e3bf 100644
--- a/src/native/external/libunwind_extras/CMakeLists.txt
+++ b/src/native/external/libunwind_extras/CMakeLists.txt
@@ -78,7 +78,7 @@ if(CLR_CMAKE_HOST_UNIX)
###TODO: maybe add options for RISCV64
endif()
- if (CLR_CMAKE_HOST_OSX)
+ if (CLR_CMAKE_HOST_APPLE)
add_definitions(-DUNW_REMOTE_ONLY)
add_compile_options(-Wno-sometimes-uninitialized)
add_compile_options(-Wno-implicit-function-declaration)
@@ -86,7 +86,7 @@ if(CLR_CMAKE_HOST_UNIX)
# Our posix abstraction layer will provide these headers
set(HAVE_ELF_H 1)
set(HAVE_ENDIAN_H 1)
- endif(CLR_CMAKE_HOST_OSX)
+ endif(CLR_CMAKE_HOST_APPLE)
endif(CLR_CMAKE_HOST_UNIX)
@@ -146,7 +146,7 @@ if(CLR_CMAKE_HOST_WIN32)
add_compile_options(-wd4311) # pointer truncation from 'unw_word_t *' to 'long'
add_compile_options(-wd4475) # 'fprintf' : length modifier 'L' cannot be used
add_compile_options(-wd4477) # fprintf argument type
-elseif(CLR_CMAKE_HOST_OSX)
+elseif(CLR_CMAKE_HOST_APPLE)
include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote)
include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/mac)
endif (CLR_CMAKE_HOST_WIN32)
@@ -166,11 +166,11 @@ if(CLR_CMAKE_HOST_WIN32)
endif(CLR_CMAKE_HOST_WIN32)
if(CLR_CMAKE_HOST_UNIX)
- if(CLR_CMAKE_HOST_OSX)
+ if(CLR_CMAKE_HOST_APPLE)
add_library(libunwind_dac OBJECT ${LIBUNWIND_SOURCES})
else()
add_library(libunwind OBJECT ${LIBUNWIND_SOURCES})
- endif(CLR_CMAKE_HOST_OSX)
+ endif(CLR_CMAKE_HOST_APPLE)
else(CLR_CMAKE_HOST_UNIX)
set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc)
diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake
index 945fbed855ce8..fc7332a54f9fa 100644
--- a/src/native/libs/configure.cmake
+++ b/src/native/libs/configure.cmake
@@ -9,7 +9,7 @@ include(CheckTypeSize)
include(CheckLibraryExists)
include(CheckFunctionExists)
-if (CLR_CMAKE_TARGET_OSX)
+if (CLR_CMAKE_TARGET_APPLE)
# Xcode's clang does not include /usr/local/include by default, but brew's does.
# This ensures an even playing field.
include_directories(SYSTEM /usr/local/include)
diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
index 0e16db616d62e..2c1304b0dc360 100644
--- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
+++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
@@ -13,6 +13,7 @@
public class AppleAppBuilderTask : Task
{
private string targetOS = TargetNames.iOS;
+ private TargetRuntime targetRuntime;
///
/// The Apple OS we are targeting (ios, tvos, iossimulator, tvossimulator)
@@ -177,9 +178,9 @@ public string TargetOS
public bool StripSymbolTable { get; set; }
///
- /// Bundles the application for NativeAOT runtime. Default runtime is Mono.
+ /// Bundles the application for specific runtime. Valid values: MonoVM, NativeAOT, CoreCLR.
///
- public bool UseNativeAOTRuntime { get; set; }
+ public string Runtime { get; set; } = "MonoVM";
///
/// Extra native dependencies to link into the app
@@ -193,28 +194,33 @@ public string TargetOS
public void ValidateRuntimeSelection()
{
- if (UseNativeAOTRuntime)
+ if (!Enum.TryParse(Runtime, out targetRuntime))
+ {
+ throw new ArgumentException($"The \"{nameof(AppleAppBuilderTask)}\" task was not given an invalid value for parameter \"{nameof(Runtime)}\".");
+ }
+
+ if (targetRuntime == TargetRuntime.NativeAOT || targetRuntime == TargetRuntime.CoreCLR)
{
if (!string.IsNullOrEmpty(MonoRuntimeHeaders))
- throw new ArgumentException($"Property \"{nameof(MonoRuntimeHeaders)}\" is not supported with NativeAOT runtime and will be ignored.");
+ throw new ArgumentException($"Property \"{nameof(MonoRuntimeHeaders)}\" is not supported with {Runtime} runtime and will be ignored.");
- if (!string.IsNullOrEmpty(MainLibraryFileName))
- throw new ArgumentException($"Property \"{nameof(MainLibraryFileName)}\" is not supported with NativeAOT runtime and will be ignored.");
+ if (!string.IsNullOrEmpty(MainLibraryFileName) && targetRuntime == TargetRuntime.NativeAOT)
+ throw new ArgumentException($"Property \"{nameof(MainLibraryFileName)}\" is not supported with {Runtime} runtime and will be ignored.");
if (ForceInterpreter)
- throw new ArgumentException($"Property \"{nameof(ForceInterpreter)}\" is not supported with NativeAOT runtime and will be ignored.");
+ throw new ArgumentException($"Property \"{nameof(ForceInterpreter)}\" is not supported with {Runtime} runtime and will be ignored.");
if (ForceAOT)
- throw new ArgumentException($"Property \"{nameof(ForceAOT)}\" is not supported with NativeAOT runtime and will be ignored.");
+ throw new ArgumentException($"Property \"{nameof(ForceAOT)}\" is not supported with {Runtime} runtime and will be ignored.");
- if (RuntimeComponents.Length > 0)
+ if (RuntimeComponents.Length > 0 && targetRuntime == TargetRuntime.NativeAOT)
throw new ArgumentException($"Item \"{nameof(RuntimeComponents)}\" is not supported with NativeAOT runtime and will be ignored.");
if (!string.IsNullOrEmpty(DiagnosticPorts))
- throw new ArgumentException($"Property \"{nameof(DiagnosticPorts)}\" is not supported with NativeAOT runtime and will be ignored.");
+ throw new ArgumentException($"Property \"{nameof(DiagnosticPorts)}\" is not supported with {Runtime} runtime and will be ignored.");
if (EnableRuntimeLogging)
- throw new ArgumentException($"Property \"{nameof(EnableRuntimeLogging)}\" is not supported with NativeAOT runtime and will be ignored.");
+ throw new ArgumentException($"Property \"{nameof(EnableRuntimeLogging)}\" is not supported with {Runtime} runtime and will be ignored.");
}
else
{
@@ -288,7 +294,7 @@ public override bool Execute()
}
}
- if (!ForceInterpreter && (shouldStaticLink || ForceAOT) && (assemblerFiles.Count == 0 && !UseNativeAOTRuntime))
+ if (!ForceInterpreter && (shouldStaticLink || ForceAOT) && (assemblerFiles.Count == 0 && targetRuntime == TargetRuntime.MonoVM))
{
throw new InvalidOperationException("Need list of AOT files for static linked builds.");
}
@@ -315,12 +321,25 @@ public override bool Execute()
extraLinkerArgs.Add(item.ItemSpec);
}
+ if (targetRuntime == TargetRuntime.CoreCLR)
+ {
+ if (targetOS == TargetNames.MacCatalyst)
+ {
+ extraLinkerArgs.Add("-rpath @executable_path/../Resources");
+ }
+ else
+ {
+ extraLinkerArgs.Add("-rpath @executable_path");
+ }
+ shouldStaticLink = false;
+ }
+
var generator = new Xcode(Log, TargetOS, Arch);
if (GenerateXcodeProject)
{
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes,
- AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime, IsLibraryMode);
+ AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, targetRuntime, IsLibraryMode);
if (BuildAppBundle)
{
@@ -346,7 +365,7 @@ public override bool Execute()
else if (GenerateCMakeProject)
{
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes,
- AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime, IsLibraryMode);
+ AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, targetRuntime, IsLibraryMode);
}
return true;
diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
index a2c93c2f89d2a..1f0e6ba463420 100644
--- a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
+++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
@@ -9,11 +9,13 @@
+
+
diff --git a/src/tasks/AppleAppBuilder/TargetRuntime.cs b/src/tasks/AppleAppBuilder/TargetRuntime.cs
new file mode 100644
index 0000000000000..81fb9b1c956d1
--- /dev/null
+++ b/src/tasks/AppleAppBuilder/TargetRuntime.cs
@@ -0,0 +1,9 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal enum TargetRuntime
+{
+ MonoVM,
+ CoreCLR,
+ NativeAOT,
+}
diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
index d988551bedf1b..b291b723fdc27 100644
--- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
+++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
@@ -28,7 +28,7 @@ endif()
%Defines%
-if(NOT %UseNativeAOTRuntime%)
+if(NOT "%MonoInclude%" STREQUAL "")
include_directories("%MonoInclude%")
endif()
diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m
new file mode 100644
index 0000000000000..582f041a44d3e
--- /dev/null
+++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m
@@ -0,0 +1,161 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#import
+#include "coreclrhost.h"
+#include
+#import
+#include
+#include
+#include
+#include
+#include
+
+#import "util.h"
+
+#define APPLE_RUNTIME_IDENTIFIER "iossimulator-arm64"
+
+const char *
+get_bundle_path (void)
+{
+ static char *bundle_path = NULL;
+ if (bundle_path)
+ return bundle_path;
+ NSBundle* main_bundle = [NSBundle mainBundle];
+ NSString* path = [main_bundle bundlePath];
+
+#if TARGET_OS_MACCATALYST
+ path = [path stringByAppendingString:@"/Contents/Resources"];
+#endif
+
+ bundle_path = strdup ([path UTF8String]);
+
+ return bundle_path;
+}
+
+char *
+compute_trusted_platform_assemblies ()
+{
+ const char *bundle_path = get_bundle_path ();
+
+ NSMutableArray *files = [NSMutableArray array];
+ NSMutableArray *exes = [NSMutableArray array];
+
+ NSFileManager *manager = [NSFileManager defaultManager];
+ NSString *dir = [NSString stringWithUTF8String: bundle_path];
+ NSDirectoryEnumerator *enumerator = [manager enumeratorAtURL:[NSURL fileURLWithPath: dir]
+ includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
+ options:NSDirectoryEnumerationSkipsSubdirectoryDescendants
+ errorHandler:nil];
+ for (NSURL *file in enumerator) {
+ // skip subdirectories
+ NSNumber *isDirectory = nil;
+ if (![file getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] || [isDirectory boolValue])
+ continue;
+
+ NSString *name = nil;
+ if (![file getResourceValue:&name forKey:NSURLNameKey error:nil])
+ continue;
+ if ([name length] < 4)
+ continue;
+ if ([name compare: @".dll" options: NSCaseInsensitiveSearch range: NSMakeRange ([name length] - 4, 4)] == NSOrderedSame) {
+ [files addObject: [dir stringByAppendingPathComponent: name]];
+ }
+ }
+
+ // Join them all together with a colon separating them
+ NSString *joined = [files componentsJoinedByString: @":"];
+ return strdup([joined UTF8String]);
+}
+
+void*
+pinvoke_override (const char *libraryName, const char *entrypointName)
+{
+ if (!strcmp (libraryName, "__Internal"))
+ {
+ return dlsym (RTLD_DEFAULT, entrypointName);
+ }
+ return NULL;
+}
+
+void
+mono_ios_runtime_init (void)
+{
+#if INVARIANT_GLOBALIZATION
+ setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE);
+#endif
+
+#if HYBRID_GLOBALIZATION
+ setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE);
+#endif
+
+ // build using DiagnosticPorts property in AppleAppBuilder
+ // or set DOTNET_DiagnosticPorts env via mlaunch, xharness when undefined.
+ // NOTE, using DOTNET_DiagnosticPorts requires app build using AppleAppBuilder and RuntimeComponents=diagnostics_tracing
+#ifdef DIAGNOSTIC_PORTS
+ setenv ("DOTNET_DiagnosticPorts", DIAGNOSTIC_PORTS, true);
+#endif
+
+ char **managed_argv;
+ int argi = get_managed_args (&managed_argv);
+
+ bool wait_for_debugger = FALSE;
+
+ const char* bundle = get_bundle_path ();
+ chdir (bundle);
+
+ char icu_dat_path [1024];
+ int res;
+#if defined(HYBRID_GLOBALIZATION)
+ res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt_hybrid.dat");
+#else
+ res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt.dat");
+#endif
+ assert (res > 0);
+
+ char pinvoke_override_addr [16];
+ sprintf (pinvoke_override_addr, "%p", &pinvoke_override);
+
+ // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES
+ const char *appctx_keys [] = {
+ "RUNTIME_IDENTIFIER",
+ "APP_CONTEXT_BASE_DIRECTORY",
+ "TRUSTED_PLATFORM_ASSEMBLIES",
+ "PINVOKE_OVERRIDE",
+#if !defined(INVARIANT_GLOBALIZATION)
+ "ICU_DAT_FILE_PATH"
+#endif
+ };
+ const char *appctx_values [] = {
+ APPLE_RUNTIME_IDENTIFIER,
+ bundle,
+ compute_trusted_platform_assemblies(),
+ pinvoke_override_addr,
+#if !defined(INVARIANT_GLOBALIZATION)
+ icu_dat_path
+#endif
+ };
+
+ const char* executable = "Program.dll";
+ const char *executablePath = [[[[NSBundle mainBundle] executableURL] path] UTF8String];
+ unsigned int coreclr_domainId = 0;
+ void *coreclr_handle = NULL;
+
+ char path [1024];
+ res = snprintf (path, sizeof (path) - 1, "%s/%s", bundle, executable);
+ assert (res > 0);
+
+ res = coreclr_initialize (
+ executablePath, executable,
+ sizeof (appctx_keys) / sizeof (appctx_keys [0]), appctx_keys, appctx_values,
+ &coreclr_handle, &coreclr_domainId);
+ assert (res == 0);
+
+ coreclr_execute_assembly (coreclr_handle, coreclr_domainId, argi, managed_argv, path, &res);
+ // Print this so apps parsing logs can detect when we exited
+ os_log_info (OS_LOG_DEFAULT, EXIT_CODE_TAG ": %d", res);
+
+ free_managed_args (&managed_argv, argi);
+
+ exit (res);
+}
diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs
index ce13c9bf008d1..0b3acb9f32f58 100644
--- a/src/tasks/AppleAppBuilder/Xcode.cs
+++ b/src/tasks/AppleAppBuilder/Xcode.cs
@@ -190,10 +190,10 @@ public string GenerateXCode(
string? diagnosticPorts,
IEnumerable runtimeComponents,
string? nativeMainSource = null,
- bool useNativeAOTRuntime = false,
+ TargetRuntime targetRuntime = TargetRuntime.MonoVM,
bool isLibraryMode = false)
{
- var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, excludes, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, useNativeAOTRuntime, isLibraryMode);
+ var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, excludes, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, targetRuntime, isLibraryMode);
CreateXcodeProject(projectName, cmakeDirectoryPath);
return Path.Combine(binDir, projectName, projectName + ".xcodeproj");
}
@@ -263,14 +263,14 @@ public string GenerateCMake(
string? diagnosticPorts,
IEnumerable runtimeComponents,
string? nativeMainSource = null,
- bool useNativeAOTRuntime = false,
+ TargetRuntime targetRuntime = TargetRuntime.MonoVM,
bool isLibraryMode = false)
{
// bundle everything as resources excluding native files
- var predefinedExcludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib", "icudt*" };
+ var predefinedExcludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "icudt*" };
// TODO: All of these exclusions shouldn't be needed once we carefully construct the publish folder on Helix
- if (useNativeAOTRuntime)
+ if (targetRuntime == TargetRuntime.NativeAOT)
{
predefinedExcludes.Add(".dll");
predefinedExcludes.Add(".pdb");
@@ -289,6 +289,10 @@ public string GenerateCMake(
{
predefinedExcludes.Add(".pdb");
}
+ if (targetRuntime != TargetRuntime.CoreCLR)
+ {
+ predefinedExcludes.Add("libcoreclr.dylib");
+ }
string[] resources = Directory.GetFileSystemEntries(workspace, "", SearchOption.TopDirectoryOnly)
.Where(f => !predefinedExcludes.Any(e => (!e.EndsWith('*') && f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)) || (e.EndsWith('*') && Path.GetFileName(f).StartsWith(e.TrimEnd('*'), StringComparison.InvariantCultureIgnoreCase) &&
@@ -338,7 +342,8 @@ public string GenerateCMake(
string cmakeTemplateName = (isLibraryMode) ? "CMakeLists-librarymode.txt.template" : "CMakeLists.txt.template";
string cmakeLists = Utils.GetEmbeddedResource(cmakeTemplateName)
- .Replace("%UseNativeAOTRuntime%", useNativeAOTRuntime ? "TRUE" : "FALSE")
+ .Replace("%UseMonoRuntime%", targetRuntime == TargetRuntime.MonoVM ? "TRUE" : "FALSE")
+ .Replace("%UseNativeAOTRuntime%", targetRuntime == TargetRuntime.NativeAOT ? "TRUE" : "FALSE")
.Replace("%ProjectName%", projectName)
.Replace("%AppResources%", appResources)
.Replace("%MainSource%", nativeMainSource)
@@ -356,7 +361,7 @@ public string GenerateCMake(
// Current differences:
// - NativeAOT produces {ProjectName}.dylib, while MonoAOT produces lib{ProjectName}.dylib
// - NativeAOT places the library in the 'workspace' location ie 'publish' folder, while MonoAOT places it in 'binDir' ie 'AppBundle'
- if (useNativeAOTRuntime)
+ if (targetRuntime == TargetRuntime.NativeAOT)
{
libraryPath = Path.Combine(workspace, $"{projectName}.dylib");
}
@@ -373,7 +378,7 @@ public string GenerateCMake(
cmakeLists = cmakeLists.Replace("%DYLIB_PATH%", libraryPath);
// pass the shared library to the linker for dynamic linking
- if (useNativeAOTRuntime)
+ if (targetRuntime == TargetRuntime.NativeAOT)
toLink += $" {libraryPath}{Environment.NewLine}";
}
else
@@ -407,29 +412,38 @@ public string GenerateCMake(
}
string[] dylibs = Directory.GetFiles(workspace, "*.dylib");
-
- // Sort the static libraries to link so the brotli libs are added to the list last (after the compression native libs)
- List staticLibsToLink = Directory.GetFiles(workspace, "*.a").OrderBy(libName => libName.Contains("brotli") ? 1 : 0).ToList();
- foreach (string lib in staticLibsToLink)
+ if (targetRuntime == TargetRuntime.CoreCLR)
{
- // all component libs already added to linker.
- if (allComponentLibs.Any(lib.Contains))
- continue;
-
- string libName = Path.GetFileNameWithoutExtension(lib);
- // libmono must always be statically linked, for other librarires we can use dylibs
- bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib");
-
- if (useNativeAOTRuntime)
+ foreach (string lib in dylibs)
{
- // link NativeAOT framework libs without '-force_load'
- toLink += $" {lib}{Environment.NewLine}";
+ toLink += $" \"-force_load {lib}\"{Environment.NewLine}";
}
- else if (forceAOT || !(preferDylibs && dylibExists))
+ }
+ else
+ {
+ // Sort the static libraries to link so the brotli libs are added to the list last (after the compression native libs)
+ List staticLibsToLink = Directory.GetFiles(workspace, "*.a").OrderBy(libName => libName.Contains("brotli") ? 1 : 0).ToList();
+ foreach (string lib in staticLibsToLink)
{
- // these libraries are pinvoked
- // -force_load will be removed once we enable direct-pinvokes for AOT
- toLink += $" \"-force_load {lib}\"{Environment.NewLine}";
+ // all component libs already added to linker.
+ if (allComponentLibs.Any(lib.Contains))
+ continue;
+
+ string libName = Path.GetFileNameWithoutExtension(lib);
+ // libmono must always be statically linked, for other librarires we can use dylibs
+ bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib");
+
+ if (targetRuntime == TargetRuntime.NativeAOT)
+ {
+ // link NativeAOT framework libs without '-force_load'
+ toLink += $" {lib}{Environment.NewLine}";
+ }
+ else if (forceAOT || !(preferDylibs && dylibExists))
+ {
+ // these libraries are pinvoked
+ // -force_load will be removed once we enable direct-pinvokes for AOT
+ toLink += $" \"-force_load {lib}\"{Environment.NewLine}";
+ }
}
}
@@ -463,7 +477,14 @@ public string GenerateCMake(
cmakeLists = cmakeLists.Replace("%EXTRA_LINKER_ARGS%", extraLinkerArgsConcat);
cmakeLists = cmakeLists.Replace("%AotSources%", aotSources);
cmakeLists = cmakeLists.Replace("%AotTargetsList%", aotList);
- cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m");
+ if (targetRuntime == TargetRuntime.CoreCLR)
+ {
+ cmakeLists = cmakeLists.Replace("%AotModulesSource%", "coreclrhost.h");
+ }
+ else
+ {
+ cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m");
+ }
var defines = new StringBuilder();
if (forceInterpreter)
@@ -496,10 +517,14 @@ public string GenerateCMake(
defines.AppendLine($"\nadd_definitions(-DDIAGNOSTIC_PORTS=\"{diagnosticPorts}\")");
}
- if (useNativeAOTRuntime)
+ if (targetRuntime == TargetRuntime.NativeAOT)
{
defines.AppendLine("add_definitions(-DUSE_NATIVE_AOT=1)");
}
+ else if (targetRuntime == TargetRuntime.CoreCLR)
+ {
+ defines.AppendLine("add_definitions(-DCORECLR=1)");
+ }
if (isLibraryMode)
{
@@ -534,30 +559,45 @@ public string GenerateCMake(
File.WriteAllText(Path.Combine(binDir, "runtime-librarymode.h"), Utils.GetEmbeddedResource("runtime-librarymode.h"));
File.WriteAllText(Path.Combine(binDir, "runtime-librarymode.m"), Utils.GetEmbeddedResource("runtime-librarymode.m"));
}
- else if (!useNativeAOTRuntime)
+ else if (targetRuntime != TargetRuntime.NativeAOT)
{
File.WriteAllText(Path.Combine(binDir, "runtime.h"),
Utils.GetEmbeddedResource("runtime.h"));
- // lookup statically linked libraries via dlsym(), see handle_pinvoke_override() in runtime.m
- var pinvokeOverrides = new StringBuilder();
- foreach (string aFile in Directory.GetFiles(workspace, "*.a"))
+ if (targetRuntime == TargetRuntime.MonoVM)
{
- string aFileName = Path.GetFileNameWithoutExtension(aFile);
- pinvokeOverrides.AppendLine($" \"{aFileName}\",");
+ // lookup statically linked libraries via dlsym(), see handle_pinvoke_override() in runtime.m
+ var pinvokeOverrides = new StringBuilder();
+ foreach (string aFile in Directory.GetFiles(workspace, "*.a"))
+ {
+ string aFileName = Path.GetFileNameWithoutExtension(aFile);
+ pinvokeOverrides.AppendLine($" \"{aFileName}\",");
- // also register with or without "lib" prefix
- aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName;
- pinvokeOverrides.AppendLine($" \"{aFileName}\",");
- }
+ // also register with or without "lib" prefix
+ aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName;
+ pinvokeOverrides.AppendLine($" \"{aFileName}\",");
+ }
- pinvokeOverrides.AppendLine($" \"System.Globalization.Native\",");
+ pinvokeOverrides.AppendLine($" \"System.Globalization.Native\",");
- File.WriteAllText(Path.Combine(binDir, "runtime.m"),
- Utils.GetEmbeddedResource("runtime.m")
- .Replace("//%PInvokeOverrideLibraries%", pinvokeOverrides.ToString())
- .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier)
- .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));
+ string runtimeTemplateName = (isLibraryMode) ? "runtime-librarymode.m" : "runtime.m";
+ File.WriteAllText(Path.Combine(binDir, "runtime.m"),
+ Utils.GetEmbeddedResource(runtimeTemplateName)
+ .Replace("//%PInvokeOverrideLibraries%", pinvokeOverrides.ToString())
+ .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier)
+ .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));
+ }
+ else
+ {
+ File.WriteAllText(Path.Combine(binDir, "coreclrhost.h"),
+ Utils.GetEmbeddedResource("coreclrhost.h"));
+
+ // NOTE: Library mode is not supported yet
+ File.WriteAllText(Path.Combine(binDir, "runtime.m"),
+ Utils.GetEmbeddedResource("runtime-coreclr.m")
+ .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier)
+ .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));
+ }
}
File.WriteAllText(Path.Combine(binDir, "util.h"), Utils.GetEmbeddedResource("util.h"));
diff --git a/src/tasks/LibraryBuilder/LibraryBuilder.csproj b/src/tasks/LibraryBuilder/LibraryBuilder.csproj
index 7fa908222541d..da2885a572223 100644
--- a/src/tasks/LibraryBuilder/LibraryBuilder.csproj
+++ b/src/tasks/LibraryBuilder/LibraryBuilder.csproj
@@ -20,6 +20,7 @@
+
diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props
index 2f438eea2fea1..ec537c61c5d9c 100644
--- a/src/tests/Directory.Build.props
+++ b/src/tests/Directory.Build.props
@@ -223,7 +223,8 @@
<_targetOS>$(TargetOS)
<_targetArchitecture>$(TargetArchitecture)
- true
+ NativeAOT
+ CoreCLR
static
true
<_IsApplePlatform Condition="'$(TargetsAppleMobile)' == 'true'">true
diff --git a/src/tests/build.proj b/src/tests/build.proj
index 96b6595c4ba91..12aaff5466a8d 100644
--- a/src/tests/build.proj
+++ b/src/tests/build.proj
@@ -423,8 +423,7 @@
-
-
+
$([System.IO.Path]::GetDirectoryName($([System.IO.Path]::GetDirectoryName($(_CMDDIR)))))
$([System.IO.Path]::GetFileName($(CategoryPath)))
@@ -443,7 +442,10 @@
false
false
+
+
+
@@ -454,6 +456,10 @@
+
+ $(IntermediateOutputPath)\..\$(TestRelativePath)\$(TestName)\native\$(TestName).o
+
+
@@ -488,14 +494,21 @@
Projects="@(RunProj)"
Targets="BuildMonoiOSApp"
BuildInParallel="true"
- Condition="'@(TestDirectories)' != '' and '$(TestBuildMode)' != 'nativeaot'"
+ Condition="'@(TestDirectories)' != '' and '$(RuntimeFlavor)' != 'coreclr'"
+ />
+
+