runtime: Referencing OpenTK.Mathematics crashes the Ready2Run build.
Description
When referencing OpenTK.Mathematics (or OpenTK.Windowing.Desktop), I’m getting a NotImplementedException on a Ready2Run publish and the build fails.
Demo project for reproduction:
Steps to reproduce the problem:
- Publish the demo project with the following settings:
Configuration
- .NET 6
- Windows 10
- Architecture: x64
Other information
2>ConsoleApp1 -> C:\Users\Win10 Home x64\source\repos\ConsoleApp1\ConsoleApp1\bin\Release\net6.0\win-x64\ConsoleApp1.dll
2>Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
2>C:\Users\Win10 Home x64.nuget\packages\microsoft.netcore.app.crossgen2.win-x64\6.0.0-preview.6.21352.12\tools\crossgen2.exe --targetos:windows
2>–targetarch:x64
2>-O
2>-r:“obj\Release\net6.0\win-x64\linked\OpenTK.Mathematics.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\ConsoleApp1.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Collections.Immutable.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Collections.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.ComponentModel.Primitives.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.ComponentModel.TypeConverter.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Console.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Diagnostics.StackTrace.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Drawing.Primitives.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Drawing.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.IO.Compression.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.IO.MemoryMappedFiles.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.ObjectModel.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Private.CoreLib.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Private.Xml.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Reflection.Metadata.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Runtime.CompilerServices.Unsafe.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Runtime.Extensions.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Runtime.InteropServices.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Runtime.Intrinsics.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Runtime.dll”
2>-r:“obj\Release\net6.0\win-x64\linked\System.Xml.ReaderWriter.dll”
2>–out:“obj\Release\net6.0\win-x64\R2R\OpenTK.Mathematics.dll”
2>obj\Release\net6.0\win-x64\linked\OpenTK.Mathematics.dll
2>
2>Error: The method or operation is not implemented.
2>System.NotImplementedException: The method or operation is not implemented.
2> at Internal.TypeSystem.Ecma.EcmaModule.GetType(String nameSpace, String name, NotFoundBehavior notFoundBehavior) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x6000573+0x145
2> at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x600057c+0x2e
2> at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x60006d6+0x131
2> at Internal.TypeSystem.LockFreeReaderHashtable2.CreateValueAndEnsureValueIsInTable(TKey key) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x60003ba+0x0 2> at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle, NotFoundBehavior notFoundBehavior) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x6000577+0x0 2> at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle) in ILCompiler.TypeSystem.ReadyToRun.dll:token 0x6000574+0x0 2> at ILCompiler.ReadyToRunCompilationModuleGroupBase.TryGetModuleTokenForExternalType(TypeDesc type, ModuleToken& token) in ILCompiler.ReadyToRun.dll:token 0x60000d4+0x51 2> at ILCompiler.DependencyAnalysis.ReadyToRun.ModuleTokenResolver.GetModuleTokenForType(EcmaType type, Boolean throwIfNotFound) in ILCompiler.ReadyToRun.dll:token 0x60005af+0x3c 2> at ILCompiler.DependencyAnalysis.ReadyToRun.SignatureContext.GetTargetModule(TypeDesc type) in ILCompiler.ReadyToRun.dll:token 0x600061e+0x35 2> at ILCompiler.DependencyAnalysis.ReadyToRun.TypeFixupSignature.GetData(NodeFactory factory, Boolean relocsOnly) in ILCompiler.ReadyToRun.dll:token 0x600065c+0x9 2> at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitPortableExecutable() in ILCompiler.ReadyToRun.dll:token 0x6000323+0x174 2> at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in ILCompiler.ReadyToRun.dll:token 0x600012f+0x35 2> at ILCompiler.Program.RunSingleCompilation(Dictionary
2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary2 unrootedInputFilePaths, HashSet
1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext) in crossgen2.dll:token 0x600015a+0x5e7
2> at ILCompiler.Program.Run(String[] args) in crossgen2.dll:token 0x6000159+0x52e
2> at ILCompiler.Program.Main(String[] args) in crossgen2.dll:token 0x6000161+0x5
I’m assuming it’s this line right here: https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs#L322
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (13 by maintainers)
Commits related to this issue
- Harvest signatures of methods being compiled by the token resolver Fixes: https://github.com/dotnet/runtime/issues/56971 I believe this is the primary fix for the issue; when a type only ever occurs... — committed to trylek/runtime by trylek 3 years ago
- Harvest signatures of methods being compiled by the token resolver (#57366) Fixes: https://github.com/dotnet/runtime/issues/56971 I believe this is the primary fix for the issue; when a type only ... — committed to dotnet/runtime by trylek 3 years ago
I’ve confirmed that the issue with the linker writing invalid exports was fixed by https://github.com/mono/linker/commit/664e78edc72dd0a48e6f55e352051b6ba61bba9a.
The issue is that to return true for IsForwarder, the implementation token needs to reference an AssemblyRef. If you look at the exported type Implementation token, in the ildasm output you can see that the token is 0x26000000. That indicates a token into the File table with Rid 0. This is nonsense and an indication that the IL Linker did something unfortunate. We should probably fix the code to detect this sort of nonsense and simple not consider that ExportedType token as meaningful, and file a bug against the IL linker to not spit that out.