From fd6d33c657fea8ffaf4f4d24cec54ae6a9a096d4 Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Mon, 20 Mar 2023 17:44:17 +0100 Subject: [PATCH 1/3] * add arm64 wasm support --- eng/native/init-vs-env.cmd | 2 +- src/mono/CMakeLists.txt | 8 +++++--- src/mono/mono.proj | 2 +- src/mono/mono/metadata/coree.c | 2 +- src/mono/mono/mini/mini-windows.c | 4 +++- src/mono/mono/utils/mono-threads-coop.c | 2 ++ 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/eng/native/init-vs-env.cmd b/eng/native/init-vs-env.cmd index 68242ed725f67..6c1ad8f3a1786 100644 --- a/eng/native/init-vs-env.cmd +++ b/eng/native/init-vs-env.cmd @@ -8,7 +8,7 @@ if /i "%~1" == "x86" (set __VCBuildArch=x86) if /i "%~1" == "x64" (set __VCBuildArch=x86_amd64) if /i "%~1" == "arm" (set __VCBuildArch=x86_arm) if /i "%~1" == "arm64" (set __VCBuildArch=x86_arm64) -if /i "%~1" == "wasm" (set __VCBuildArch=x86_amd64) +if /i "%~1" == "wasm" (if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (set __VCBuildArch=x86_arm64) else (set __VCBuildArch=x86_amd64)) :: Default to highest Visual Studio version available that has Visual C++ tools. :: diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 7b57776aa007c..e4863f7dbf05d 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -40,9 +40,11 @@ set(CMAKE_MODULE_PATH ) set(CMAKE_INSTALL_MESSAGE LAZY) -find_program(CCACHE_PROGRAM ccache) -if(CCACHE_PROGRAM) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") +if(USE_CCACHE) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + endif() endif() function(append value) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 695064cc7663b..8fcc0f537630b 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -856,7 +856,7 @@ <_MonoSkipInitCompiler Condition="'$(RealTargetArchitecture)' != '' and '$(RealTargetArchitecture)' != '$(BuildArchitecture)'">false - <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">$(PythonCmd) $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') + <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">python $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') <_MonoAotCMakeConfigureCommand>cmake @(MonoAOTCMakeArgs, ' ') $(MonoCMakeExtraArgs) "$(MonoProjectRoot.TrimEnd('\/'))" <_MonoAotCMakeConfigureCommand Condition="'$(_MonoSkipInitCompiler)' != 'true' and '$(HostOS)' != 'windows'">sh -c 'build_arch="$(_CompilerTargetArch)" compiler="$(MonoCCompiler)" . "$(RepositoryEngineeringCommonDir)native/init-compiler.sh" && @(_MonoAotBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand)' <_MonoAotCMakeConfigureCommand Condition="'$(_MonoSkipInitCompiler)' == 'true' and '$(HostOS)' != 'windows'">$(_MonoAOTCCOption) $(_MonoAOTCXXOption) @(_MonoAotBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand) diff --git a/src/mono/mono/metadata/coree.c b/src/mono/mono/metadata/coree.c index 2efdfd25adb64..37c94daf32fdb 100644 --- a/src/mono/mono/metadata/coree.c +++ b/src/mono/mono/metadata/coree.c @@ -646,7 +646,7 @@ STDAPI MonoFixupCorEE(HMODULE ModuleHandle) *(Trampoline)++ = 0xFF; *(Trampoline)++ = 0xE3; #else -#error Unsupported architecture. + g_assert_not_reached(); #endif #else ProcRva = (DWORD)(ExportFixup->ProcAddress.DWordPtr - (DWORD_PTR)DosHeader); diff --git a/src/mono/mono/mini/mini-windows.c b/src/mono/mono/mini/mini-windows.c index c678f4c4594c4..f5d81c537a691 100644 --- a/src/mono/mono/mini/mini-windows.c +++ b/src/mono/mono/mini/mini-windows.c @@ -283,7 +283,9 @@ thread_timer_expired (HANDLE thread) if (GetThreadContext (thread, &context)) { guchar *ip; -#ifdef _WIN64 +#ifdef _ARM64_ + ip = (guchar *) context.Pc; +#elif _WIN64 ip = (guchar *) context.Rip; #else ip = (guchar *) context.Eip; diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 4ed659d66058c..b6263bd844cea 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -219,6 +219,7 @@ typedef struct { __declspec(naked) void __cdecl copy_stack_data_internal_win32_wrapper (MonoThreadInfo *info, MonoStackData *stackdata_begin, MonoBuiltinUnwindInfo *unwind_info_data, CopyStackDataFunc func) { +#if defined(TARGET_X86) || defined(TARGET_AMD64) __asm { mov edx, dword ptr [esp + 0Ch] mov dword ptr [edx + 00h], ebx @@ -230,6 +231,7 @@ copy_stack_data_internal_win32_wrapper (MonoThreadInfo *info, MonoStackData *sta mov edx, dword ptr [esp + 10h] jmp edx }; +#endif } #endif From 8f2aa683c8a461a139df70085b06b8eba8ef186e Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Wed, 29 Mar 2023 22:20:46 +0200 Subject: [PATCH 2/3] * workaround due to emscripten regression --- src/mono/wasm/wasm.proj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 9755e405afed4..8342ee12786eb 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -293,7 +293,6 @@ <_EmccLinkFlags Include="-s EXPORTED_RUNTIME_METHODS=$(_EmccExportedRuntimeMethods)" /> <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=$(_EmccExportedFunctions)" /> <_EmccLinkFlags Include="--source-map-base http://example.com" /> - <_EmccLinkFlags Include="-s STRICT_JS=1" /> <_EmccLinkFlags Include="-s WASM_BIGINT=1" /> <_EmccLinkFlags Include="-s EXPORT_NAME="'createDotnetRuntime'"" /> <_EmccLinkFlags Include="-s MODULARIZE=1"/> From d3fc7ad9463ed79b14a5d05ea319d6ec0620a21a Mon Sep 17 00:00:00 2001 From: Evgeny Karpov Date: Tue, 25 Apr 2023 16:23:38 +0200 Subject: [PATCH 3/3] * refactor PythonCmd variable change --- src/mono/mono.proj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 8fcc0f537630b..da81b42e1b2b2 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -745,7 +745,6 @@ $(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.dylib $(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.so $([MSBuild]::NormalizePath('$(MonoLLVMDir)', '$(BuildArchitecture)', 'bin', 'libclang.dll')) - setlocal EnableDelayedExpansion && call "$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env.bat'))" && !EMSDK_PYTHON! <_ForceRelease Condition="$([MSBuild]::IsOSPlatform('Windows')) and '$(TargetArchitecture)' == 'wasm' and '$(Configuration)' == 'Debug'">true @@ -856,7 +855,7 @@ <_MonoSkipInitCompiler Condition="'$(RealTargetArchitecture)' != '' and '$(RealTargetArchitecture)' != '$(BuildArchitecture)'">false - <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">python $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') + <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">$(PythonCmd) $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') <_MonoAotCMakeConfigureCommand>cmake @(MonoAOTCMakeArgs, ' ') $(MonoCMakeExtraArgs) "$(MonoProjectRoot.TrimEnd('\/'))" <_MonoAotCMakeConfigureCommand Condition="'$(_MonoSkipInitCompiler)' != 'true' and '$(HostOS)' != 'windows'">sh -c 'build_arch="$(_CompilerTargetArch)" compiler="$(MonoCCompiler)" . "$(RepositoryEngineeringCommonDir)native/init-compiler.sh" && @(_MonoAotBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand)' <_MonoAotCMakeConfigureCommand Condition="'$(_MonoSkipInitCompiler)' == 'true' and '$(HostOS)' != 'windows'">$(_MonoAOTCCOption) $(_MonoAOTCXXOption) @(_MonoAotBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand)