From 78376fc27023eaf18d67f10cc046bdef3196dd2c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 13 Nov 2025 20:56:48 -0800 Subject: [PATCH 01/15] Make AppleAppBuilder host template use host_runtime_contract --- .../AppleAppBuilder/AppleAppBuilder.csproj | 1 + .../Templates/runtime-coreclr.m | 91 ++++++++++++++++++- src/tasks/AppleAppBuilder/Xcode.cs | 2 + 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj index 1f0e6ba463420f..165faa29d08fa8 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj @@ -10,6 +10,7 @@ + diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index b6ef00acd7d0dc..a86f3e8e61489f 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -3,6 +3,7 @@ #import #include "coreclrhost.h" +#include "host_runtime_contract.h" #include #import #include @@ -68,7 +69,7 @@ return strdup([joined UTF8String]); } -void* +const void* pinvoke_override (const char *libraryName, const char *entrypointName) { if (!strcmp (libraryName, "__Internal")) @@ -79,6 +80,80 @@ return NULL; } +#include +#include +size_t get_image_size(void* base_address) +{ + uint32_t image_count = _dyld_image_count(); + for (uint32_t i = 0; i < image_count; ++i) + { + const struct mach_header_64* header = (const struct mach_header_64*)_dyld_get_image_header(i); + if ((const void*)header != base_address) + continue; + + const struct load_command* cmd = (const struct load_command*)((const char*)header + sizeof(struct mach_header_64)); + + size_t image_size = 0; + for (uint32_t j = 0; j < header->ncmds; ++j) + { + if (cmd->cmd == LC_SEGMENT_64) + { + const struct segment_command_64* seg = (const struct segment_command_64*)cmd; + size_t end_addr = (size_t)(seg->vmaddr + seg->vmsize); + if (end_addr > image_size) + image_size = end_addr; + } + + cmd = (const struct load_command*)((const char*)cmd + cmd->cmdsize); + } + + return image_size; + } +} + +bool get_native_code_data(const struct host_runtime_contract_native_code_context* context, struct host_runtime_contract_native_code_data* data) +{ + if (!context || !data || !context->assembly_path || !context->owner_composite_name) + return false; + + // Look for the owner composite R2R image in the same directory as the assembly + char r2r_path[PATH_MAX]; + const char *last_slash = strrchr(context->assembly_path, '/'); + size_t dir_len = last_slash ? (size_t)(last_slash - context->assembly_path) : 0; + if (dir_len >= sizeof(r2r_path) - 1) + return false; + + strncpy(r2r_path, context->assembly_path, dir_len); + int written = snprintf(r2r_path + dir_len, sizeof(r2r_path) - dir_len, "/%s", context->owner_composite_name); + if (written <= 0 || (size_t)written >= sizeof(r2r_path) - dir_len) + return false; + + // TODO: store and dlclose the handles after the app runs + void* handle = dlopen(r2r_path, RTLD_LAZY | RTLD_LOCAL); + if (handle == NULL) + return false; + + void* r2r_header = dlsym(handle, "RTR_HEADER"); + if (r2r_header == NULL) + { + dlclose(handle); + return false; + } + + Dl_info info; + if (dladdr(r2r_header, &info) == 0) + { + dlclose(handle); + return false; + } + + data->size = sizeof(struct host_runtime_contract_native_code_data); + data->r2r_header_ptr = r2r_header; + data->image_size = get_image_size(info.dli_fbase); + data->image_base = info.dli_fbase; + return true; +} + void mono_ios_runtime_init (void) { @@ -116,15 +191,21 @@ #endif assert (res > 0); - char pinvoke_override_addr [16]; - sprintf (pinvoke_override_addr, "%p", &pinvoke_override); + struct host_runtime_contract host_contract = { + .size = sizeof(struct host_runtime_contract), + .pinvoke_override = &pinvoke_override, + .get_native_code_data = &get_native_code_data + }; + + char contract_str[19]; // 0x + 16 hex digits + '\0' + snprintf(contract_str, 19, "0x%zx", (size_t)(&host_contract)); // 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", + "HOST_RUNTIME_CONTRACT", #if !defined(INVARIANT_GLOBALIZATION) "ICU_DAT_FILE_PATH" #endif @@ -133,7 +214,7 @@ APPLE_RUNTIME_IDENTIFIER, bundle, compute_trusted_platform_assemblies(), - pinvoke_override_addr, + contract_str, #if !defined(INVARIANT_GLOBALIZATION) icu_dat_path #endif diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index 54b3bb9f43be84..ec421fec422171 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -618,6 +618,8 @@ public string GenerateCMake( { File.WriteAllText(Path.Combine(binDir, "coreclrhost.h"), Utils.GetEmbeddedResource("coreclrhost.h")); + File.WriteAllText(Path.Combine(binDir, "host_runtime_contract.h"), + Utils.GetEmbeddedResource("host_runtime_contract.h")); // NOTE: Library mode is not supported yet File.WriteAllText(Path.Combine(binDir, "runtime.m"), From c9b56e6f164393b179c569c9681650ea40a68865 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 13 Nov 2025 20:58:03 -0800 Subject: [PATCH 02/15] Allow PublishReadyToRun=true for iOS sample --- .../apple/build/AppleBuild.InTree.targets | 15 +++++++++++ src/mono/sample/iOS/Program.csproj | 25 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets index 37bc5fed8830e3..653c84a59739ae 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets @@ -33,4 +33,19 @@ + + + + + $([MSBuild]::NormalizePath('$(Crossgen2InBuildDir)', 'crossgen2$(ExeSuffix)')) + + + + + + diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index c409a2a72f98a6..8e40e294c63ea7 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -26,15 +26,32 @@ Publish + + true + macho + + - - - + + + + + + + + + + - + + + $(Crossgen2SdkOverrideTargetsPath) + $(AfterMicrosoftNETSdkTargets);$(MonoProjectRoot)\msbuild\apple\build\AppleBuild.InTree.targets + From 582e4bfd541e7087f196ad34df0420969a4ddaba Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 19 Nov 2025 10:29:54 -0800 Subject: [PATCH 03/15] Make AppleAppBulider sign *.r2r.dylib --- src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index f8c6f32b723095..bd72abc8b03ceb 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -79,6 +79,12 @@ add_custom_command( if ls -1 $CODESIGNING_FOLDER_PATH/*.dylib 2>/dev/null | grep -q .\; then codesign --force --sign \"$SIGN_IDENTITY\" --timestamp $CODESIGNING_FOLDER_PATH/*.dylib\; fi\; + if ls -1 $CODESIGNING_FOLDER_PATH/Contents/Resources/*.r2r.dylib 2>/dev/null | grep -q .\; then + codesign --force --sign \"$SIGN_IDENTITY\" --timestamp $CODESIGNING_FOLDER_PATH/Contents/Resources/*.r2r.dylib\; + fi\; + if ls -1 $CODESIGNING_FOLDER_PATH/*.r2r.dylib 2>/dev/null | grep -q .\; then + codesign --force --sign \"$SIGN_IDENTITY\" --timestamp $CODESIGNING_FOLDER_PATH/*.r2r.dylib\; + fi\; fi\; fi ) From 83a3b42a92a049c51af880b859561fa0e763525b Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 19 Nov 2025 10:31:58 -0800 Subject: [PATCH 04/15] Leave R2R on by default for Apple mobile --- src/coreclr/inc/clrconfigvalues.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index 3a1b3dc5fbe19c..4292d73105da52 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -579,11 +579,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_CreateDumpDiagnostics, W("CreateDumpDiagnostic /// R2R /// RETAIL_CONFIG_STRING_INFO(INTERNAL_NativeImageSearchPaths, W("NativeImageSearchPaths"), "Extra search paths for native composite R2R images") -#if defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) -RETAIL_CONFIG_DWORD_INFO(EXTERNAL_ReadyToRun, W("ReadyToRun"), 0, "Enable/disable use of ReadyToRun native code") // Off by default for Apple mobile -#else RETAIL_CONFIG_DWORD_INFO(EXTERNAL_ReadyToRun, W("ReadyToRun"), 1, "Enable/disable use of ReadyToRun native code") // On by default for CoreCLR -#endif // defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) RETAIL_CONFIG_STRING_INFO(EXTERNAL_ReadyToRunExcludeList, W("ReadyToRunExcludeList"), "List of assemblies that cannot use Ready to Run images") RETAIL_CONFIG_STRING_INFO(EXTERNAL_ReadyToRunLogFile, W("ReadyToRunLogFile"), "Name of file to log success/failure of using Ready to Run images") From d5b94134bb267941e5a0a68b45086858cae07a0d Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 19 Nov 2025 13:19:52 -0800 Subject: [PATCH 05/15] Close loaded handles --- .../AppleAppBuilder/Templates/runtime-coreclr.m | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index a86f3e8e61489f..a7986a23bbcfba 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -16,6 +16,10 @@ #define APPLE_RUNTIME_IDENTIFIER "//%APPLE_RUNTIME_IDENTIFIER%" +#define MAX_LOADED_NATIVE_CODE_COUNT 64 // Arbitrarily 'large enough' number +static void* loaded_native_code_handles[MAX_LOADED_NATIVE_CODE_COUNT]; +static int loaded_native_code_handle_count = 0; + const char * get_bundle_path (void) { @@ -128,11 +132,14 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context if (written <= 0 || (size_t)written >= sizeof(r2r_path) - dir_len) return false; - // TODO: store and dlclose the handles after the app runs + assert(loaded_native_code_handle_count < MAX_LOADED_NATIVE_CODE_COUNT); void* handle = dlopen(r2r_path, RTLD_LAZY | RTLD_LOCAL); if (handle == NULL) return false; + loaded_native_code_handles[loaded_native_code_handle_count] = handle; + loaded_native_code_handle_count++; + void* r2r_header = dlsym(handle, "RTR_HEADER"); if (r2r_header == NULL) { @@ -241,5 +248,13 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context free_managed_args (&managed_argv, argi); + // Close all loaded handles after the app runs + for (int i = 0; i < loaded_native_code_handle_count; ++i) + { + if (loaded_native_code_handles[i] != NULL) { + dlclose(loaded_native_code_handles[i]); + } + } + exit (res); } From 4cdb4baeab7225450dd13a5613aebfce74afb92f Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 19 Nov 2025 13:20:09 -0800 Subject: [PATCH 06/15] Update makefile --- src/mono/msbuild/apple/build/AppleBuild.targets | 2 +- src/mono/sample/iOS/Makefile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 08f925649eb13f..9f987572457cb9 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -257,7 +257,7 @@ <_MonoLLVMPath Condition="'$(_MonoLLVMPath)' == '' and '$(MonoEnableLLVM)' == 'true'">$([System.IO.Path]::GetDirectoryName("$(_CompilerBinaryPath)")) - Date: Thu, 20 Nov 2025 10:30:34 -0800 Subject: [PATCH 07/15] Revert "Close loaded handles" This reverts commit d5b94134bb267941e5a0a68b45086858cae07a0d. --- .../AppleAppBuilder/Templates/runtime-coreclr.m | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index a7986a23bbcfba..a86f3e8e61489f 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -16,10 +16,6 @@ #define APPLE_RUNTIME_IDENTIFIER "//%APPLE_RUNTIME_IDENTIFIER%" -#define MAX_LOADED_NATIVE_CODE_COUNT 64 // Arbitrarily 'large enough' number -static void* loaded_native_code_handles[MAX_LOADED_NATIVE_CODE_COUNT]; -static int loaded_native_code_handle_count = 0; - const char * get_bundle_path (void) { @@ -132,14 +128,11 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context if (written <= 0 || (size_t)written >= sizeof(r2r_path) - dir_len) return false; - assert(loaded_native_code_handle_count < MAX_LOADED_NATIVE_CODE_COUNT); + // TODO: store and dlclose the handles after the app runs void* handle = dlopen(r2r_path, RTLD_LAZY | RTLD_LOCAL); if (handle == NULL) return false; - loaded_native_code_handles[loaded_native_code_handle_count] = handle; - loaded_native_code_handle_count++; - void* r2r_header = dlsym(handle, "RTR_HEADER"); if (r2r_header == NULL) { @@ -248,13 +241,5 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context free_managed_args (&managed_argv, argi); - // Close all loaded handles after the app runs - for (int i = 0; i < loaded_native_code_handle_count; ++i) - { - if (loaded_native_code_handles[i] != NULL) { - dlclose(loaded_native_code_handles[i]); - } - } - exit (res); } From ed1355a38beb0030253f88f3373b8d5f0613cd98 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 11:29:37 -0800 Subject: [PATCH 08/15] Feedback --- src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index a86f3e8e61489f..cb87414ea6fead 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -109,6 +109,8 @@ size_t get_image_size(void* base_address) return image_size; } + + return 0; } bool get_native_code_data(const struct host_runtime_contract_native_code_context* context, struct host_runtime_contract_native_code_data* data) @@ -128,7 +130,6 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context if (written <= 0 || (size_t)written >= sizeof(r2r_path) - dir_len) return false; - // TODO: store and dlclose the handles after the app runs void* handle = dlopen(r2r_path, RTLD_LAZY | RTLD_LOCAL); if (handle == NULL) return false; @@ -191,6 +192,7 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context #endif assert (res > 0); + // Contract lasts the lifetime of the app. The app exists before the end of this function. struct host_runtime_contract host_contract = { .size = sizeof(struct host_runtime_contract), .pinvoke_override = &pinvoke_override, From 14264d2a907ff0eca18db6ada9e267e8af9c4b8c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 11:32:40 -0800 Subject: [PATCH 09/15] Interpret all (non-R2R) on Apple mobile --- src/coreclr/interpreter/eeinterp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/interpreter/eeinterp.cpp b/src/coreclr/interpreter/eeinterp.cpp index 38acc3593f2d77..8bc5e15dd76256 100644 --- a/src/coreclr/interpreter/eeinterp.cpp +++ b/src/coreclr/interpreter/eeinterp.cpp @@ -85,8 +85,8 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd, break; } -#ifdef TARGET_WASM - // interpret everything on wasm +#if defined(TARGET_WASM) || defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) + // interpret everything on wasm and Apple mobile platforms doInterpret = true; #else // NOTE: We do this check even if doInterpret==true in order to populate g_interpModule From 5fc7ca2a51a4f2a14e5b9d066adc8df656fb8c0b Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 12:45:15 -0800 Subject: [PATCH 10/15] Remove environment variables --- src/mono/sample/iOS/Program.csproj | 8 -------- .../iOS.Simulator.CoreCLR.Interpreter.Test.csproj | 4 ---- 2 files changed, 12 deletions(-) diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 8e40e294c63ea7..667fcc709e9010 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -35,14 +35,6 @@ - - - - - - - - diff --git a/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj b/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj index 23315975066cd6..b206728d9afe97 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj @@ -12,10 +12,6 @@ 42 - - - - From 6b642a81c41464b6a9bc49ae38b1be289dfb01d1 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 16:25:18 -0800 Subject: [PATCH 11/15] Set EnableHWIntrinsic=0 --- src/coreclr/inc/clrconfigvalues.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index 4292d73105da52..f2d9fc939ab526 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -666,6 +666,9 @@ RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PreferredVectorBitWidth, W("PreferredV #if defined(TARGET_LOONGARCH64) //TODO: should implement LoongArch64's features. RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 0, "Allows Base+ hardware intrinsics to be disabled") +#elif defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) +// Always disabled on Apple mobile +RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 0, "Allows Base+ hardware intrinsics to be disabled") #else RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 1, "Allows Base+ hardware intrinsics to be disabled") #endif // defined(TARGET_LOONGARCH64) From 0f8b95b364caa48b032513b3989a435d18443d63 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 19:25:19 -0800 Subject: [PATCH 12/15] Revert "Set EnableHWIntrinsic=0" This reverts commit 6b642a81c41464b6a9bc49ae38b1be289dfb01d1. --- src/coreclr/inc/clrconfigvalues.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index f2d9fc939ab526..4292d73105da52 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -666,9 +666,6 @@ RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PreferredVectorBitWidth, W("PreferredV #if defined(TARGET_LOONGARCH64) //TODO: should implement LoongArch64's features. RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 0, "Allows Base+ hardware intrinsics to be disabled") -#elif defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) -// Always disabled on Apple mobile -RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 0, "Allows Base+ hardware intrinsics to be disabled") #else RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableHWIntrinsic, W("EnableHWIntrinsic"), 1, "Allows Base+ hardware intrinsics to be disabled") #endif // defined(TARGET_LOONGARCH64) From c5741b94b1b1234c3199f5b434bfc72f1222f445 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 20 Nov 2025 19:27:56 -0800 Subject: [PATCH 13/15] Revert iOS.Simulator.CoreCLR.Interpreter.Test.csproj --- .../iOS.Simulator.CoreCLR.Interpreter.Test.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj b/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj index b206728d9afe97..23315975066cd6 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Simulator/CoreCLR.Interpreter/iOS.Simulator.CoreCLR.Interpreter.Test.csproj @@ -12,6 +12,10 @@ 42 + + + + From 43fbdddac9326a5344f4ee43530b43602daddc70 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 24 Nov 2025 12:32:44 -0800 Subject: [PATCH 14/15] Update src/coreclr/interpreter/eeinterp.cpp Co-authored-by: Jan Kotas --- src/coreclr/interpreter/eeinterp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/interpreter/eeinterp.cpp b/src/coreclr/interpreter/eeinterp.cpp index 8bc5e15dd76256..49af0d423fbe9e 100644 --- a/src/coreclr/interpreter/eeinterp.cpp +++ b/src/coreclr/interpreter/eeinterp.cpp @@ -85,8 +85,8 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd, break; } -#if defined(TARGET_WASM) || defined(TARGET_IOS) || defined(TARGET_TVOS) || defined(TARGET_MACCATALYST) - // interpret everything on wasm and Apple mobile platforms +#if !defined(FEATURE_JIT) + // interpret everything when we do not have a JIT doInterpret = true; #else // NOTE: We do this check even if doInterpret==true in order to populate g_interpModule From 751dfdd4cb6ee2d929b41237eada0c7bd621a3e2 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 24 Nov 2025 12:54:47 -0800 Subject: [PATCH 15/15] Use base address directly as header --- .../Templates/runtime-coreclr.m | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index cb87414ea6fead..938de5423105c6 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -82,35 +82,25 @@ #include #include -size_t get_image_size(void* base_address) +size_t get_image_size(const struct mach_header_64* header) { - uint32_t image_count = _dyld_image_count(); - for (uint32_t i = 0; i < image_count; ++i) - { - const struct mach_header_64* header = (const struct mach_header_64*)_dyld_get_image_header(i); - if ((const void*)header != base_address) - continue; - - const struct load_command* cmd = (const struct load_command*)((const char*)header + sizeof(struct mach_header_64)); + const struct load_command* cmd = (const struct load_command*)((const char*)header + sizeof(struct mach_header_64)); - size_t image_size = 0; - for (uint32_t j = 0; j < header->ncmds; ++j) + size_t image_size = 0; + for (uint32_t j = 0; j < header->ncmds; ++j) + { + if (cmd->cmd == LC_SEGMENT_64) { - if (cmd->cmd == LC_SEGMENT_64) - { - const struct segment_command_64* seg = (const struct segment_command_64*)cmd; - size_t end_addr = (size_t)(seg->vmaddr + seg->vmsize); - if (end_addr > image_size) - image_size = end_addr; - } - - cmd = (const struct load_command*)((const char*)cmd + cmd->cmdsize); + const struct segment_command_64* seg = (const struct segment_command_64*)cmd; + size_t end_addr = (size_t)(seg->vmaddr + seg->vmsize); + if (end_addr > image_size) + image_size = end_addr; } - return image_size; + cmd = (const struct load_command*)((const char*)cmd + cmd->cmdsize); } - return 0; + return image_size; } bool get_native_code_data(const struct host_runtime_contract_native_code_context* context, struct host_runtime_contract_native_code_data* data) @@ -148,10 +138,14 @@ bool get_native_code_data(const struct host_runtime_contract_native_code_context return false; } + // The base address points to the Mach header + void* base_address = info.dli_fbase; + const struct mach_header_64* header = (const struct mach_header_64*)base_address; + data->size = sizeof(struct host_runtime_contract_native_code_data); data->r2r_header_ptr = r2r_header; - data->image_size = get_image_size(info.dli_fbase); - data->image_base = info.dli_fbase; + data->image_size = get_image_size(header); + data->image_base = base_address; return true; }