Skip to content

Commit

Permalink
Remove alignment restriction for FieldRVA in Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Aug 6, 2023
1 parent 2c2aea0 commit 1727923
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/DotNet/Writer/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2706,11 +2706,8 @@ protected void AddFieldRVA(FieldDef field) {
uint rid = GetRid(field);

uint alignment = ModuleWriterBase.DEFAULT_CONSTANTS_ALIGNMENT;
const uint MaxFieldInitialValueAlignment = 1024U;
if (field.FieldType is TypeDefOrRefSig tdrSig && tdrSig.TypeDef?.ClassLayout is {} classLayout) {
uint requiredAlignment = Math.Min(Utils.RoundToNextPowerOfTwo(classLayout.PackingSize), MaxFieldInitialValueAlignment);
alignment = Math.Max(alignment, requiredAlignment);
}
if (field.FieldType is TypeDefOrRefSig tdrSig && tdrSig.TypeDef?.ClassLayout is {} classLayout)
alignment = Math.Max(alignment, Utils.RoundToNextPowerOfTwo(classLayout.PackingSize));

var iv = constants.Add(new ByteArrayChunk(ivBytes, alignment), alignment);
fieldToInitialValue[field] = iv;
Expand Down

0 comments on commit 1727923

Please sign in to comment.