Skip to content

[release/7.0] [NativeAOT] Ensure that frozen objects respect the minimum object size #76050

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

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public override ObjectNodeSection Section
}
}

public int MinimumObjectSize => _type.Context.Target.PointerSize * 3;
public int MinimumObjectSize => GetMinimumObjectSize(_type.Context);

public static int GetMinimumObjectSize(TypeSystemContext typeSystemContext)
=> typeSystemContext.Target.PointerSize * 3;

protected virtual bool EmitVirtualSlotsAndInterfaces => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ int ISymbolDefinitionNode.Offset

public override void EncodeData(ref ObjectDataBuilder dataBuilder, NodeFactory factory, bool relocsOnly)
{
int initialOffset = dataBuilder.CountBytes;

// Sync Block
dataBuilder.EmitZeroPointer();

// byte contents
_data.WriteContent(ref dataBuilder, this, factory);

int objectSize = dataBuilder.CountBytes - initialOffset;
int minimumObjectSize = EETypeNode.GetMinimumObjectSize(factory.TypeSystemContext);
if (objectSize < minimumObjectSize)
{
dataBuilder.EmitZeros(minimumObjectSize - objectSize);
}
}

protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private static IEETypeNode GetEETypeNode(NodeFactory factory)

public override void EncodeData(ref ObjectDataBuilder dataBuilder, NodeFactory factory, bool relocsOnly)
{
int initialOffset = dataBuilder.CountBytes;

dataBuilder.EmitZeroPointer(); // Sync block

dataBuilder.EmitPointerReloc(GetEETypeNode(factory));
Expand All @@ -73,6 +75,12 @@ public override void EncodeData(ref ObjectDataBuilder dataBuilder, NodeFactory f
// Null-terminate for friendliness with interop
dataBuilder.EmitShort(0);

int objectSize = dataBuilder.CountBytes - initialOffset;
int minimumObjectSize = EETypeNode.GetMinimumObjectSize(factory.TypeSystemContext);
if (objectSize < minimumObjectSize)
{
dataBuilder.EmitZeros(minimumObjectSize - objectSize);
}
}

protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
Expand Down