Repository navigation
Closed
Labels
Description
If you compile application with custom runtime where System.AppContext class is not defined, compiler crash
Unhandled exception. ILCompiler.CodeGenerationFailedException: Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.SetAppContextSwitches()'
---> System.InvalidOperationException: Expected type 'System.AppContext' not found in module 'SeeSharpSnake'
at Internal.IL.HelperExtensions.GetKnownType(ModuleDesc module, String namespace, String name) in ILCompiler.Compiler.dll:token 0x60000ff+0x35
at Internal.IL.Stubs.StartupCode.AppContextInitializerMethod.EmitIL() in ILCompiler.Compiler.dll:token 0x6000144+0x5
at Internal.IL.CoreRTILProvider.GetMethodIL(MethodDesc method) in ILCompiler.Compiler.dll:token 0x6000077+0x8f
at ILCompiler.FeatureSwitchManager.GetMethodIL(MethodDesc method) in ILCompiler.Compiler.dll:token 0x60002c8+0x13
at ILCompiler.Compilation.CombinedILProvider.GetMethodIL(MethodDesc method) in ILCompiler.Compiler.dll:token 0x6001049+0x0
at ILCompiler.Compilation.ILCache.CreateValueFromKey(MethodDesc key) in ILCompiler.Compiler.dll:token 0x6001047+0x5
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) in ILCompiler.TypeSystem.dll:token 0x6000486+0x0
at ILCompiler.Compilation.GetMethodIL(MethodDesc method) in ILCompiler.Compiler.dll:token 0x6000309+0x28
at Internal.IL.ILImporter..ctor(ILScanner compilation, MethodDesc method, MethodIL methodIL) in ILCompiler.Compiler.dll:token 0x600008c+0x11
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in ILCompiler.Compiler.dll:token 0x60002ed+0x7
--- End of inner exception stack trace ---
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in ILCompiler.Compiler.dll:token 0x60002ed+0x56
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() in System.Private.CoreLib.dll:token 0x6002ba2+0x14
at System.Threading.ThreadPoolWorkQueue.Dispatch() in System.Private.CoreLib.dll:token 0x6002b7c+0xa0
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in System.Private.CoreLib.dll:token 0x6002c66+0x67
at System.Threading.Thread.StartCallback() in System.Private.CoreLib.dll:token 0x600280f+0xe
Which is there
Line 70 in 699b0ae
| MetadataType appContextType = Context.SystemModule.GetKnownType("System", "AppContext"); |
I think that initializer should produce empty method and do not crash the compiler. For example in UEFI maybe AppContext switches is not so good idea.
Activity
MichalStrehovsky commentedon Jan 17, 2022
Add this to your project: https://github.com/MichalStrehovsky/zerosharp/blob/186dc165ec5cce3033200e1d4177b9bbb89fb7d9/no-runtime/noruntime.csproj#L35-L40
The compiler needs to fail if it's told to set AppContext switches on the ILC command line but there's no AppContext class in the core library. It cannot ignore what the user told it to do.
kant2002 commentedon Jan 17, 2022
Done! Thanks.
Maybe then we should produce nice error message which basically say something like that "AppContext switches passed, but no AppContext class not present in the runtime"?
MichalStrehovsky commentedon Jan 17, 2022
People who don't use System.Private.CoreLib are already expected to read ILC source code because they're deep in unsupported territories.
Expected type 'System.AppContext' not found in module 'SeeSharpSnake'is par for the course in that mode ("CoreLib doesn't have the thing I need in it").If you're up for submitting a pull request along the lines of
runtime/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs
Lines 131 to 132 in ae2f60c
we can fix this, but otherwise I would just close this.
But it will be just another TODO for "we need to throw something better than Exception" and "we'll need to put this into a RESX file so that it's localizable at some point".