From 0b9b0ee2d3898badea0f7644bf7d35e6e0264b84 Mon Sep 17 00:00:00 2001 From: jfrijters Date: Thu, 1 Feb 2007 07:13:02 +0000 Subject: [PATCH] - Changed ikvmc to fail with a Link Error when it detects a loader constraints violation (instead of emitting code that throws a LinkageError at runtime). --- ikvmc/CompilerClassLoader.cs | 26 ++++++++++++++++++++++++++ runtime/TypeWrapper.cs | 6 ++++++ runtime/verifier.cs | 9 +++++++++ 3 files changed, 41 insertions(+) diff --git a/ikvmc/CompilerClassLoader.cs b/ikvmc/CompilerClassLoader.cs index 772cc65e..bf14429c 100644 --- a/ikvmc/CompilerClassLoader.cs +++ b/ikvmc/CompilerClassLoader.cs @@ -2672,5 +2672,31 @@ namespace IKVM.Internal Console.Error.Write("{0} IKVMC{1:D4}: ", msgId < Message.StartWarnings ? "Note" : "Warning", (int)msgId); Console.Error.WriteLine(msg, values); } + + internal static void LinkageError(string msg, TypeWrapper actualType, TypeWrapper expectedType, params object[] values) + { + object[] args = new object[values.Length + 2]; + values.CopyTo(args, 2); + args[0] = AssemblyQualifiedName(actualType); + args[1] = AssemblyQualifiedName(expectedType); + Console.Error.WriteLine("Link Error: " + msg, args); + Environment.Exit(1); + } + + private static string AssemblyQualifiedName(TypeWrapper tw) + { + ClassLoaderWrapper loader = tw.GetClassLoader(); + AssemblyClassLoader acl = loader as AssemblyClassLoader; + if(acl != null) + { + return tw.Name + ", " + acl.Assembly.FullName; + } + CompilerClassLoader ccl = loader as CompilerClassLoader; + if(ccl != null) + { + return tw.Name + ", " + ccl.GetTypeWrapperFactory().ModuleBuilder.Assembly.FullName; + } + return tw.Name + " (unknown assembly)"; + } } } diff --git a/runtime/TypeWrapper.cs b/runtime/TypeWrapper.cs index 6fc40b95..f4f9d603 100644 --- a/runtime/TypeWrapper.cs +++ b/runtime/TypeWrapper.cs @@ -4172,6 +4172,9 @@ namespace IKVM.Internal } else { +#if STATIC_COMPILER + StaticCompiler.LinkageError("Method \"{2}.{3}{4}\" has a return type \"{0}\" and tries to override method \"{5}.{3}{4}\" that has a return type \"{1}\"", mw.ReturnType, baseMethod.ReturnType, mw.DeclaringType.Name, mw.Name, mw.Signature, baseMethod.DeclaringType.Name); +#endif throw new LinkageError("Loader constraints violated"); } } @@ -4190,6 +4193,9 @@ namespace IKVM.Internal } else { +#if STATIC_COMPILER + StaticCompiler.LinkageError("Method \"{2}.{3}{4}\" has an argument type \"{0}\" and tries to override method \"{5}.{3}{4}\" that has an argument type \"{1}\"", here[i], there[i], mw.DeclaringType.Name, mw.Name, mw.Signature, baseMethod.DeclaringType.Name); +#endif throw new LinkageError("Loader constraints violated"); } } diff --git a/runtime/verifier.cs b/runtime/verifier.cs index 4f70fd34..2085f2f6 100644 --- a/runtime/verifier.cs +++ b/runtime/verifier.cs @@ -3243,6 +3243,9 @@ class MethodAnalyzer } if(cpi.GetFieldType() != field.FieldTypeWrapper && !field.FieldTypeWrapper.IsUnloadable) { +#if STATIC_COMPILER + StaticCompiler.LinkageError("Field \"{2}.{3}\" is of type \"{0}\" instead of type \"{1}\" as expected by \"{4}\"", field.FieldTypeWrapper, cpi.GetFieldType(), cpi.GetClassType().Name, cpi.Name, wrapper.Name); +#endif instr.SetHardError(HardError.LinkageError, AllocErrorMessage("Loader constraints violated: " + field.DeclaringType.Name + "." + field.Name)); return; } @@ -3305,6 +3308,9 @@ class MethodAnalyzer { if(cpi.GetRetType() != mw.ReturnType && !mw.ReturnType.IsUnloadable) { +#if STATIC_COMPILER + StaticCompiler.LinkageError("Method \"{2}.{3}{4}\" has a return type \"{0}\" instead of type \"{1}\" as expected by \"{5}\"", mw.ReturnType, cpi.GetRetType(), cpi.GetClassType().Name, cpi.Name, cpi.Signature, classFile.Name); +#endif return "Loader constraints violated (return type): " + mw.DeclaringType.Name + "." + mw.Name + mw.Signature; } TypeWrapper[] here = cpi.GetArgTypes(); @@ -3313,6 +3319,9 @@ class MethodAnalyzer { if(here[i] != there[i] && !there[i].IsUnloadable) { +#if STATIC_COMPILER + StaticCompiler.LinkageError("Method \"{2}.{3}{4}\" has a argument type \"{0}\" instead of type \"{1}\" as expected by \"{5}\"", there[i], here[i], cpi.GetClassType().Name, cpi.Name, cpi.Signature, classFile.Name); +#endif return "Loader constraints violated (arg " + i + "): " + mw.DeclaringType.Name + "." + mw.Name + mw.Signature; } }