Skip to content

Commit

Permalink
Fix Crossgen2 bug #61104 and add regression test (#63956)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trylek authored Jan 20, 2022
1 parent 94b699c commit 93dc760
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public static int NameHashCode(string name)
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
{
Expand Down
12 changes: 12 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_61104/test61104.cs
Original file line number Diff line number Diff line change
@@ -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_
{
}
17 changes: 17 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_61104/test61104.csproj
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 93dc760

Please sign in to comment.