diff options
author | Ankit Jain <radical@gmail.com> | 2022-05-28 09:02:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-28 09:02:07 +0300 |
commit | 38681fe9a1c6e1743a62e363a9d4561fa5d736a8 (patch) | |
tree | 92d12710a34269ec1c2b6d6cefd07b2149b703e6 /src | |
parent | e297470559fb95344ab52c8dad561885a1430e7e (diff) |
[wasm] Explicitly include mscorlib.dll, to support scanning assemblies (#69886)
* [wasm] Explicitly include mscorlib.dll, to support scanning assemblies
.. with mscorlib dependency.
This showed up when scanning `Dia2Lib` for icalls, which is indirectly
used by the microbenchmarks in `dotnet/performance`. It would fail with:
```
System.IO.FileNotFoundException: Could not find assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.
at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveAssembly(AssemblyReferenceHandle handle, EcmaModule module)
at System.Reflection.TypeLoading.Ecma.EcmaResolver.ComputeTypeRefResolution(TypeReferenceHandle handle, EcmaModule module)
at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveTypeRef(TypeReferenceHandle handle, EcmaModule module)
at System.Reflection.TypeLoading.Ecma.EcmaModule.GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, Byte rawTypeKind)
at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeTypeHandle(BlobReader& blobReader, Byte rawTypeKind, Boolean allowTypeSpecifications)
at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode)
at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode)
at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader)
at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase)
at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig()
at System.Reflection.TypeLoading.RoMethod.get_ReturnType()
at SignatureMapper.MethodToSignature(MethodInfo method)
at IcallTableGenerator.<ProcessType>g__AddSignature|15_1(Type type, MethodInfo method)
at IcallTableGenerator.ProcessType(Type type)
at IcallTableGenerator.GenIcallTable(String runtimeIcallTableFile, String[] assemblies, String outputPath)
at ManagedToNativeGenerator.ExecuteInternal()
at ManagedToNativeGenerator.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```
This is thrown when `SignatureMapper.MethodToSignature` called
`method.ReturnType` for:
```
.method public hidebysig newslot virtual
instance void loadAndValidateDataFromPdb([in] string marshal( lpwstr) pdbPath,
[in] [mscorlib]System.Guid& pcsig70,
[in] uint32 sig,
[in] uint32 age) runtime managed internalcall
{
.override Dia2Lib.IDiaDataSource::loadAndValidateDataFromPdb
} // end of method DiaSourceClass::loadAndValidateDataFromPdb
```
We use `PathAssemblyResolver` with a closed set of assemblies, which
didn't include mscorlib.dll . So, we include that explicitly from the
runtime pack.
Fixes https://github.com/dotnet/runtime/issues/69861
* Add mscorlib.dll, only if it wasn't already there.
`System.Reflection.MetadataLoadContext.Tests` tests failed:
```
The "ManagedToNativeGenerator" task failed unexpectedly. [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
System.IO.FileLoadException: The assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already loaded been loaded into this MetadataLoadContext. [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at System.Reflection.MetadataLoadContext.LoadFromStreamCore(Stream peStream) [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at System.Reflection.MetadataLoadContext.LoadFromAssemblyPath(String assemblyPath) [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at PInvokeTableGenerator.GenPInvokeTable(String[] pinvokeModules, String[] assemblies, String outputPath) in /_/src/tasks/WasmAppBuilder/PInvokeTableGenerator.cs:line 37 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at ManagedToNativeGenerator.ExecuteInternal() in /_/src/tasks/WasmAppBuilder/ManagedToNativeGenerator.cs:line 71 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at ManagedToNativeGenerator.Execute() in /_/src/tasks/WasmAppBuilder/ManagedToNativeGenerator.cs:line 56 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```
Diffstat (limited to 'src')
-rw-r--r-- | src/mono/wasm/build/WasmApp.Native.targets | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 317597e45db..2a700da6487 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -272,7 +272,12 @@ <_WasmPInvokeModules Include="libSystem.Globalization.Native" /> <_WasmPInvokeModules Include="libSystem.Security.Cryptography.Native.Browser" /> </ItemGroup> - + + <PropertyGroup> + <_HasMscorlib Condition="'%(_WasmAssembliesInternal.FileName)%(_WasmAssembliesInternal.Extension)' == 'mscorlib.dll'">true</_HasMscorlib> + <_MscorlibPath Condition="'$(_HasMscorlib)' != 'true'">$(MicrosoftNetCoreAppRuntimePackRidDir)lib\net7.0\mscorlib.dll</_MscorlibPath> + </PropertyGroup> + <Error Condition="'$(_MonoAotCrossCompilerPath)' == '' or !Exists('$(_MonoAotCrossCompilerPath)')" Text="Could not find AOT cross compiler at %24(_MonoAotCrossCompilerPath)=$(_MonoAotCrossCompilerPath)" /> @@ -284,7 +289,7 @@ <MakeDir Directories="$(_WasmIntermediateOutputPath)" Condition="!Exists('$(_WasmIntermediateOutputPath)')" /> <ManagedToNativeGenerator - Assemblies="@(_WasmAssembliesInternal)" + Assemblies="@(_WasmAssembliesInternal);$(_MscorlibPath)" RuntimeIcallTableFile="$(_WasmRuntimeICallTablePath)" IcallOutputPath="$(_WasmICallTablePath)" PInvokeModules="@(_WasmPInvokeModules)" |