From af406a752aba13979e2f566b3a061555de9da283 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 25 Jul 2023 17:10:45 +0200 Subject: [PATCH 01/11] Make it possible to compile CoreCLR on iOS-like platforms with './build.sh clr+clr.nativeaotlibs+libs+packs -os [iossimulator/maccatalyst/ios] -arch arm64 -cross' Build the singlefilehost even if we don't currently use it Make coreclrhost.h compatible v C(not++) Fix TargetOS::IsMacOS WIP: AppleAppBuilder support for CoreCLR Make the sample app working: dotnet publish src/mono/sample/iOS/Program.csproj -c Release /p:TargetOS=iossimulator /p:TargetArchitecture=arm64 /p:AppleAppBuilderRuntime=CoreCLR /p:DeployAndRun=true /p:UseMonoRuntime=false /p:RunAOTCompilation=false /p:MonoForceInterpreter=false Cleanup Update src/tasks/AppleAppBuilder/AppleAppBuilder.csproj Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com> Use sys_icache_invalidate for all iOS-like platforms Consolidate macOS-only entrypoints in a single #if block Apply feedback Fix jitinterface cross-build Infer AppleAppBuilderRuntime from UseMonoRuntime and UseNativeAOTRuntime Minor changes to test infrastructure Add basic documentation Add nearly complete support for building runtime tests Fix building seh-unwind with older iOS SDK Use enum for TargetRuntime in AppleAppBuilder Fix LibraryBuilder build Cleanup Fix after rebase Revert accidental change Fix tvOS build Drop CoreCLR tvOS Simulator support for now --- docs/workflow/building/coreclr/ios.md | 33 ++++ eng/Subsets.props | 6 +- ...Reflection.ReadyToRun.Experimental.pkgproj | 2 +- src/coreclr/CMakeLists.txt | 21 ++- src/coreclr/debug/daccess/CMakeLists.txt | 6 +- src/coreclr/dlls/mscordac/CMakeLists.txt | 4 +- .../dlls/mscoree/coreclr/CMakeLists.txt | 3 + src/coreclr/hosts/inc/coreclrhost.h | 6 + src/coreclr/inc/crosscomp.h | 6 +- src/coreclr/inc/executableallocator.h | 4 +- src/coreclr/inc/targetosarch.h | 2 +- src/coreclr/jit/CMakeLists.txt | 2 +- src/coreclr/minipal/Unix/doublemapping.cpp | 34 ++-- src/coreclr/pal/inc/pal.h | 4 +- src/coreclr/pal/src/CMakeLists.txt | 21 ++- src/coreclr/pal/src/configure.cmake | 6 +- src/coreclr/pal/src/debug/debug.cpp | 2 + src/coreclr/pal/src/exception/seh-unwind.cpp | 12 +- src/coreclr/pal/src/include/pal/context.h | 16 +- src/coreclr/pal/src/include/pal/dbgmsg.h | 6 +- src/coreclr/pal/src/map/virtual.cpp | 30 +++- src/coreclr/pal/src/misc/dbgmsg.cpp | 4 +- src/coreclr/pal/src/misc/sysinfo.cpp | 6 +- src/coreclr/pal/src/thread/context.cpp | 29 ++-- src/coreclr/pal/src/thread/process.cpp | 16 +- .../ObjectWriter/TargetExtensions.cs | 5 + .../aot/crossgen2/Crossgen2RootCommand.cs | 2 +- .../tools/aot/jitinterface/jitwrapper.cpp | 4 + src/coreclr/utilcode/executableallocator.cpp | 4 +- src/coreclr/vm/amd64/asmhelpers.S | 6 +- src/coreclr/vm/amd64/jithelpers_fast.S | 2 +- src/coreclr/vm/arm64/asmhelpers.S | 8 +- src/coreclr/vm/arm64/stubs.cpp | 4 +- src/coreclr/vm/cdacplatformmetadata.cpp | 2 +- src/coreclr/vm/comdelegate.cpp | 2 +- src/coreclr/vm/jitinterface.cpp | 2 +- src/coreclr/vm/threads.h | 2 +- src/coreclr/vm/threadstatics.cpp | 14 +- .../Directory.Build.props | 1 + .../apple/build/AppleBuild.InTree.targets | 9 + src/mono/msbuild/apple/build/AppleBuild.props | 10 +- .../msbuild/apple/build/AppleBuild.targets | 14 +- .../corehost/apphost/static/CMakeLists.txt | 8 +- src/native/corehost/hostmisc/pal.h | 2 +- .../hostpolicy/hostpolicy_context.cpp | 4 +- src/native/external/libunwind.cmake | 4 +- .../external/libunwind_extras/CMakeLists.txt | 10 +- .../CMakeLists.txt | 6 + src/native/libs/System.Native/CMakeLists.txt | 2 +- src/native/libs/System.Native/entrypoints.c | 2 + .../System.Net.Security.Native/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- .../entrypoints.c | 46 ++--- src/native/libs/configure.cmake | 2 +- src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 40 +++-- .../AppleAppBuilder/AppleAppBuilder.csproj | 2 + src/tasks/AppleAppBuilder/TargetRuntime.cs | 9 + .../Templates/CMakeLists.txt.template | 2 +- .../Templates/runtime-coreclr.m | 161 ++++++++++++++++++ src/tasks/AppleAppBuilder/Xcode.cs | 125 +++++++++----- .../LibraryBuilder/LibraryBuilder.csproj | 1 + src/tests/Directory.Build.props | 3 +- src/tests/build.proj | 21 ++- 63 files changed, 600 insertions(+), 226 deletions(-) create mode 100644 docs/workflow/building/coreclr/ios.md create mode 100644 src/tasks/AppleAppBuilder/TargetRuntime.cs create mode 100644 src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m 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 a50fd3e80025e..6ec519ba2945d 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..199f478af17c9 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() @@ -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..2988ea0452acf 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -19,9 +19,15 @@ // 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) +#ifdef __cplusplus #define CORECLR_HOSTING_API(function, ...) \ extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) +#else +#define CORECLR_HOSTING_API(function, ...) \ + int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ + typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) +#endif // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index 10a196302f35e..b3d504903ff9e 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 67d516fb322a5..54fe6c816698b 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); @@ -71,25 +71,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; @@ -120,7 +120,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) { @@ -134,7 +134,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs } void* result = PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(rangeStart, rangeEnd, size, 0 /* fStoreAllocationInfo */); -#ifndef TARGET_OSX +#ifndef TARGET_APPLE if (result != NULL) { // Map the shared memory over the range reserved from the executable memory allocator. @@ -145,7 +145,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) @@ -153,7 +153,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs return result; } -#ifndef TARGET_OSX +#ifndef TARGET_APPLE result = mmap(NULL, size, PROT_NONE, MAP_SHARED, fd, offset); #else int mmapFlags = MAP_ANON | MAP_PRIVATE; @@ -183,20 +183,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) @@ -204,7 +204,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; @@ -229,7 +229,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 48631c96621ec..cf5e83889fe0d 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -2939,14 +2939,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 0a3ed749f29fb..bff3edaa818d2 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,18 @@ if(CLR_CMAKE_TARGET_OSX) if(CLR_CMAKE_HOST_ARCH_AMD64) add_definitions(-DXSTATE_SUPPORTED) endif() +endif() + +if(CLR_CMAKE_TARGET_APPLE) + add_definitions(-DTARGET_APPLE) + add_definitions(-D_XOPEN_SOURCE) 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 +121,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") @@ -222,7 +227,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 @@ -244,7 +249,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 79140466b97d5..df1d3abd2dfd8 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") @@ -888,7 +888,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))") @@ -927,7 +927,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..04a12b6956b50 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(TARGET_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(TARGET_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(TARGET_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(TARGET_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(TARGET_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(TARGET_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..f769da2a61550 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(TARGET_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 && !TARGET_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(TARGET_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 // TARGET_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 // TARGET_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 TARGET_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 //TARGET_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 // TARGET_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..a5b04430d410e 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -39,12 +39,17 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d #include #include #include +#include #if HAVE_VM_ALLOCATE #include #include #endif // HAVE_VM_ALLOCATE +#if defined(TARGET_APPLE) && !defined(TARGET_OSX) +#include +#endif + using namespace CorUnix; CRITICAL_SECTION virtual_critsec; @@ -1234,7 +1239,30 @@ VirtualProtect( return bRetVal; } -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) + +#if defined(TARGET_APPLE) && !defined(TARGET_OSX) + +void +(*jit_write_protect_np)(int enabled); + +static struct jit_write_protect_helper +{ + jit_write_protect_helper() + { + 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" ); + exit(1); + } + } +} jit_write_protect_helper; + +#define pthread_jit_write_protect_np jit_write_protect_np + +#endif + PALAPI VOID PAL_JitWriteProtect(bool writeEnable) { thread_local int enabledCount = 0; 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..e0f8af8c6e7c2 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(TARGET_APPLE) #include #include #include #include -#endif // defined(TARGET_OSX) +#endif // defined(TARGET_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..e3c33c7468673 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(TARGET_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 && !TARGET_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 TARGET_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 // TARGET_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 // TARGET_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(TARGET_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 && !TARGET_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(TARGET_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 && !TARGET_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 TARGET_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 // TARGET_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 // TARGET_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 2e22f22b5ae6e..090ac4df71660 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" @@ -234,7 +232,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 @@ -2219,6 +2217,9 @@ PROCCreateCrashDump( INT cbErrorMessageBuffer, bool serialize) { +#if defined(TARGET_IOS) + return FALSE; +#else _ASSERTE(argv.size() > 0); _ASSERTE(errorMessageBuffer == nullptr || cbErrorMessageBuffer > 0); @@ -2343,6 +2344,7 @@ PROCCreateCrashDump( } } return true; +#endif // !TARGET_IOS } /*++ @@ -2613,7 +2615,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)); @@ -2643,7 +2645,7 @@ InitializeFlushProcessWriteBuffers() } return status == 0; -#endif // TARGET_OSX +#endif // TARGET_APPLE } #define FATAL_ASSERT(e, msg) \ @@ -2693,7 +2695,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; @@ -2722,7 +2724,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 6cf5a7ec84589..9e5a44af11e62 100644 --- a/src/coreclr/vm/arm64/stubs.cpp +++ b/src/coreclr/vm/arm64/stubs.cpp @@ -1370,7 +1370,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); @@ -1386,7 +1386,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 205c5105d5a2d..e5681a89a8f7e 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 2e125d4ddd78b..3c0124ccbeea4 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 2cd3cf685d335..0d32b493702a0 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 463bcac8622e9..1a0a28c1187f0 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) - + @@ -297,8 +297,15 @@ + + + NativeAOT + CoreCLR + MonoVM + + UseConsoleUITemplate="$(UseConsoleUITemplate)"> diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index c013b3fcce0d7..4565d4423dc06 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -167,7 +167,6 @@ else() System.IO.Compression.Native-Static System.Net.Security.Native-Static System.Native-Static - System.Security.Cryptography.Native.OpenSsl-Static coreclrpal_dac corguids @@ -176,6 +175,10 @@ else() nativeresourcestring ) + if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) + LIST(APPEND NATIVE_LIBS System.Security.Cryptography.Native.OpenSsl-Static) + endif() + # additional requirements for System.IO.Compression.Native include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) append_extra_compression_libs(NATIVE_LIBS) @@ -197,7 +200,6 @@ else() endif() set(RUNTIMEINFO_LIB runtimeinfo) - endif() if(CLR_CMAKE_TARGET_APPLE) @@ -215,13 +217,11 @@ endif() # if(CLR_CMAKE_TARGET_APPLE) find_library(COREFOUNDATION CoreFoundation) - find_library(CORESERVICES CoreServices) find_library(SECURITY Security) find_library(SYSTEM System) LIST(APPEND NATIVE_LIBS ${COREFOUNDATION} - ${CORESERVICES} ${SECURITY} ${SYSTEM} ) diff --git a/src/native/corehost/hostmisc/pal.h b/src/native/corehost/hostmisc/pal.h index bde8446cc22cd..0c1f1b2d787c5 100644 --- a/src/native/corehost/hostmisc/pal.h +++ b/src/native/corehost/hostmisc/pal.h @@ -71,7 +71,7 @@ #if defined(TARGET_WINDOWS) #define LIB_PREFIX "" #define LIB_FILE_EXT ".dll" -#elif defined(TARGET_OSX) +#elif defined(TARGET_APPLE) #define LIB_PREFIX "lib" #define LIB_FILE_EXT ".dylib" #else diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 63ef9cdbc0d32..01956d5dc75d8 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -70,10 +70,12 @@ namespace return SystemResolveDllImport(entry_point_name); } +#if !defined(TARGET_APPLE) || defined(TARGET_OSX) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.OpenSsl")) == 0) { return CryptoResolveDllImport(entry_point_name); } +#endif #endif if (strcmp(library_name, LIB_NAME("System.IO.Compression.Native")) == 0) @@ -95,7 +97,7 @@ namespace } } -#if defined(TARGET_OSX) +#if defined(TARGET_APPLE) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.Apple")) == 0) { return CryptoAppleResolveDllImport(entry_point_name); 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/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 07080ea9056bb..1cdc1cb923178 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -188,6 +188,12 @@ add_library(System.Globalization.Native-Static entrypoints.c ) +if (DEFINED CMAKE_ICU_DIR) + include_directories(${CMAKE_ICU_DIR}/include) + target_link_libraries(System.Globalization.Native-Static ${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) + target_link_libraries(System.Globalization.Native-Static stdc++) +endif() + if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) set_target_properties(System.Globalization.Native-Static PROPERTIES OUTPUT_NAME System.Globalization.Native CLEAN_DIRECT_OUTPUT 1) endif() diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 7712f25560202..8dbbf14d90f53 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -126,7 +126,7 @@ if (GEN_SHARED_LIB) install_with_stripped_symbols (System.Native PROGRAMS .) endif () -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVE_SOURCES ${NATIVE_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Native/entrypoints.c b/src/native/libs/System.Native/entrypoints.c index fcde21046a7c4..8323336347fb1 100644 --- a/src/native/libs/System.Native/entrypoints.c +++ b/src/native/libs/System.Native/entrypoints.c @@ -34,6 +34,7 @@ static const Entry s_sysNative[] = { DllImportEntry(SystemNative_FStat) +#if !defined(TARGET_APPLE) || defined(TARGET_OSX) DllImportEntry(SystemNative_GetWindowSize) DllImportEntry(SystemNative_IsATty) DllImportEntry(SystemNative_InitializeTerminalAndSignalHandling) @@ -46,6 +47,7 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_ReadStdin) DllImportEntry(SystemNative_GetSignalForBreak) DllImportEntry(SystemNative_SetSignalForBreak) +#endif DllImportEntry(SystemNative_GetSystemTimeAsTicks) DllImportEntry(SystemNative_GetDefaultTimeZone) DllImportEntry(SystemNative_GetTimeZoneData) diff --git a/src/native/libs/System.Net.Security.Native/CMakeLists.txt b/src/native/libs/System.Net.Security.Native/CMakeLists.txt index b0e02f41509b5..e8efae3d33a79 100644 --- a/src/native/libs/System.Net.Security.Native/CMakeLists.txt +++ b/src/native/libs/System.Net.Security.Native/CMakeLists.txt @@ -19,7 +19,7 @@ if (GEN_SHARED_LIB) ) endif() -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVEGSS_SOURCES ${NATIVEGSS_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index 84615493f4495..daba219facad9 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -105,7 +105,7 @@ if (GEN_SHARED_LIB) ) endif() -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +if (NOT GEN_SHARED_LIB) set(NATIVECRYPTO_SOURCES ${NATIVECRYPTO_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c index 5163aa5b12123..ea70c53b30477 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c @@ -8,7 +8,6 @@ #include "pal_ecc.h" #include "pal_hmac.h" #include "pal_keyagree.h" -#include "pal_keychain_macos.h" #include "pal_keyderivation.h" #include "pal_random.h" #include "pal_rsa.h" @@ -19,10 +18,16 @@ #include "pal_ssl.h" #include "pal_swiftbindings.h" #include "pal_symmetric.h" -#include "pal_trust_macos.h" #include "pal_x509.h" -#include "pal_x509_macos.h" #include "pal_x509chain.h" +#if defined(TARGET_OSX) +#include "pal_trust_macos.h" +#include "pal_keychain_macos.h" +#include "pal_x509_macos.h" +#else +#include "pal_keychain_ios.h" +#include "pal_x509_ios.h" +#endif static const Entry s_cryptoAppleNative[] = { @@ -31,6 +36,7 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Encrypt) DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Decrypt) DllImportEntry(AppleCryptoNative_DigestClone) + DllImportEntry(AppleCryptoNative_DigestFree) DllImportEntry(AppleCryptoNative_DigestCreate) DllImportEntry(AppleCryptoNative_DigestCurrent) DllImportEntry(AppleCryptoNative_DigestFinal) @@ -51,15 +57,8 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_HmacOneShot) DllImportEntry(AppleCryptoNative_HmacUpdate) DllImportEntry(AppleCryptoNative_IsAuthenticationFailure) - DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) - DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) - DllImportEntry(AppleCryptoNative_SecKeychainCreate) - DllImportEntry(AppleCryptoNative_SecKeychainDelete) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateCerts) - DllImportEntry(AppleCryptoNative_SecKeychainOpen) - DllImportEntry(AppleCryptoNative_SecKeychainUnlock) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateIdentities) - DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) DllImportEntry(AppleCryptoNative_SslCopyCADistinguishedNames) DllImportEntry(AppleCryptoNative_SslCopyCertChain) DllImportEntry(AppleCryptoNative_SslIsHostnameMatch) @@ -80,8 +79,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_RsaEncryptionPrimitive) DllImportEntry(AppleCryptoNative_RsaVerificationPrimitive) DllImportEntry(AppleCryptoNative_SecCopyErrorMessageString) - DllImportEntry(AppleCryptoNative_SecKeyExport) - DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) DllImportEntry(AppleCryptoNative_SecKeyGetSimpleKeySizeInBytes) DllImportEntry(AppleCryptoNative_SecKeyCreateSignature) DllImportEntry(AppleCryptoNative_SecKeyVerifySignature) @@ -108,10 +105,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_CryptorCreate) DllImportEntry(AppleCryptoNative_CryptorUpdate) DllImportEntry(AppleCryptoNative_CryptorReset) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) DllImportEntry(AppleCryptoNative_X509ChainCreate) DllImportEntry(AppleCryptoNative_X509DemuxAndRetainHandle) DllImportEntry(AppleCryptoNative_X509GetContentType) @@ -120,10 +113,7 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509CopyPrivateKeyFromIdentity) DllImportEntry(AppleCryptoNative_X509ImportCollection) DllImportEntry(AppleCryptoNative_X509ImportCertificate) - DllImportEntry(AppleCryptoNative_X509ExportData) DllImportEntry(AppleCryptoNative_X509GetRawData) - DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) - DllImportEntry(AppleCryptoNative_X509MoveToKeychain) DllImportEntry(AppleCryptoNative_X509ChainCreateDefaultPolicy) DllImportEntry(AppleCryptoNative_X509ChainCreateRevocationPolicy) DllImportEntry(AppleCryptoNative_X509ChainEvaluate) @@ -137,6 +127,24 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509StoreRemoveCertificate) DllImportEntry(AppleCryptoNative_Pbkdf2) DllImportEntry(AppleCryptoNative_X509GetSubjectSummary) +#ifdef TARGET_OSX + DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) + DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) + DllImportEntry(AppleCryptoNative_SecKeychainCreate) + DllImportEntry(AppleCryptoNative_SecKeychainDelete) + DllImportEntry(AppleCryptoNative_SecKeychainOpen) + DllImportEntry(AppleCryptoNative_SecKeychainUnlock) + DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) + DllImportEntry(AppleCryptoNative_SecKeyExport) + DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) + DllImportEntry(AppleCryptoNative_X509ExportData) + DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) + DllImportEntry(AppleCryptoNative_X509MoveToKeychain) +#endif }; EXTERN_C const void* CryptoAppleResolveDllImport(const char* name); 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..9635fe02dc22d 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,18 @@ public override bool Execute() extraLinkerArgs.Add(item.ItemSpec); } + if (targetRuntime == TargetRuntime.CoreCLR) + { + 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 +358,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 141a8f3edad0a..5d3a72acc04fe 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 aed4bf7dfaeba..733e766d18b35 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,26 +412,36 @@ public string GenerateCMake( } string[] dylibs = Directory.GetFiles(workspace, "*.dylib"); - foreach (string lib in Directory.GetFiles(workspace, "*.a")) + 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 + { + foreach (string lib in Directory.GetFiles(workspace, "*.a")) { - // 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}"; + } } } @@ -460,7 +475,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) @@ -493,10 +515,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) { @@ -531,30 +557,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'" + /> + + From 7b5c2a32e335d603d8773c593a227073c6e7da9d Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 18 Nov 2024 14:05:54 +0100 Subject: [PATCH 02/11] Fix rpath on MacCatalyst --- src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 9635fe02dc22d..2c1304b0dc360 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -323,7 +323,14 @@ public override bool Execute() if (targetRuntime == TargetRuntime.CoreCLR) { - extraLinkerArgs.Add("-rpath @executable_path"); + if (targetOS == TargetNames.MacCatalyst) + { + extraLinkerArgs.Add("-rpath @executable_path/../Resources"); + } + else + { + extraLinkerArgs.Add("-rpath @executable_path"); + } shouldStaticLink = false; } From a9185986bbacf19d3045441b0c3b4049cdd08b47 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 18 Nov 2024 17:35:04 +0100 Subject: [PATCH 03/11] Apply suggestions from code review Co-authored-by: Aaron Robinson --- src/coreclr/pal/src/map/virtual.cpp | 2 +- src/native/corehost/hostpolicy/hostpolicy_context.cpp | 2 +- src/native/libs/System.Native/entrypoints.c | 2 +- .../System.Security.Cryptography.Native.Apple/entrypoints.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index a5b04430d410e..63f29be003f2e 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -1261,7 +1261,7 @@ static struct jit_write_protect_helper #define pthread_jit_write_protect_np jit_write_protect_np -#endif +#endif // defined(TARGET_APPLE) && !defined(TARGET_OSX) PALAPI VOID PAL_JitWriteProtect(bool writeEnable) { diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 01956d5dc75d8..351fc02377c74 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -75,7 +75,7 @@ namespace { return CryptoResolveDllImport(entry_point_name); } -#endif +#endif // !defined(TARGET_APPLE) || defined(TARGET_OSX) #endif if (strcmp(library_name, LIB_NAME("System.IO.Compression.Native")) == 0) diff --git a/src/native/libs/System.Native/entrypoints.c b/src/native/libs/System.Native/entrypoints.c index 8323336347fb1..1b88a3dca2e56 100644 --- a/src/native/libs/System.Native/entrypoints.c +++ b/src/native/libs/System.Native/entrypoints.c @@ -47,7 +47,7 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_ReadStdin) DllImportEntry(SystemNative_GetSignalForBreak) DllImportEntry(SystemNative_SetSignalForBreak) -#endif +#endif // !defined(TARGET_APPLE) || defined(TARGET_OSX) DllImportEntry(SystemNative_GetSystemTimeAsTicks) DllImportEntry(SystemNative_GetDefaultTimeZone) DllImportEntry(SystemNative_GetTimeZoneData) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c index ea70c53b30477..9be3ea855a82a 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c @@ -27,7 +27,7 @@ #else #include "pal_keychain_ios.h" #include "pal_x509_ios.h" -#endif +#endif // defined(TARGET_OSX) static const Entry s_cryptoAppleNative[] = { @@ -144,7 +144,7 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509ExportData) DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) DllImportEntry(AppleCryptoNative_X509MoveToKeychain) -#endif +#endif // defined(TARGET_OSX) }; EXTERN_C const void* CryptoAppleResolveDllImport(const char* name); From 078e390c1f57ae63b6b0f4b115875bb2b196dbb7 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 19 Nov 2024 09:30:25 +0100 Subject: [PATCH 04/11] Use CORECLR_HOSTING_API_LINKAGE for extern 'C' --- src/coreclr/hosts/inc/coreclrhost.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 2988ea0452acf..8c85a1b5276ba 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -14,20 +14,20 @@ #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) -#ifdef __cplusplus #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__) -#else -#define CORECLR_HOSTING_API(function, ...) \ - int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ - typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) -#endif // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain From eed27009b6dc889d1d3712a5ed6803ce26e70da8 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 19 Nov 2024 09:31:13 +0100 Subject: [PATCH 05/11] Remove extra #include --- src/coreclr/pal/src/map/virtual.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index 63f29be003f2e..16a4a946fc3dc 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -46,10 +46,6 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d #include #endif // HAVE_VM_ALLOCATE -#if defined(TARGET_APPLE) && !defined(TARGET_OSX) -#include -#endif - using namespace CorUnix; CRITICAL_SECTION virtual_critsec; From 7397eea602973be6e6159e5b2bcb890bde58c197 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 19 Nov 2024 09:39:59 +0100 Subject: [PATCH 06/11] Drop ICU linkage (not needed with Hybrid Globalization) --- src/native/libs/System.Globalization.Native/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 1cdc1cb923178..07080ea9056bb 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -188,12 +188,6 @@ add_library(System.Globalization.Native-Static entrypoints.c ) -if (DEFINED CMAKE_ICU_DIR) - include_directories(${CMAKE_ICU_DIR}/include) - target_link_libraries(System.Globalization.Native-Static ${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) - target_link_libraries(System.Globalization.Native-Static stdc++) -endif() - if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) set_target_properties(System.Globalization.Native-Static PROPERTIES OUTPUT_NAME System.Globalization.Native CLEAN_DIRECT_OUTPUT 1) endif() From 5fe0ed4293e2bfd4713a3be34a46e52bd5f2f8da Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 19 Nov 2024 10:11:23 +0100 Subject: [PATCH 07/11] Move jit_write_protect_np initialization --- src/coreclr/pal/src/map/virtual.cpp | 39 +++++++++++------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index 16a4a946fc3dc..aa02c81a1514b 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -55,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 @@ -179,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; } @@ -1236,29 +1250,6 @@ VirtualProtect( } #if defined(HOST_APPLE) && defined(HOST_ARM64) - -#if defined(TARGET_APPLE) && !defined(TARGET_OSX) - -void -(*jit_write_protect_np)(int enabled); - -static struct jit_write_protect_helper -{ - jit_write_protect_helper() - { - 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" ); - exit(1); - } - } -} jit_write_protect_helper; - -#define pthread_jit_write_protect_np jit_write_protect_np - -#endif // defined(TARGET_APPLE) && !defined(TARGET_OSX) - PALAPI VOID PAL_JitWriteProtect(bool writeEnable) { thread_local int enabledCount = 0; @@ -1278,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 //--------------------------------------------------------------------------------------- From 44fe9c51cd125eb81a676b4e90889ef4b849d017 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 29 Nov 2024 19:45:22 +0100 Subject: [PATCH 08/11] Use __APPLE__ in PAL instead of TARGET_APPLE for consistency --- src/coreclr/pal/src/CMakeLists.txt | 1 - src/coreclr/pal/src/exception/seh-unwind.cpp | 12 +++++----- src/coreclr/pal/src/include/pal/context.h | 16 ++++++------- src/coreclr/pal/src/misc/sysinfo.cpp | 4 ++-- src/coreclr/pal/src/thread/context.cpp | 24 ++++++++++---------- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index bff3edaa818d2..5f8c27da9a506 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -73,7 +73,6 @@ if(CLR_CMAKE_TARGET_OSX) endif() if(CLR_CMAKE_TARGET_APPLE) - add_definitions(-DTARGET_APPLE) add_definitions(-D_XOPEN_SOURCE) set(PLATFORM_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/context.S diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index 04a12b6956b50..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_APPLE) && 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_APPLE) && 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_APPLE) +#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_APPLE) +#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_APPLE) && 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_APPLE) && 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 f769da2a61550..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_APPLE) +#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_APPLE +#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_APPLE) // 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_APPLE +#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_APPLE +#endif // __APPLE__ #elif defined(HOST_LOONGARCH64) @@ -882,7 +882,7 @@ const _STRUCT_ARM_NEON_STATE64* GetConstNativeSigSimdContext(const native_contex #else // HOST_ARM64 -#ifdef TARGET_APPLE +#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_APPLE +#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_APPLE +#endif // __APPLE__ #endif // HOST_ARM64 #else // HOST_64BIT diff --git a/src/coreclr/pal/src/misc/sysinfo.cpp b/src/coreclr/pal/src/misc/sysinfo.cpp index e0f8af8c6e7c2..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_APPLE) +#if defined(__APPLE__) #include #include #include #include -#endif // defined(TARGET_APPLE) +#endif // defined(__APPLE__) #ifdef __HAIKU__ #include diff --git a/src/coreclr/pal/src/thread/context.cpp b/src/coreclr/pal/src/thread/context.cpp index e3c33c7468673..feff4b8915f7f 100644 --- a/src/coreclr/pal/src/thread/context.cpp +++ b/src/coreclr/pal/src/thread/context.cpp @@ -725,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_APPLE) && !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) || @@ -733,7 +733,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) { GetNativeSigSimdContext(native, &fp, &sve); } -#endif // HOST_ARM64 && !TARGET_APPLE && !TARGET_FREEBSD +#endif // HOST_ARM64 && !__APPLE__ && !TARGET_FREEBSD if ((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) { @@ -763,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_APPLE +#ifdef __APPLE__ _STRUCT_ARM_NEON_STATE64* fp = GetNativeSigSimdContext(native); fp->__fpsr = lpContext->Fpsr; fp->__fpcr = lpContext->Fpcr; @@ -782,7 +782,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) *(NEON128*) &fp->fp_q[i] = lpContext->V[i]; } } -#else // TARGET_APPLE +#else // __APPLE__ if (fp) { fp->fpsr = lpContext->Fpsr; @@ -792,7 +792,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) *(NEON128*) &fp->vregs[i] = lpContext->V[i]; } } -#endif // TARGET_APPLE +#endif // __APPLE__ #elif defined(HOST_ARM) VfpSigFrame* fp = GetNativeSigSimdContext(native); if (fp) @@ -920,7 +920,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) } -#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(TARGET_APPLE) +#if defined(HOST_64BIT) && defined(HOST_ARM64) && !defined(TARGET_FREEBSD) && !defined(__APPLE__) /*++ Function : _GetNativeSigSimdContext @@ -1010,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_APPLE +#endif // HOST_64BIT && HOST_ARM64 && !TARGET_FREEBSD && !__APPLE__ /*++ Function : @@ -1077,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_APPLE) && !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) || @@ -1085,7 +1085,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex { GetConstNativeSigSimdContext(native, &fp, &sve); } -#endif // HOST_ARM64 && !TARGET_APPLE && !TARGET_FREEBSD +#endif // HOST_ARM64 && !__APPLE__ && !TARGET_FREEBSD if ((contextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) { @@ -1114,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_APPLE +#ifdef __APPLE__ const _STRUCT_ARM_NEON_STATE64* fp = GetConstNativeSigSimdContext(native); lpContext->Fpsr = fp->__fpsr; lpContext->Fpcr = fp->__fpcr; @@ -1133,7 +1133,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex lpContext->V[i] = *(NEON128*) &fp->fp_q[i]; } } -#else // TARGET_APPLE +#else // __APPLE__ if (fp) { lpContext->Fpsr = fp->fpsr; @@ -1143,7 +1143,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex lpContext->V[i] = *(NEON128*) &fp->vregs[i]; } } -#endif // TARGET_APPLE +#endif // __APPLE__ #elif defined(HOST_ARM) const VfpSigFrame* fp = GetConstNativeSigSimdContext(native); if (fp) From 780667b520dc8b3f9401861e3aa5d0b4c66615f8 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 30 Nov 2024 13:42:18 +0100 Subject: [PATCH 09/11] Revert changes to native libs and exclude singlefilehost --- src/coreclr/CMakeLists.txt | 2 +- src/native/libs/System.Native/CMakeLists.txt | 2 +- src/native/libs/System.Native/entrypoints.c | 2 - .../System.Net.Security.Native/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- .../entrypoints.c | 46 ++++++++----------- 6 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 199f478af17c9..bc093f7270ccd 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -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) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 8dbbf14d90f53..7712f25560202 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -126,7 +126,7 @@ if (GEN_SHARED_LIB) install_with_stripped_symbols (System.Native PROGRAMS .) endif () -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVE_SOURCES ${NATIVE_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Native/entrypoints.c b/src/native/libs/System.Native/entrypoints.c index 1b88a3dca2e56..fcde21046a7c4 100644 --- a/src/native/libs/System.Native/entrypoints.c +++ b/src/native/libs/System.Native/entrypoints.c @@ -34,7 +34,6 @@ static const Entry s_sysNative[] = { DllImportEntry(SystemNative_FStat) -#if !defined(TARGET_APPLE) || defined(TARGET_OSX) DllImportEntry(SystemNative_GetWindowSize) DllImportEntry(SystemNative_IsATty) DllImportEntry(SystemNative_InitializeTerminalAndSignalHandling) @@ -47,7 +46,6 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_ReadStdin) DllImportEntry(SystemNative_GetSignalForBreak) DllImportEntry(SystemNative_SetSignalForBreak) -#endif // !defined(TARGET_APPLE) || defined(TARGET_OSX) DllImportEntry(SystemNative_GetSystemTimeAsTicks) DllImportEntry(SystemNative_GetDefaultTimeZone) DllImportEntry(SystemNative_GetTimeZoneData) diff --git a/src/native/libs/System.Net.Security.Native/CMakeLists.txt b/src/native/libs/System.Net.Security.Native/CMakeLists.txt index e8efae3d33a79..b0e02f41509b5 100644 --- a/src/native/libs/System.Net.Security.Native/CMakeLists.txt +++ b/src/native/libs/System.Net.Security.Native/CMakeLists.txt @@ -19,7 +19,7 @@ if (GEN_SHARED_LIB) ) endif() -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVEGSS_SOURCES ${NATIVEGSS_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index daba219facad9..84615493f4495 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -105,7 +105,7 @@ if (GEN_SHARED_LIB) ) endif() -if (NOT GEN_SHARED_LIB) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) set(NATIVECRYPTO_SOURCES ${NATIVECRYPTO_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c index 9be3ea855a82a..5163aa5b12123 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c @@ -8,6 +8,7 @@ #include "pal_ecc.h" #include "pal_hmac.h" #include "pal_keyagree.h" +#include "pal_keychain_macos.h" #include "pal_keyderivation.h" #include "pal_random.h" #include "pal_rsa.h" @@ -18,16 +19,10 @@ #include "pal_ssl.h" #include "pal_swiftbindings.h" #include "pal_symmetric.h" -#include "pal_x509.h" -#include "pal_x509chain.h" -#if defined(TARGET_OSX) #include "pal_trust_macos.h" -#include "pal_keychain_macos.h" +#include "pal_x509.h" #include "pal_x509_macos.h" -#else -#include "pal_keychain_ios.h" -#include "pal_x509_ios.h" -#endif // defined(TARGET_OSX) +#include "pal_x509chain.h" static const Entry s_cryptoAppleNative[] = { @@ -36,7 +31,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Encrypt) DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Decrypt) DllImportEntry(AppleCryptoNative_DigestClone) - DllImportEntry(AppleCryptoNative_DigestFree) DllImportEntry(AppleCryptoNative_DigestCreate) DllImportEntry(AppleCryptoNative_DigestCurrent) DllImportEntry(AppleCryptoNative_DigestFinal) @@ -57,8 +51,15 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_HmacOneShot) DllImportEntry(AppleCryptoNative_HmacUpdate) DllImportEntry(AppleCryptoNative_IsAuthenticationFailure) + DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) + DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) + DllImportEntry(AppleCryptoNative_SecKeychainCreate) + DllImportEntry(AppleCryptoNative_SecKeychainDelete) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateCerts) + DllImportEntry(AppleCryptoNative_SecKeychainOpen) + DllImportEntry(AppleCryptoNative_SecKeychainUnlock) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateIdentities) + DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) DllImportEntry(AppleCryptoNative_SslCopyCADistinguishedNames) DllImportEntry(AppleCryptoNative_SslCopyCertChain) DllImportEntry(AppleCryptoNative_SslIsHostnameMatch) @@ -79,6 +80,8 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_RsaEncryptionPrimitive) DllImportEntry(AppleCryptoNative_RsaVerificationPrimitive) DllImportEntry(AppleCryptoNative_SecCopyErrorMessageString) + DllImportEntry(AppleCryptoNative_SecKeyExport) + DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) DllImportEntry(AppleCryptoNative_SecKeyGetSimpleKeySizeInBytes) DllImportEntry(AppleCryptoNative_SecKeyCreateSignature) DllImportEntry(AppleCryptoNative_SecKeyVerifySignature) @@ -105,6 +108,10 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_CryptorCreate) DllImportEntry(AppleCryptoNative_CryptorUpdate) DllImportEntry(AppleCryptoNative_CryptorReset) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) DllImportEntry(AppleCryptoNative_X509ChainCreate) DllImportEntry(AppleCryptoNative_X509DemuxAndRetainHandle) DllImportEntry(AppleCryptoNative_X509GetContentType) @@ -113,7 +120,10 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509CopyPrivateKeyFromIdentity) DllImportEntry(AppleCryptoNative_X509ImportCollection) DllImportEntry(AppleCryptoNative_X509ImportCertificate) + DllImportEntry(AppleCryptoNative_X509ExportData) DllImportEntry(AppleCryptoNative_X509GetRawData) + DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) + DllImportEntry(AppleCryptoNative_X509MoveToKeychain) DllImportEntry(AppleCryptoNative_X509ChainCreateDefaultPolicy) DllImportEntry(AppleCryptoNative_X509ChainCreateRevocationPolicy) DllImportEntry(AppleCryptoNative_X509ChainEvaluate) @@ -127,24 +137,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509StoreRemoveCertificate) DllImportEntry(AppleCryptoNative_Pbkdf2) DllImportEntry(AppleCryptoNative_X509GetSubjectSummary) -#ifdef TARGET_OSX - DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) - DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) - DllImportEntry(AppleCryptoNative_SecKeychainCreate) - DllImportEntry(AppleCryptoNative_SecKeychainDelete) - DllImportEntry(AppleCryptoNative_SecKeychainOpen) - DllImportEntry(AppleCryptoNative_SecKeychainUnlock) - DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) - DllImportEntry(AppleCryptoNative_SecKeyExport) - DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) - DllImportEntry(AppleCryptoNative_X509ExportData) - DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) - DllImportEntry(AppleCryptoNative_X509MoveToKeychain) -#endif // defined(TARGET_OSX) }; EXTERN_C const void* CryptoAppleResolveDllImport(const char* name); From 5451afe86225860a46c4ca06bab74b0c4ba77e22 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 30 Nov 2024 13:49:01 +0100 Subject: [PATCH 10/11] Revert more singlefilehost changes --- src/native/corehost/apphost/static/CMakeLists.txt | 8 ++++---- src/native/corehost/hostmisc/pal.h | 2 +- src/native/corehost/hostpolicy/hostpolicy_context.cpp | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 4565d4423dc06..c013b3fcce0d7 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -167,6 +167,7 @@ else() System.IO.Compression.Native-Static System.Net.Security.Native-Static System.Native-Static + System.Security.Cryptography.Native.OpenSsl-Static coreclrpal_dac corguids @@ -175,10 +176,6 @@ else() nativeresourcestring ) - if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) - LIST(APPEND NATIVE_LIBS System.Security.Cryptography.Native.OpenSsl-Static) - endif() - # additional requirements for System.IO.Compression.Native include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) append_extra_compression_libs(NATIVE_LIBS) @@ -200,6 +197,7 @@ else() endif() set(RUNTIMEINFO_LIB runtimeinfo) + endif() if(CLR_CMAKE_TARGET_APPLE) @@ -217,11 +215,13 @@ endif() # if(CLR_CMAKE_TARGET_APPLE) find_library(COREFOUNDATION CoreFoundation) + find_library(CORESERVICES CoreServices) find_library(SECURITY Security) find_library(SYSTEM System) LIST(APPEND NATIVE_LIBS ${COREFOUNDATION} + ${CORESERVICES} ${SECURITY} ${SYSTEM} ) diff --git a/src/native/corehost/hostmisc/pal.h b/src/native/corehost/hostmisc/pal.h index 0c1f1b2d787c5..bde8446cc22cd 100644 --- a/src/native/corehost/hostmisc/pal.h +++ b/src/native/corehost/hostmisc/pal.h @@ -71,7 +71,7 @@ #if defined(TARGET_WINDOWS) #define LIB_PREFIX "" #define LIB_FILE_EXT ".dll" -#elif defined(TARGET_APPLE) +#elif defined(TARGET_OSX) #define LIB_PREFIX "lib" #define LIB_FILE_EXT ".dylib" #else diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 351fc02377c74..63ef9cdbc0d32 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -70,12 +70,10 @@ namespace return SystemResolveDllImport(entry_point_name); } -#if !defined(TARGET_APPLE) || defined(TARGET_OSX) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.OpenSsl")) == 0) { return CryptoResolveDllImport(entry_point_name); } -#endif // !defined(TARGET_APPLE) || defined(TARGET_OSX) #endif if (strcmp(library_name, LIB_NAME("System.IO.Compression.Native")) == 0) @@ -97,7 +95,7 @@ namespace } } -#if defined(TARGET_APPLE) +#if defined(TARGET_OSX) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.Apple")) == 0) { return CryptoAppleResolveDllImport(entry_point_name); From 0eae3aa955f03ad5719d0def64aed7830b1f4482 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 30 Nov 2024 17:48:34 +0100 Subject: [PATCH 11/11] Remove excessive -D_XOPEN_SOURCE --- src/coreclr/pal/src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 5f8c27da9a506..a37497df7932e 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -73,7 +73,6 @@ if(CLR_CMAKE_TARGET_OSX) endif() if(CLR_CMAKE_TARGET_APPLE) - add_definitions(-D_XOPEN_SOURCE) set(PLATFORM_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/context.S arch/${PAL_ARCH_SOURCES_DIR}/dispatchexceptionwrapper.S