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

[mono] ILStrip sorts custom attribute table #87923

Merged
merged 4 commits into from
Jun 22, 2023

Conversation

jandupej
Copy link
Member

This prevents custom attribute table corruption by sorting it as the last step when stripping an assembly. Addresses #85414.

The PR will have to be backported to net7.0.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 22, 2023
@ghost ghost assigned jandupej Jun 22, 2023
@jandupej jandupej added area-Build-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 22, 2023
@jandupej jandupej added this to the 8.0.0 milestone Jun 22, 2023
@@ -192,6 +203,15 @@ void PatchResources()
}
}

void SortCustomAttributes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a comment about why we need to sort the custom attributes here?

@steveisok
Copy link
Member

/backport to release/7.0-staging

@github-actions
Copy link
Contributor

Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/5349160200

{
CustomAttributeRow row_left = (CustomAttributeRow)left;
CustomAttributeRow row_right = (CustomAttributeRow)right;
return row_left.Parent.RID.CompareTo(row_right.Parent.RID);
Copy link
Member

@lambdageek lambdageek Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is subtly wrong. the problem is that RID on a cecil metadata token masks out the token type.

We actually have to reconstruct the custom attribute coded-index.
something like:

   var leftParentCodedIdx = Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, row_left.Parent);
   var rightParentCodedIdx = Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, row_right.Parent);
   return leftParentCodedIdx.CompareTo(rightParentCodedIdx);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the issue I was running into on #88167

akoeplinger added a commit to akoeplinger/runtime that referenced this pull request Jul 5, 2023
The change in dotnet#87923 was subtly wrong, the problem is that RID on a Cecil metadata token masks out the token type.
We actually have to reconstruct the custom attribute coded-index.
github-actions bot pushed a commit that referenced this pull request Jul 5, 2023
The change in #87923 was subtly wrong, the problem is that RID on a Cecil metadata token masks out the token type.
We actually have to reconstruct the custom attribute coded-index.
lewing pushed a commit that referenced this pull request Jul 5, 2023
The change in #87923 was subtly wrong, the problem is that RID on a Cecil metadata token masks out the token type.
We actually have to reconstruct the custom attribute coded-index.
@ghost ghost locked as resolved and limited conversation to collaborators Aug 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants