[mono] Use `unsigned char` when computing UTF8 string hashes (#21632)
commitef0450d2e42a961b857a144eb986fcc5eabe595d
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Mon, 13 Mar 2023 11:57:25 +0000 (13 07:57 -0400)
committerGitHub <noreply@github.com>
Mon, 13 Mar 2023 11:57:25 +0000 (13 12:57 +0100)
tree36808e48f99b06dd6128e50bbf8ce39b28eb4236
parent0904a6073ca8011db5a917c36fbbf8ca45c70497
[mono] Use `unsigned char` when computing UTF8 string hashes (#21632)

Backport of https://github.com/dotnet/runtime/pull/83273 to mono/mono `main`

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.

Contributes to https://github.com/dotnet/runtime/issues/82187
Contributes to https://github.com/dotnet/runtime/issues/78638
mono/eglib/ghashtable.c
mono/metadata/metadata.c