-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
@@ -192,6 +203,15 @@ void PatchResources() | |||
} | |||
} | |||
|
|||
void SortCustomAttributes() |
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.
can you please add a comment about why we need to sort the custom attributes here?
/backport to release/7.0-staging |
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); |
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.
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);
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.
This fixed the issue I was running into on #88167
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.
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.
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.
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.