-
Notifications
You must be signed in to change notification settings - Fork 126
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
Attribute removal should not kick in for assemblies which are not linked #1344
Attribute removal should not kick in for assemblies which are not linked #1344
Conversation
MarkStep go over all assemblies (Regardless if they're being linked or just copied) and marks everything as usual. But in the end it will not "trim" anything from the copy assembly. So we must make sure that everything the assembly needs is marked. Attribute removal needs to comply with this behavior as well. This change fixes several other issues around link attribute XML files: - If the XML refers to an attribute which will in turn bring in new assemblies to the closure it would not correctly register all of them - the step needs to behave just like any other step which can bring in new assembly to the closure - Several places in MarkStep didn't use the CustomAttributeSource to detect presense of attributes - meaning that injecting attributes via the XML on a member which had no other (IL based) attributes didn't actually do anything. - Also fixed the annotation's handling of the same issue - presence of custom attributes needs to be determined via the CustomAttributeSource in any place where attributes which are recognized by the linker as special are handled. Added tests for all of the changes above
src/linker/Linker.Steps/MarkStep.cs
Outdated
@@ -531,10 +531,11 @@ void MarkMarshalSpec (IMarshalInfoProvider spec, in DependencyInfo reason, IMemb | |||
|
|||
void MarkCustomAttributes (ICustomAttributeProvider provider, in DependencyInfo reason, IMemberDefinition sourceLocationMember) | |||
{ | |||
if (!provider.HasCustomAttributes) | |||
if (!_context.CustomAttributes.HasAttributes (provider)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to have if (provider.HasCustomAttributes) { ... }
for the section which iterates provider.CustomAttributes
. The logic after that will work as it's
src/linker/Linker.Steps/MarkStep.cs
Outdated
@@ -808,11 +809,13 @@ bool MarkDependencyField (TypeDefinition type, string name, in DependencyInfo re | |||
|
|||
void LazyMarkCustomAttributes (ICustomAttributeProvider provider) | |||
{ | |||
if (!provider.HasCustomAttributes) | |||
if (!_context.CustomAttributes.HasAttributes (provider)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - for now... I reverted the change.
I pulled this change and verified it fixes the error I am seeing when trying to use the changes in dotnet/runtime#39000 to link a Blazor application. |
…ked (dotnet/linker#1344) * Attribute removal should not kick in for assemblies which are not linked MarkStep go over all assemblies (Regardless if they're being linked or just copied) and marks everything as usual. But in the end it will not "trim" anything from the copy assembly. So we must make sure that everything the assembly needs is marked. Attribute removal needs to comply with this behavior as well. This change fixes several other issues around link attribute XML files: - If the XML refers to an attribute which will in turn bring in new assemblies to the closure it would not correctly register all of them - the step needs to behave just like any other step which can bring in new assembly to the closure - Several places in MarkStep didn't use the CustomAttributeSource to detect presense of attributes - meaning that injecting attributes via the XML on a member which had no other (IL based) attributes didn't actually do anything. - Also fixed the annotation's handling of the same issue - presence of custom attributes needs to be determined via the CustomAttributeSource in any place where attributes which are recognized by the linker as special are handled. Added tests for all of the changes above * PR Feedback and test fix Commit migrated from dotnet/linker@f42b2d7
MarkStep go over all assemblies (Regardless if they're being linked or just copied) and marks everything as usual. But in the end it will not "trim" anything from the copy assembly. So we must make sure that everything the assembly needs is marked.
Attribute removal needs to comply with this behavior as well.
This change fixes several other issues around link attribute XML files:
Added tests for all of the changes above
Fixes #1341.