dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 508 forks source link

Unhandled Exception: ILCompiler.CodeGenerationFailedException: Code generation failed for method #8346

Open Powerlated opened 4 years ago

Powerlated commented 4 years ago
Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception: Unhandled Exception:
  Unhandled Exception:
  Unhandled Exception:
  Unhandled Exception: ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,ShaderType,string&,int32[])'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32&)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,ShaderType,string&,int32*)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,All,string&,int32[])'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32[])'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,All,string&,int32*)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
  ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,All,string&,int32&)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,All,string&,int32*)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,ShaderType,string&,int32&)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(uint32,All,string&,int32[])'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK]OpenTK.Graphics.ES30.GL+Qcom.ExtGetProgramBinarySource(int32,All,string&,int32&)'
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.ThreadPoolWorkQueue.Dispatch()

I am attempting to dotnet publish -r win-x64 -c Release a program and I receieve this error after the Generating compatible native code. message.

jkotas commented 4 years ago

OpenTK assembly contains invalid IL:

    .method public hidebysig static void 
            ExtGetProgramBinarySource(int32 program,
                                      valuetype OpenTK.Graphics.ES30.All shadertype,
                                      [out] string& source,
                                      [out] int32[] length) cil managed
    {
      .maxstack  7
      .locals init (native int V_0,
               int32 V_1,
               int32& pinned V_2)
      IL_0000:  ldarg.0
      IL_0001:  ldarg.1
      IL_0002:  ldarg.2
      IL_0003:  pop
      IL_0004:  ldarg.3 <- the type of 3rd argument is `int32[]`
      IL_0005:  ldind.i4 <- ldind.i4 on `int32[]` is invalid IL operation
...

(This is just one example. There are more.)

It is crashing the JIT with CORJIT_INTERNALERROR and in turn crashing the compiler.

jkotas commented 4 years ago

OpenTK project is using IL generator https://github.com/opentk/opentk/tree/master/src/Generator.Rewrite that seems to be responsible for the invalid IL.

We should look into reporting this error in a better way, but the underlying problem should be fixed in OpenTK project. @Powerlated Could you please open an issue on this in OpenTK project?