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

Attribute removal should not kick in for assemblies which are not linked #1344

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

vitek-karas
Copy link
Member

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

Fixes #1341.

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
@@ -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))
Copy link
Contributor

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

@@ -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))
Copy link
Contributor

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

Copy link
Member Author

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.

@eerhardt
Copy link
Member

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.

@marek-safar marek-safar merged commit f42b2d7 into dotnet:master Jul 10, 2020
@sbomer sbomer mentioned this pull request Jul 20, 2020
@vitek-karas vitek-karas deleted the CopyAssemblyAttributeRemoval branch March 13, 2021 22:12
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing attributes breaks when an assembly is set to "copy"
3 participants