From d43aec85ca4d5565c69f39fab204ba8d7436239f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 27 May 2024 13:44:28 +0200 Subject: [PATCH] [tools] Update how we encode AOT symbols according to upstream changes. Ref: https://github.com/dotnet/runtime/pull/101681. --- tools/common/Target.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/common/Target.cs b/tools/common/Target.cs index 3afd261f0a76..3e674c7b802a 100644 --- a/tools/common/Target.cs +++ b/tools/common/Target.cs @@ -933,10 +933,13 @@ void GenerateIOSMain (StringWriter sw, Abi abi) sw.WriteLine ("}"); } + static readonly char[] charsToReplaceAot = new[] { '.', '-', '+', '<', '>' }; static string EncodeAotSymbol (string symbol) { var sb = new StringBuilder (); /* This mimics what the aot-compiler does */ + // https://github.com/dotnet/runtime/blob/2f08fcbfece0c09319f237a6aee6f74c4a9e14e8/src/mono/mono/metadata/native-library.c#L1265-L1284 + // https://github.com/dotnet/runtime/blob/2f08fcbfece0c09319f237a6aee6f74c4a9e14e8/src/tasks/Common/Utils.cs#L419-L445 foreach (var b in System.Text.Encoding.UTF8.GetBytes (symbol)) { char c = (char) b; if ((c >= '0' && c <= '9') || @@ -944,8 +947,12 @@ static string EncodeAotSymbol (string symbol) (c >= 'A' && c <= 'Z')) { sb.Append (c); continue; + } else if (charsToReplaceAot.Contains (c)) { + sb.Append ('_'); + } else { + // Append the hex representation of b between underscores + sb.Append ($"_{b:X}_"); } - sb.Append ('_'); } return sb.ToString (); }