Fix Crossgen2 bug #61104 and add regression test (#63956)
authorTomáš Rylek <trylek@microsoft.com>
Thu, 20 Jan 2022 00:52:15 +0000 (01:52 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Jan 2022 00:52:15 +0000 (01:52 +0100)
The issue tracks the runtime regression failure where
Crossgen2-compiled app is unable to locate a type with non-ASCII
characters in its name. The failure was caused by the fact that
Crossgen2 was incorrectly zero-extending the individual UTF8 characters
when calculating the hash whereas runtime is sign-extending them.

Thanks

Tomas

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunHashCode.cs
src/tests/Regressions/coreclr/GitHub_61104/test61104.cs [new file with mode: 0644]
src/tests/Regressions/coreclr/GitHub_61104/test61104.csproj [new file with mode: 0644]

index e506bb8..9380a82 100644 (file)
@@ -34,10 +34,10 @@ namespace ILCompiler
             byte[] src = Encoding.UTF8.GetBytes(name);
             for (int i = 0; i < src.Length; i += 2)
             {
-                hash1 = unchecked(hash1 + RotateLeft(hash1, 5)) ^ src[i];
+                hash1 = unchecked(hash1 + RotateLeft(hash1, 5)) ^ (int)unchecked((sbyte)src[i]);
                 if (i + 1 < src.Length)
                 {
-                    hash2 = unchecked(hash2 + RotateLeft(hash2, 5)) ^ src[i + 1];
+                    hash2 = unchecked(hash2 + RotateLeft(hash2, 5)) ^ (int)unchecked((sbyte)src[i + 1]);
                 }
                 else
                 {
diff --git a/src/tests/Regressions/coreclr/GitHub_61104/test61104.cs b/src/tests/Regressions/coreclr/GitHub_61104/test61104.cs
new file mode 100644 (file)
index 0000000..2e01b96
--- /dev/null
@@ -0,0 +1,12 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+var type = Type.GetType("_测试数据记录仪_Iiİı_åäö_Controller_DataLogger1_log_all_", false);
+var obj = Activator.CreateInstance(type!);
+Console.WriteLine(obj?.GetType().Name);
+
+return 100;
+
+public class _测试数据记录仪_Iiİı_åäö_Controller_DataLogger1_log_all_
+{
+}
diff --git a/src/tests/Regressions/coreclr/GitHub_61104/test61104.csproj b/src/tests/Regressions/coreclr/GitHub_61104/test61104.csproj
new file mode 100644 (file)
index 0000000..b72e9a4
--- /dev/null
@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+    <CLRTestPriority>1</CLRTestPriority>
+
+    <!-- This is an explicit crossgen test -->
+    <AlwaysUseCrossGen2>true</AlwaysUseCrossGen2>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="test61104.cs" />
+  </ItemGroup>
+
+</Project>