From 035e4fa8f8cd4a53bbc8a3cb50cda6d956b14f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 5 Jul 2023 21:01:21 +0200 Subject: [PATCH] [mono] Fix sorting custom attributes in ILStrip The change in https://github.com/dotnet/runtime/pull/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. --- .../ILStrip/AssemblyStripper/AssemblyStripper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs index 8ec3790784b621..c61cf219f7165a 100644 --- a/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs +++ b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs @@ -18,7 +18,9 @@ public int Compare(object left, object right) { CustomAttributeRow row_left = (CustomAttributeRow)left; CustomAttributeRow row_right = (CustomAttributeRow)right; - return row_left.Parent.RID.CompareTo(row_right.Parent.RID); + var leftParentCodedIdx = Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, row_left.Parent); + var rightParentCodedIdx = Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, row_right.Parent); + return leftParentCodedIdx.CompareTo(rightParentCodedIdx); } }