From 0ac06661636ea7f1a3cc2a6ee9245d6df5b47f24 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 18 May 2020 11:02:32 -0300 Subject: [PATCH] [mono] Linking statically ICU shim on mono (#35790) Linking statically ICU shim on mono for windows, linux, macOs and android. --- .../Loader/AssemblyLoadContext.CoreCLR.cs | 10 +++ .../Common/src/Interop/Interop.Libraries.cs | 4 + .../System.Globalization.Native/pal_icushim.c | 5 +- .../System.Globalization/tests/IcuTests.cs | 3 +- .../Runtime/Loader/AssemblyLoadContext.cs | 10 --- src/mono/configure.ac | 40 +++++++++ src/mono/mono/metadata/Makefile.am | 26 +++++- src/mono/mono/metadata/native-library.c | 20 ++++- src/mono/mono/mini/monovm.c | 3 + src/mono/mono/utils/mono-dl-posix.c | 6 +- src/mono/mono/utils/mono-dl.c | 34 ++++++++ src/mono/mono/utils/mono-dl.h | 2 + src/mono/msvc/libmono-dynamic.vcxproj | 16 ++-- src/mono/msvc/libmonoruntime.targets | 1 + src/mono/msvc/libmonoruntime.targets.filters | 1 + src/mono/msvc/libmonoruntime.vcxproj | 16 ++-- src/mono/msvc/mono.props | 4 + src/mono/msvc/shimglobalization.targets | 51 +++++++++++ .../msvc/shimglobalization.targets.filters | 87 +++++++++++++++++++ .../Globalization/GlobalizationMode.Mono.cs | 16 ++-- .../GlobalizationMode.Unix.Mono.cs | 1 + .../GlobalizationMode.Windows.Mono.cs | 10 +-- .../Loader/AssemblyLoadContext.Mono.cs | 8 +- 23 files changed, 324 insertions(+), 50 deletions(-) create mode 100644 src/mono/msvc/shimglobalization.targets create mode 100644 src/mono/msvc/shimglobalization.targets.filters diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index 7b494115f72d61..997fa49107dcee 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@ -95,6 +95,16 @@ internal Assembly LoadFromInMemoryModule(IntPtr moduleHandle) } #endif + // This method is invoked by the VM to resolve a satellite assembly reference + // after trying assembly resolution via Load override without success. + private static Assembly? ResolveSatelliteAssembly(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) + { + AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!; + + // Invoke the ResolveSatelliteAssembly method + return context.ResolveSatelliteAssembly(assemblyName); + } + // This method is invoked by the VM when using the host-provided assembly load context // implementation. private static IntPtr ResolveUnmanagedDll(string unmanagedDllName, IntPtr gchManagedAssemblyLoadContext) diff --git a/src/libraries/Common/src/Interop/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Interop.Libraries.cs index 4fee38ad35bd22..9a64a909e35ca8 100644 --- a/src/libraries/Common/src/Interop/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Interop.Libraries.cs @@ -6,6 +6,10 @@ internal static partial class Interop { internal static partial class Libraries { +#if MONO + internal const string GlobalizationNative = "__Internal"; +#else internal const string GlobalizationNative = "libSystem.Globalization.Native"; +#endif } } diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c index 1a594c461c0ed9..093188b964a0e9 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c @@ -3,6 +3,9 @@ // See the LICENSE file in the project root for more information. // +#include +#include "pal_icushim_internal.h" + #if defined(TARGET_UNIX) #include #elif defined(TARGET_WINDOWS) @@ -10,12 +13,10 @@ #include #include #endif -#include #include #include #include -#include "pal_icushim_internal.h" #include "pal_icushim.h" // Define pointers to all the used ICU functions diff --git a/src/libraries/System.Globalization/tests/IcuTests.cs b/src/libraries/System.Globalization/tests/IcuTests.cs index 8e862c910195fd..80533da8fb7d14 100644 --- a/src/libraries/System.Globalization/tests/IcuTests.cs +++ b/src/libraries/System.Globalization/tests/IcuTests.cs @@ -11,8 +11,7 @@ namespace System.Globalization.Tests public class IcuTests { private static bool IsIcuCompatiblePlatform => PlatformDetection.IsNotWindows || - (!PlatformDetection.IsMonoRuntime && - PlatformDetection.IsWindows10Version1903OrGreater); + PlatformDetection.IsWindows10Version1903OrGreater; [ConditionalFact(nameof(IsIcuCompatiblePlatform))] public static void IcuShouldBeUsedByDefault() diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs index c958169fe579dc..80d7c00ea8d546 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -564,16 +564,6 @@ public void Dispose() return context.ResolveUsingLoad(assemblyName); } - // This method is invoked by the VM to resolve a satellite assembly reference - // after trying assembly resolution via Load override without success. - private static Assembly? ResolveSatelliteAssembly(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) - { - AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!; - - // Invoke the ResolveSatelliteAssembly method - return context.ResolveSatelliteAssembly(assemblyName); - } - private Assembly? GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) { Assembly? resolvedAssembly = null; diff --git a/src/mono/configure.ac b/src/mono/configure.ac index 42ceddb528e27b..94c228bd8049ff 100644 --- a/src/mono/configure.ac +++ b/src/mono/configure.ac @@ -6795,6 +6795,46 @@ AC_COMPILE_IFELSE( AC_MSG_RESULT(no) ]) +# for icu shim +ICU_SHIM_PATH=. +if test x$with_core = xonly; then + if test x$cross_compiling = xno; then + AC_CHECK_FILE($srcdir/../libraries/Native/Unix/System.Globalization.Native/pal_icushim.h, [have_shim_globalization=yes], [have_shim_globalization=no]) + fi + if test x$have_shim_globalization = xyes || test x$cross_compiling = xyes; then + ICU_SHIM_PATH=../../../libraries/Native/Unix/System.Globalization.Native + if test x$target_osx = xyes; then + ORIG_CPPFLAGS=$CPPFLAGS + # adding icu path to pkg_config_path + PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig + export PKG_CONFIG_PATH + CPPFLAGS="`pkg-config --cflags-only-I icu-uc`" + AC_CHECK_LIB(icucore, ucol_open, LIBS=$LIBS, + [AC_MSG_ERROR([Cannot find libicucore, skipping build for System.Globalization.Native. .NET globalization is not expected to function.])]) + AC_CHECK_HEADER(unicode/utypes.h, [have_sys_icu=yes], [have_sys_icu=no]) + if test x$have_sys_icu = xyes; then + ICU_CFLAGS="$CPPFLAGS -DOSX_ICU_LIBRARY_PATH=AS_ESCAPE(\"/usr/lib/libicucore.dylib\", '\"') -DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations" + fi + CPPFLAGS=$ORIG_CPPFLAGS + elif test x$platform_android = xyes; then + ICU_CFLAGS="-DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -DTARGET_ANDROID -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option" + have_sys_icu=yes + elif test x$host_linux = xyes; then + AC_CHECK_LIB(icuuc, main, LIBS=$LIBS, + [AC_MSG_ERROR([Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform).])]) + AC_CHECK_LIB(icui18n, main, LIBS=$LIBS, + [AC_MSG_ERROR([Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform).])]) + AC_CHECK_HEADER(unicode/utypes.h, [have_sys_icu=yes], [have_sys_icu=no]) + if test x$have_sys_icu = xyes; then + ICU_CFLAGS="-DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option" + fi + fi + AC_SUBST(ICU_CFLAGS) + fi +fi +AC_SUBST(ICU_SHIM_PATH) +AM_CONDITIONAL(HAVE_SYS_ICU, test x$have_sys_icu = xyes) + AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS) diff --git a/src/mono/mono/metadata/Makefile.am b/src/mono/mono/metadata/Makefile.am index 0415d87bee410c..6a4bf4e7238ebe 100644 --- a/src/mono/mono/metadata/Makefile.am +++ b/src/mono/mono/metadata/Makefile.am @@ -103,7 +103,7 @@ Z_LIBS=$(BUNDLE_ZLIB_PATH) endif endif -noinst_LTLIBRARIES = libmonoruntime-config.la $(support_libraries) $(boehm_libraries) $(sgen_libraries) +noinst_LTLIBRARIES = libmonoruntime-config.la $(support_libraries) $(boehm_libraries) $(sgen_libraries) $(shim_libraries) lib_LTLIBRARIES = $(icall_table_libraries) $(ilgen_libraries) @@ -136,6 +136,26 @@ libmonoruntime_support_la_SOURCES = support.c libmonoruntime_support_la_LDFLAGS = $(Z_LIBS) libmonoruntime_support_la_CFLAGS = $(filter-out @CXX_REMOVE_CFLAGS@, @CFLAGS@) @ZLIB_CFLAGS@ +if ENABLE_NETCORE +if HAVE_SYS_ICU +shim_libraries = libmonoruntime-shimglobalization.la + +libmonoruntime_shimglobalization_la_SOURCES = \ + @ICU_SHIM_PATH@/pal_calendarData.c \ + @ICU_SHIM_PATH@/pal_casing.c \ + @ICU_SHIM_PATH@/pal_collation.c \ + @ICU_SHIM_PATH@/pal_idna.c \ + @ICU_SHIM_PATH@/pal_locale.c \ + @ICU_SHIM_PATH@/pal_localeNumberData.c \ + @ICU_SHIM_PATH@/pal_localeStringData.c \ + @ICU_SHIM_PATH@/pal_normalization.c \ + @ICU_SHIM_PATH@/pal_timeZoneInfo.c \ + @ICU_SHIM_PATH@/pal_icushim.c + +libmonoruntime_shimglobalization_la_CFLAGS = @ICU_CFLAGS@ -I$(top_srcdir)/../libraries/Native/Unix/Common/ +endif +endif + # # This library contains the icall tables if the runtime was configured with --disable-icall-tables # @@ -424,12 +444,12 @@ if !ENABLE_MSVC_ONLY libmonoruntime_la_SOURCES = $(common_sources) $(icall_tables_sources) $(ilgen_sources) $(gc_dependent_sources) $(null_gc_sources) $(boehm_sources) # Add CXX_ADD_CFLAGS per-library until/unless https://github.com/dotnet/corefx/pull/31342. libmonoruntime_la_CFLAGS = $(BOEHM_DEFINES) @CXX_ADD_CFLAGS@ -libmonoruntime_la_LIBADD = libmonoruntime-config.la $(support_libraries) +libmonoruntime_la_LIBADD = libmonoruntime-config.la $(support_libraries) $(shim_libraries) libmonoruntimesgen_la_SOURCES = $(common_sources) $(icall_tables_sources) $(ilgen_sources) $(gc_dependent_sources) $(sgen_sources) # Add CXX_ADD_CFLAGS per-library until/unless https://github.com/dotnet/corefx/pull/31342. libmonoruntimesgen_la_CFLAGS = $(SGEN_DEFINES) @CXX_ADD_CFLAGS@ -libmonoruntimesgen_la_LIBADD = libmonoruntime-config.la $(support_libraries) +libmonoruntimesgen_la_LIBADD = libmonoruntime-config.la $(support_libraries) $(shim_libraries) endif # !ENABLE_MSVC_ONLY diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 91b88a79f8b323..2b04f0d6d83c17 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -758,7 +758,7 @@ netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, c // We allow a special name to dlopen from the running process namespace, which is not present in CoreCLR if (strcmp (scope, "__Internal") == 0) { if (!internal_module) - internal_module = mono_dl_open (NULL, MONO_DL_LAZY, &error_msg); + internal_module = mono_dl_open_self (&error_msg); module = internal_module; if (!module) { @@ -1240,6 +1240,9 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou #endif #ifdef ENABLE_NETCORE +#ifndef HOST_WIN32 +retry_with_libcoreclr: +#endif // FIXME: these flags are not getting passed correctly module = netcore_lookup_native_library (alc, image, new_scope, 0); #else @@ -1262,6 +1265,21 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou addr = pinvoke_probe_for_symbol (module, piinfo, new_import, &error_msg); if (!addr) { +#if defined(ENABLE_NETCORE) && !defined(HOST_WIN32) + if (strcmp (new_scope, "__Internal") == 0) { + g_free ((char *)new_scope); +#if defined(TARGET_OSX) + new_scope = g_strdup ("libcoreclr.dylib"); +#else +#if defined(TARGET_ANDROID) + new_scope = g_strdup ("libmonosgen-2.0.so"); +#else + new_scope = g_strdup ("libcoreclr.so"); +#endif +#endif + goto retry_with_libcoreclr; + } +#endif status_out->err_code = LOOKUP_PINVOKE_ERR_NO_SYM; status_out->err_arg = g_strdup (new_import); goto exit; diff --git a/src/mono/mono/mini/monovm.c b/src/mono/mono/mini/monovm.c index d1aff44ed68f6a..32185645d985f4 100644 --- a/src/mono/mono/mini/monovm.c +++ b/src/mono/mono/mini/monovm.c @@ -181,6 +181,9 @@ parse_properties (int propertyCount, const char **propertyKeys, const char **pro } else if (prop_len == 30 && !strncmp (propertyKeys [i], "System.Globalization.Invariant", 30)) { // TODO: Ideally we should propagate this through AppContext options g_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", propertyValues [i], TRUE); + } else if (prop_len == 27 && !strncmp (propertyKeys [i], "System.Globalization.UseNls", 27)) { + // TODO: Ideally we should propagate this through AppContext options + g_setenv ("DOTNET_SYSTEM_GLOBALIZATION_USENLS", propertyValues [i], TRUE); } else { #if 0 // can't use mono logger, it's not initialized yet. diff --git a/src/mono/mono/utils/mono-dl-posix.c b/src/mono/mono/utils/mono-dl-posix.c index 1900a1acf5621b..a6c767c8285dbe 100644 --- a/src/mono/mono/utils/mono-dl-posix.c +++ b/src/mono/mono/utils/mono-dl-posix.c @@ -136,10 +136,10 @@ mono_dl_convert_flags (int flags) #ifdef ENABLE_NETCORE // Specifying both will default to LOCAL - if (flags & MONO_DL_LOCAL) - lflags |= RTLD_LOCAL; - else if (flags & MONO_DL_GLOBAL) + if (flags & MONO_DL_GLOBAL && !(flags & MONO_DL_LOCAL)) lflags |= RTLD_GLOBAL; + else + lflags |= RTLD_LOCAL; #else lflags = flags & MONO_DL_LOCAL ? RTLD_LOCAL : RTLD_GLOBAL; #endif diff --git a/src/mono/mono/utils/mono-dl.c b/src/mono/mono/utils/mono-dl.c index 8b4aedd179ac91..32fc1daed7dbc7 100644 --- a/src/mono/mono/utils/mono-dl.c +++ b/src/mono/mono/utils/mono-dl.c @@ -21,6 +21,9 @@ #include #include #include +#if defined(ENABLE_NETCORE) && defined(TARGET_ANDROID) +#include +#endif // Contains LIBC_SO definition #ifdef HAVE_GNU_LIB_NAMES_H @@ -168,6 +171,37 @@ fix_libc_name (const char *name) } #endif +/** + * mono_dl_open_self: + * \param error_msg pointer for error message on failure + * + * Returns a handle to the main program, on android x86 it's not possible to + * call dl_open(null), it returns a null handle, so this function returns RTLD_DEFAULT + * handle in this platform. + */ +MonoDl* +mono_dl_open_self (char **error_msg) +{ +#if defined(ENABLE_NETCORE) && defined(TARGET_ANDROID) + MonoDl *module; + if (error_msg) + *error_msg = NULL; + module = (MonoDl *) g_malloc (sizeof (MonoDl)); + if (!module) { + if (error_msg) + *error_msg = g_strdup ("Out of memory"); + return NULL; + } + mono_refcount_init (module, NULL); + module->handle = RTLD_DEFAULT; + module->dl_fallback = NULL; + module->full_name = NULL; + return module; +#else + return mono_dl_open (NULL, MONO_DL_LAZY, error_msg); +#endif +} + /** * mono_dl_open: * \param name name of file containing shared module diff --git a/src/mono/mono/utils/mono-dl.h b/src/mono/mono/utils/mono-dl.h index 6236d98b1e59b7..6efee6feabfd5b 100644 --- a/src/mono/mono/utils/mono-dl.h +++ b/src/mono/mono/utils/mono-dl.h @@ -43,6 +43,8 @@ char* mono_dl_build_path (const char *directory, const char *name, void ** MonoDl* mono_dl_open_runtime_lib (const char *lib_name, int flags, char **error_msg); +MonoDl* mono_dl_open_self (char **error_msg); + //Platform API for mono_dl const char* mono_dl_get_so_prefix (void); diff --git a/src/mono/msvc/libmono-dynamic.vcxproj b/src/mono/msvc/libmono-dynamic.vcxproj index 3b1fab1c678a23..c63be2c85ad72f 100644 --- a/src/mono/msvc/libmono-dynamic.vcxproj +++ b/src/mono/msvc/libmono-dynamic.vcxproj @@ -96,8 +96,8 @@ /D /NODEFAULTLIB:LIBCD" " %(AdditionalOptions) Disabled - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);%(AdditionalIncludeDirectories) - WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);_DEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);$(SHIM_GLOBALIZATION_DEFINES);_DEBUG;%(PreprocessorDefinitions) 4996;4018;4244;%(DisableSpecificWarnings) Level3 @@ -123,8 +123,8 @@ /D /NODEFAULTLIB:LIBCD" " %(AdditionalOptions) Disabled - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);%(AdditionalIncludeDirectories) - WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);WIN64;_DEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);$(SHIM_GLOBALIZATION_DEFINES);WIN64;_DEBUG;%(PreprocessorDefinitions) 4996;4018;4244;%(DisableSpecificWarnings) Level3 @@ -147,8 +147,8 @@ /D /NODEFAULTLIB:LIBCD" " %(AdditionalOptions) true - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);%(AdditionalIncludeDirectories) - WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);NDEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);$(SHIM_GLOBALIZATION_DEFINES);NDEBUG;%(PreprocessorDefinitions) true Level3 true @@ -176,8 +176,8 @@ /D /NODEFAULTLIB:LIBCD" " %(AdditionalOptions) true - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);%(AdditionalIncludeDirectories) - WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);WIN64;NDEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(MONO_LLVM_DEFAULT_INCLUDE_DIR);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;$(GC_DEFINES);MONO_DLL_EXPORT;LLVM_API_VERSION=$(MONO_LLVM_DEFAULT_API_VERSION);$(SHIM_GLOBALIZATION_DEFINES);WIN64;NDEBUG;%(PreprocessorDefinitions) true Level3 true diff --git a/src/mono/msvc/libmonoruntime.targets b/src/mono/msvc/libmonoruntime.targets index ba371e200fef98..7b797ee766ddcf 100644 --- a/src/mono/msvc/libmonoruntime.targets +++ b/src/mono/msvc/libmonoruntime.targets @@ -1,6 +1,7 @@ + diff --git a/src/mono/msvc/libmonoruntime.targets.filters b/src/mono/msvc/libmonoruntime.targets.filters index 870a2b19f6e217..d59ba5b295cee9 100644 --- a/src/mono/msvc/libmonoruntime.targets.filters +++ b/src/mono/msvc/libmonoruntime.targets.filters @@ -1,6 +1,7 @@  + diff --git a/src/mono/msvc/libmonoruntime.vcxproj b/src/mono/msvc/libmonoruntime.vcxproj index 4c009edd823914..2541712d4817e7 100644 --- a/src/mono/msvc/libmonoruntime.vcxproj +++ b/src/mono/msvc/libmonoruntime.vcxproj @@ -97,8 +97,8 @@ Level3 Disabled - WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);_DEBUG;%(PreprocessorDefinitions) - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);$(SHIM_GLOBALIZATION_DEFINES);_DEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) $(IntDir)$(TargetName).pdb ProgramDatabase @@ -111,8 +111,8 @@ Level3 Disabled - WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);WIN64;_DEBUG;%(PreprocessorDefinitions) - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);$(SHIM_GLOBALIZATION_DEFINES);WIN64;_DEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) $(IntDir)$(TargetName).pdb ProgramDatabase @@ -125,8 +125,8 @@ Level3 true - WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);NDEBUG;%(PreprocessorDefinitions) - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);$(SHIM_GLOBALIZATION_DEFINES);NDEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) $(IntDir)$(TargetName).pdb true @@ -141,8 +141,8 @@ Level3 true - WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);WIN64;NDEBUG;%(PreprocessorDefinitions) - $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);%(AdditionalIncludeDirectories) + WIN32;WIN32_LEAN_AND_MEAN;_LIB;$(GC_DEFINES);$(SHIM_GLOBALIZATION_DEFINES);WIN64;NDEBUG;%(PreprocessorDefinitions) + $(MONO_DIR);$(MONO_INCLUDE_DIR);$(LIBGC_CPPFLAGS_INCLUDE);$(GLIB_CFLAGS_INCLUDE);$(SHIM_GLOBALIZATION_INCLUDE_DIR);%(AdditionalIncludeDirectories) $(IntDir)$(TargetName).pdb true diff --git a/src/mono/msvc/mono.props b/src/mono/msvc/mono.props index e71f2cc330d6db..502c5398527d25 100644 --- a/src/mono/msvc/mono.props +++ b/src/mono/msvc/mono.props @@ -45,6 +45,9 @@ $(MONO_LIBGC_INCLUDE_DIR) $(MONO_EGLIB_SOURCE_DIR) 610 + $(top_srcdir)/../libraries/Native/Unix/System.Globalization.Native + $(top_srcdir)/../libraries/Native/Unix/Common + $(SHIM_GLOBALIZATION_COMMON);$(SHIM_GLOBALIZATION) $(MONO_DIR)/external/llvm-project/llvm/include @@ -58,6 +61,7 @@ HAVE_SGEN_GC;HAVE_MOVING_COLLECTOR;HAVE_WRITE_BARRIERS;HAVE_CONC_GC_AS_DEFAULT $(SGEN_DEFINES) + TARGET_WINDOWS;PALEXPORT=extern "C" __declspec(dllexport) libgcmonosgen.lib -sgen $(MONO_BUILD_DIR_PREFIX)sgen/ diff --git a/src/mono/msvc/shimglobalization.targets b/src/mono/msvc/shimglobalization.targets new file mode 100644 index 00000000000000..19bc337ba6c287 --- /dev/null +++ b/src/mono/msvc/shimglobalization.targets @@ -0,0 +1,51 @@ + + + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + CompileAsCpp + + + + + + + + + + + + + + + + + + + diff --git a/src/mono/msvc/shimglobalization.targets.filters b/src/mono/msvc/shimglobalization.targets.filters new file mode 100644 index 00000000000000..106d7b8717996c --- /dev/null +++ b/src/mono/msvc/shimglobalization.targets.filters @@ -0,0 +1,87 @@ + + + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Source Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + Header Files$(MonoRuntimeFilterSubFolder)\shimglobalization + + + + + + + diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs index 911499ea842e37..3d7b5ca4866f24 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs @@ -6,14 +6,18 @@ namespace System.Globalization { internal static partial class GlobalizationMode { - internal static bool Invariant { get; } = GetGlobalizationInvariantMode(); + private static bool GetInvariantSwitchValue() => + GetSwitchValue("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); - private static bool GetInvariantSwitchValue() + private static bool GetSwitchValue(string envVariable) { - string? val = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); - if (val != null) - return bool.IsTrueStringIgnoreCase(val) || val.Equals("1"); - return false; + bool ret = false; + string? switchValue = Environment.GetEnvironmentVariable(envVariable); + if (switchValue != null) + { + ret = bool.IsTrueStringIgnoreCase(switchValue) || switchValue.Equals("1"); + } + return ret; } } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs index e3ca7ce6173663..70d7e7e3dc41f9 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs @@ -8,6 +8,7 @@ namespace System.Globalization { internal partial class GlobalizationMode { + internal static bool Invariant { get; } = GetGlobalizationInvariantMode(); internal static bool UseNls => false; private static bool GetGlobalizationInvariantMode() diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs index 5aaa1431703762..abf2a603c21261 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs @@ -6,11 +6,9 @@ namespace System.Globalization { internal partial class GlobalizationMode { - internal static bool UseNls => true; - - private static bool GetGlobalizationInvariantMode() - { - return GetInvariantSwitchValue(); - } + internal static bool Invariant { get; } = GetInvariantSwitchValue(); + internal static bool UseNls { get; } = !Invariant && + (GetSwitchValue("DOTNET_SYSTEM_GLOBALIZATION_USENLS") || + Interop.Globalization.LoadICU() == 0); } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs index 5e58b1b3cf47da..4a35247b1c1373 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs @@ -130,7 +130,13 @@ public void StartProfileOptimization(string? profile) // Invoked by Mono to resolve requests to load satellite assemblies. private static Assembly? MonoResolveUsingResolveSatelliteAssembly(IntPtr gchALC, string assemblyName) { - return ResolveSatelliteAssembly(gchALC, new AssemblyName(assemblyName)); + AssemblyLoadContext context; + // This check exists because the function can be called early in startup, before the default ALC is initialized + if (gchALC == IntPtr.Zero) + context = Default; + else + context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchALC).Target)!; + return context.ResolveSatelliteAssembly(new AssemblyName(assemblyName)); } private static AssemblyLoadContext GetAssemblyLoadContext(IntPtr gchManagedAssemblyLoadContext)