Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker crashes on CustomAttribute with enum declared in generic class #2332

Closed
mrvoorhe opened this issue Oct 26, 2021 · 5 comments
Closed

Comments

@mrvoorhe
Copy link
Contributor

Mono.Linker.LinkerFatalErrorException: ILLink: error IL1005: Mono.Linker.Tests.Cases.Attributes.GenericEnumInAttribute.Main(): Error processing method 'Mono.Linker.Tests.Cases.Attributes.GenericEnumInAttribute.Method()' in assembly 'test.exe'
 ---> System.NotImplementedException: GenericInst
   at Mono.Cecil.SignatureReader.ReadPrimitiveValue(ElementType type) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3643
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3611
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3591
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3591
   at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3526
   at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArgument(Collection`1& fields, Collection`1& properties) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3556
   at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArguments(UInt16 count, Collection`1& fields, Collection`1& properties) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 3534
   at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\AssemblyReader.cs:line 2597
   at Mono.Cecil.CustomAttribute.<Resolve>b__35_0(CustomAttribute attribute, MetadataReader reader) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\CustomAttribute.cs:line 204
   at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read) in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\ModuleDefinition.cs:line 982
   at Mono.Cecil.CustomAttribute.Resolve() in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\CustomAttribute.cs:line 202
   at Mono.Cecil.CustomAttribute.get_HasConstructorArguments() in C:\Unity\dev\unity-monolinker-2\external\cecil\Mono.Cecil\CustomAttribute.cs:line 99
   at Mono.Linker.Steps.MarkStep.MarkCustomAttributeArguments(CustomAttribute ca) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 1284
   at Mono.Linker.Steps.MarkStep.MarkCustomAttribute(CustomAttribute ca, DependencyInfo& reason) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 1079
   at Mono.Linker.Steps.MarkStep.MarkCustomAttributes(ICustomAttributeProvider provider, DependencyInfo& reason) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 793
   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, Scope& scope) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 2975
   at Mono.Linker.Steps.MarkStep.ProcessQueue() in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 513
   --- End of inner exception stack trace ---
   at Mono.Linker.Steps.MarkStep.ProcessQueue() in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 515
   at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 434
   at Mono.Linker.Steps.MarkStep.Process() in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 375
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker.Steps\MarkStep.cs:line 213
   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker\Pipeline.cs:line 166
   at Mono.Linker.Pipeline.Process(LinkContext context) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker\Pipeline.cs:line 159
   at Mono.Linker.Driver.Run(ILogger customLogger, Boolean throwOnFatalLinkerException) in C:\Unity\dev\unity-monolinker-2\src\linker\Linker\Driver.cs:line 771

Here is a test case to reproduce

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Mono.Linker.Tests.Cases.Expectations.Assertions;

namespace Mono.Linker.Tests.Cases.Attributes
{
	public class GenericEnumInAttribute
	{
		public static void Main ()
		{
			Method();
		}

		[Bar (Value = MyGenericClass<string>.MyEnum.One)]
		[KeptAttributeAttribute (typeof (BarAttribute))]
		static void Method ()
		{
		}

		[Kept]
		[KeptBaseType (typeof(Attribute))]
		class BarAttribute : Attribute
		{
			[Kept]
			public object Value { get;  [Kept] set; }
		}

		[Kept]
		[KeptMember ("value__")]
		[KeptBaseType (typeof (Enum))]
		class MyGenericClass<T>
		{
			[Kept]
			public enum MyEnum
			{
				[Kept]
				One,
			}
		}
	}
}
@mrvoorhe
Copy link
Contributor Author

I created an issue for cecil as well to track this jbevain/cecil#804

@mrvoorhe
Copy link
Contributor Author

@marek-safar or @vitek-karas Any chance I can pass this one off to you guys to handle? It's bug that could easily impact any assembly.

@vitek-karas
Copy link
Member

I'll see if anybody on our end wants to dive deep into Cecil to fix this 😉

@vitek-karas
Copy link
Member

I created jbevain/cecil#827 to fix this.

@vitek-karas
Copy link
Member

The issue is fixed in Cecil and brought to linker with #2640.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants