-
-
Notifications
You must be signed in to change notification settings - Fork 639
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
FieldRVA alignment #817
FieldRVA alignment #817
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1613,8 +1613,21 @@ void AddField (FieldDefinition field) | |
void AddFieldRVA (FieldDefinition field) | ||
{ | ||
var table = GetTable<FieldRVATable> (Table.FieldRVA); | ||
|
||
// To allow for safe implementation of metadata rewriters for code which uses CreateSpan<T> | ||
// if the Field RVA refers to a locally defined type with a pack > 1, align the InitialValue | ||
// to pack boundary. This logic is restricted to only being affected by metadata local to the module | ||
// as PackingSize is only used when examining a type local to the module being written. | ||
|
||
int align = 1; | ||
if (field.FieldType.IsDefinition && !field.FieldType.IsGenericInstance) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that the |
||
var type = field.FieldType.Resolve (); | ||
|
||
if ((type.Module == module) && (type.PackingSize > 1)) | ||
align = type.PackingSize; | ||
} | ||
table.AddRow (new FieldRVARow ( | ||
data.AddData (field.InitialValue), | ||
data.AddData (field.InitialValue, align), | ||
field.token.RID)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.assembly extern mscorlib | ||
{ | ||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. | ||
.ver 4:0:0:0 | ||
} | ||
.assembly FieldRVAAlignment {} | ||
|
||
.module FieldRVAAlignment.dll | ||
|
||
.class private auto ansi '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}' | ||
extends [mscorlib]System.Object | ||
{ | ||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) | ||
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=3' | ||
extends [mscorlib]System.ValueType | ||
{ | ||
.pack 1 | ||
.size 3 | ||
} // end of class '__StaticArrayInitTypeSize=3' | ||
|
||
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=16' | ||
extends [mscorlib]System.ValueType | ||
{ | ||
.pack 8 | ||
.size 16 | ||
} // end of class '__StaticArrayInitTypeSize=16' | ||
|
||
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=20' | ||
extends [mscorlib]System.ValueType | ||
{ | ||
.pack 4 | ||
.size 20 | ||
} // end of class '__StaticArrayInitTypeSize=20' | ||
|
||
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=5' | ||
extends [mscorlib]System.ValueType | ||
{ | ||
.pack 1 | ||
.size 5 | ||
} // end of class '__StaticArrayInitTypeSize=5' | ||
|
||
.class explicit ansi sealed nested private '__StaticArrayInitTypeSize=6' | ||
extends [mscorlib]System.ValueType | ||
{ | ||
.pack 2 | ||
.size 6 | ||
} // end of class '__StaticArrayInitTypeSize=6' | ||
|
||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=3' '$$method0x6000001-1' at I_000020F0 | ||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=20' '$$method0x6000001-2' at I_000020F8 | ||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=5' '$$method0x6000001-3' at I_00002108 | ||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=20' '$$method0x6000001-4' at I_00002110 | ||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=6' '$$method0x6000001-5' at I_00002120 | ||
.field static assembly valuetype '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}'/'__StaticArrayInitTypeSize=16' '$$method0x6000001-6' at I_00002130 | ||
} // end of class '<PrivateImplementationDetails>{9B33BB20-87EF-4094-9948-34882DB2F001}' | ||
|
||
|
||
// ============================================================= | ||
|
||
.data cil I_000020F0 = bytearray ( | ||
01 02 03) | ||
.data cil I_000020F8 = bytearray ( | ||
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00) | ||
.data cil I_00002108 = bytearray ( | ||
04 05 06 07 08) | ||
.data cil I_00002110 = bytearray ( | ||
01 00 00 00 02 00 00 00 03 00 00 00 05 00 00 00 06 00 00 00) | ||
.data cil I_00002120 = bytearray ( | ||
08 00 0C 00 0D 00) | ||
.data cil I_00002130 = bytearray ( | ||
01 00 00 00 02 00 00 00 03 00 00 00 05 00 00 00) |
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.
Might be worthwhile to unpack this logic in a comment.