-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/6.0] [mono] Use unsigned char when computing UTF8 string has…
…hes (#83303) * [mono] Use `unsigned char` when computing UTF8 string hashes The C standard does not specify whether `char` is signed or unsigned, it is implementation defined. Apparently Android aarch64 makes a different choice than other platforms (at least macOS arm64 and Windows x64 give different results). Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime to optimize class name lookup. As a result, classes whose names include UTF-8 continuation bytes (with the high bit = 1) will hash differently in the AOT compiler and on the device. Fixes #82187 Fixes #78638 * Add regression test --------- Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
- Loading branch information
1 parent
fc32833
commit 0254cce
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/tests/Loader/classloader/regressions/GitHub_82187/GitHub_82187.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="repro.cs" /> | ||
</ItemGroup> | ||
</Project> |
31 changes: 31 additions & 0 deletions
31
src/tests/Loader/classloader/regressions/GitHub_82187/repro.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
|
||
/* Regression test for https://github.com/dotnet/runtime/issues/78638 | ||
* and https://github.com/dotnet/runtime/issues/82187 ensure AOT | ||
* cross-compiler and AOT runtime use the same name hashing for names | ||
* that include UTF-8 continuation bytes. | ||
*/ | ||
|
||
[MySpecial(typeof(MeineTüre))] | ||
public class Program | ||
{ | ||
public static int Main() | ||
{ | ||
var attr = (MySpecialAttribute)Attribute.GetCustomAttribute(typeof (Program), typeof(MySpecialAttribute), false); | ||
if (attr == null) | ||
return 101; | ||
if (attr.Type == null) | ||
return 102; | ||
if (attr.Type.FullName != "MeineTüre") | ||
return 103; | ||
return 100; | ||
} | ||
} | ||
|
||
public class MySpecialAttribute : Attribute | ||
{ | ||
public Type Type {get; private set; } | ||
public MySpecialAttribute(Type t) { Type = t; } | ||
} | ||
|
||
public class MeineTüre {} |