未验证 提交 872698f6 编写于 作者: A Ankit Jain 提交者: GitHub

AOTCompilerTask: use assembly name to build the aot linking symbols (#53659)

`System.Runtime.Loader.DefaultContext.Tests` fail with `wasm+aot`
Fixes https://github.com/dotnet/runtime/issues/52383

From the issue:

```
[10:39:59] info: * Assertion at /__w/1/s/src/mono/mono/mini/aot-runtime.c:2330, condition `<disabled>' not met
[10:39:59] info: 
[10:39:59] info: ABORT: undefined
[10:39:59] info: Stacktrace:
[10:39:59] info: 
[10:39:59] info: Error
[10:39:59] info:     at Object.onAbort (runtime.js:217:13)
[10:39:59] info:     at abort (dotnet.js:1233:22)
[10:39:59] info:     at _abort (dotnet.js:5561:7)
[10:39:59] info:     at monoeg_assert_abort (<anonymous>:wasm-function[5943]:0xdadad)
[10:39:59] info:     at monoeg_log_default_handler (<anonymous>:wasm-function[5960]:0xdb0c8)
[10:39:59] info:     at monoeg_g_logstr (<anonymous>:wasm-function[5953]:0xdaf76)
[10:39:59] info:     at monoeg_g_logv_nofree (<anonymous>:wasm-function[5951]:0xdaf28)
[10:39:59] info:     at monoeg_assertion_message (<anonymous>:wasm-function[5956]:0xdaff2)
[10:39:59] info:     at mono_assertion_message (<anonymous>:wasm-function[5958]:0xdb035)
[10:39:59] info:     at mono_assertion_message_disabled (<anonymous>:wasm-function[5957]:0xdb008)
[10:39:59] info:     at mono_aot_register_module (<anonymous>:wasm-function[5045]:0xbb12a)
[10:39:59] info:     at register_aot_modules (<anonymous>:wasm-function[59156]:0x12f4753)
```

vargaz: This actually happens because the generated AOT linking symbol in driver-gen.c is not correct.
Its generated from the filename, which is System.Runtime.Loader.Noop.Assembly_test.dll, but the assembly name is System.Runtime.Loader.Noop.Assembly. So linking the final app should fail, but emscripten doesn't notice the missing symbol because of https://github.com/emscripten-core/emscripten/issues/14106 .
So this turns into a runtime assertion.

- Also, enable the tests.
上级 aea3ac56
...@@ -261,9 +261,6 @@ ...@@ -261,9 +261,6 @@
<!-- Issue: https://github.com/dotnet/runtime/issues/50965 --> <!-- Issue: https://github.com/dotnet/runtime/issues/50965 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Encodings.Web\tests\System.Text.Encodings.Web.Tests.csproj" /> <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Encodings.Web\tests\System.Text.Encodings.Web.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/51680 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Loader\tests\DefaultContext\System.Runtime.Loader.DefaultContext.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/51678 --> <!-- Issue: https://github.com/dotnet/runtime/issues/51678 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Loader\tests\System.Runtime.Loader.Tests.csproj" /> <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Loader\tests\System.Runtime.Loader.Tests.csproj" />
......
...@@ -7,10 +7,12 @@ ...@@ -7,10 +7,12 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using System.Reflection.PortableExecutable;
public class MonoAOTCompiler : Microsoft.Build.Utilities.Task public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
{ {
...@@ -217,10 +219,8 @@ public override bool Execute() ...@@ -217,10 +219,8 @@ public override bool Execute()
throw new ArgumentException($"'{nameof(AotModulesTableLanguage)}' must be one of: '{nameof(MonoAotModulesTableLanguage.C)}', '{nameof(MonoAotModulesTableLanguage.ObjC)}'. Received: '{AotModulesTableLanguage}'.", nameof(AotModulesTableLanguage)); throw new ArgumentException($"'{nameof(AotModulesTableLanguage)}' must be one of: '{nameof(MonoAotModulesTableLanguage.C)}', '{nameof(MonoAotModulesTableLanguage.ObjC)}'. Received: '{AotModulesTableLanguage}'.", nameof(AotModulesTableLanguage));
} }
if (!string.IsNullOrEmpty(AotModulesTablePath)) if (!string.IsNullOrEmpty(AotModulesTablePath) && !GenerateAotModulesTable(Assemblies, Profilers))
{ return false;
GenerateAotModulesTable(Assemblies, Profilers);
}
string? monoPaths = null; string? monoPaths = null;
if (AdditionalAssemblySearchPaths != null) if (AdditionalAssemblySearchPaths != null)
...@@ -431,13 +431,23 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths) ...@@ -431,13 +431,23 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths)
return true; return true;
} }
private void GenerateAotModulesTable(ITaskItem[] assemblies, string[]? profilers) private bool GenerateAotModulesTable(ITaskItem[] assemblies, string[]? profilers)
{ {
var symbols = new List<string>(); var symbols = new List<string>();
foreach (var asm in assemblies) foreach (var asm in assemblies)
{ {
var name = Path.GetFileNameWithoutExtension(asm.ItemSpec).Replace ('.', '_').Replace ('-', '_'); string asmPath = asm.ItemSpec;
symbols.Add($"mono_aot_module_{name}_info"); if (!File.Exists(asmPath))
{
Log.LogError($"Could not find assembly {asmPath}");
return false;
}
if (!TryGetAssemblyName(asmPath, out string? assemblyName))
return false;
string symbolName = assemblyName.Replace ('.', '_').Replace ('-', '_');
symbols.Add($"mono_aot_module_{symbolName}_info");
} }
Directory.CreateDirectory(Path.GetDirectoryName(AotModulesTablePath!)!); Directory.CreateDirectory(Path.GetDirectoryName(AotModulesTablePath!)!);
...@@ -504,6 +514,34 @@ private void GenerateAotModulesTable(ITaskItem[] assemblies, string[]? profilers ...@@ -504,6 +514,34 @@ private void GenerateAotModulesTable(ITaskItem[] assemblies, string[]? profilers
} }
Log.LogMessage(MessageImportance.Low, $"Generated {AotModulesTablePath}"); Log.LogMessage(MessageImportance.Low, $"Generated {AotModulesTablePath}");
} }
return true;
}
private bool TryGetAssemblyName(string asmPath, [NotNullWhen(true)] out string? assemblyName)
{
assemblyName = null;
try
{
using var fs = new FileStream(asmPath, FileMode.Open, FileAccess.Read);
using var peReader = new PEReader(fs);
MetadataReader mr = peReader.GetMetadataReader();
assemblyName = mr.GetAssemblyDefinition().GetAssemblyName().Name;
if (string.IsNullOrEmpty(assemblyName))
{
Log.LogError($"Could not get assembly name for {asmPath}");
return false;
}
return true;
}
catch (Exception ex)
{
Log.LogError($"Failed to get assembly name for {asmPath}: {ex.Message}");
return false;
}
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.Build.Framework" Version="$(RefOnlyMicrosoftBuildFrameworkVersion)" /> <PackageReference Include="Microsoft.Build.Framework" Version="$(RefOnlyMicrosoftBuildFrameworkVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(RefOnlyMicrosoftBuildTasksCoreVersion)" /> <PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(RefOnlyMicrosoftBuildTasksCoreVersion)" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(RefOnlyMicrosoftBuildUtilitiesCoreVersion)" /> <PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(RefOnlyMicrosoftBuildUtilitiesCoreVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MonoAOTCompiler.cs" /> <Compile Include="MonoAOTCompiler.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册