From 1b87ff9e352c1caa466572c74df84e0ffe9cda37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 17 Jun 2022 21:17:51 +0900 Subject: [PATCH] Fix failure building two libraries tests (#70881) Microsoft.CSharp was hitting an issue due to a vararg constructor. We don't support varargs. They shouldn't make it into the dependency graph. We are already checking in many places. We were erroneously thinking a vararg constructor with no mandatory arguments is a default constructor. Runtime.InteropServices were crashing because we got a MulticastDelegate type into a codepath that expects a MulticastDelegate descendant. --- src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs | 7 ++++++- .../Compiler/Dataflow/ReflectionMethodBodyScanner.cs | 2 +- .../tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs index 073cb7a4fdf..2b3b625db32 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs @@ -374,7 +374,12 @@ public override MethodDesc GetDefaultConstructor() && stringComparer.Equals(methodDefinition.Name, ".ctor")) { var method = (EcmaMethod)_module.GetObject(handle); - if (method.Signature.Length != 0) + MethodSignature sig = method.Signature; + + if (sig.Length != 0) + continue; + + if ((sig.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) == MethodSignatureFlags.CallingConventionVarargs) continue; return method; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs index 4343e5352da..18c5b082f60 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs @@ -625,7 +625,7 @@ public override bool HandleCall(MethodIL callingMethodBody, MethodDesc calledMet && !systemTypeValue.RepresentedType.Type.IsGenericDefinition && !systemTypeValue.RepresentedType.Type.ContainsSignatureVariables(treatGenericParameterLikeSignatureVariable: true)) { - if (systemTypeValue.RepresentedType.Type.IsDefType) + if (systemTypeValue.RepresentedType.Type.IsDelegate) { _reflectionMarker.Dependencies.Add(_factory.DelegateMarshallingData((DefType)systemTypeValue.RepresentedType.Type), "Marshal API"); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index a5f1ce07c3c..0f4dded3fe5 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -264,6 +264,8 @@ private void ImportCall(ILOpcode opcode, int token) var method = (MethodDesc)_canonMethodIL.GetObject(token); _compilation.TypeSystemContext.EnsureLoadableMethod(method); + if ((method.Signature.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) == MethodSignatureFlags.CallingConventionVarargs) + ThrowHelper.ThrowBadImageFormatException(); _compilation.NodeFactory.MetadataManager.GetDependenciesDueToAccess(ref _dependencies, _compilation.NodeFactory, _canonMethodIL, method); -- GitLab