Skip to content

Commit f858ecf

Browse files
Assert pointer relocs are aligned (#113069)
This is a prerequisite for disabling data dehydration on Windows by default. Straddling pointers are not a big deal with dehydration, but straddling a page boundary with a reloc on Windows is a (perf) problem.
1 parent 3f0d8d9 commit f858ecf

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ArrayOfFrozenObjectsNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected override ObjectData GetDehydratableData(NodeFactory factory, bool relo
3232
return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, Array.Empty<ISymbolDefinitionNode>());
3333

3434
var builder = new ObjectDataBuilder(factory, relocsOnly);
35+
builder.RequireInitialAlignment(factory.Target.PointerSize);
3536
builder.AddSymbol(this);
3637
foreach (FrozenObjectNode node in factory.MetadataManager.GetFrozenObjects())
3738
{

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,26 @@ private void EmitObject(string objectFilePath, IReadOnlyCollection<DependencyNod
437437
sectionWriter.Position,
438438
nodeContents.Data,
439439
nodeContents.Relocs));
440+
441+
#if DEBUG
442+
// Pointer relocs should be aligned at pointer boundaries within the image.
443+
// Processing misaligned relocs (especially relocs that straddle page boundaries) can be
444+
// expensive on Windows. But: we can't guarantee this on x86.
445+
if (_nodeFactory.Target.Architecture != TargetArchitecture.X86)
446+
{
447+
bool hasPointerRelocs = false;
448+
foreach (Relocation reloc in nodeContents.Relocs)
449+
{
450+
if ((reloc.RelocType is RelocType.IMAGE_REL_BASED_DIR64 && _nodeFactory.Target.PointerSize == 8) ||
451+
(reloc.RelocType is RelocType.IMAGE_REL_BASED_HIGHLOW && _nodeFactory.Target.PointerSize == 4))
452+
{
453+
hasPointerRelocs = true;
454+
Debug.Assert(reloc.Offset % _nodeFactory.Target.PointerSize == 0);
455+
}
456+
}
457+
Debug.Assert(!hasPointerRelocs || (nodeContents.Alignment % _nodeFactory.Target.PointerSize) == 0);
458+
}
459+
#endif
440460
}
441461

442462
// Emit unwinding frames and LSDA

0 commit comments

Comments
 (0)