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") diff --git a/src/coreclr/interpreter/eeinterp.cpp b/src/coreclr/interpreter/eeinterp.cpp index 38acc3593f2d77..49af0d423fbe9e 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(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 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/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)")) - Publish + + true + macho + + - - - + + - + + + $(Crossgen2SdkOverrideTargetsPath) + $(AfterMicrosoftNETSdkTargets);$(MonoProjectRoot)\msbuild\apple\build\AppleBuild.InTree.targets + 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/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 ) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m index b6ef00acd7d0dc..938de5423105c6 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,75 @@ return NULL; } +#include +#include +size_t get_image_size(const struct mach_header_64* header) +{ + 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; + + 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; + } + + // 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(header); + data->image_base = base_address; + return true; +} + void mono_ios_runtime_init (void) { @@ -116,15 +186,22 @@ #endif assert (res > 0); - char pinvoke_override_addr [16]; - sprintf (pinvoke_override_addr, "%p", &pinvoke_override); + // 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, + .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 +210,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"),