Skip to content
Draft
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 @@ -87,6 +87,8 @@ protected override ModuleData CreateValueFromKey(string key)

private readonly SharedGenericsMode _genericsMode;

internal SharedGenericsMode SharedGenericsMode => _genericsMode;

public IReadOnlyDictionary<string, string> InputFilePaths
{
get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ protected sealed record SectionDefinition(CoffSectionHeader Header, Stream Strea
private static readonly ObjectNodeSection DebugTypesSection = new ObjectNodeSection(".debug$T", SectionType.ReadOnly);
private static readonly ObjectNodeSection DebugSymbolSection = new ObjectNodeSection(".debug$S", SectionType.ReadOnly);

public CoffObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder = null)
: base(factory, options, outputInfoBuilder)
public CoffObjectWriter(
NodeFactory factory,
ObjectWritingOptions options,
OutputInfoBuilder outputInfoBuilder = null,
Action<object, int, long, object, bool> recordIncrementalNode = null,
Action<Func<int, long, int, long?>> completeIncrementalLayout = null)
: base(
factory,
options,
outputInfoBuilder,
recordIncrementalNode,
completeIncrementalLayout)
{
_machine = factory.Target.Architecture switch
{
Expand Down Expand Up @@ -481,6 +491,32 @@ private protected override void EmitObjectFile(Stream outputFileStream)
stringTable.Write(outputFileStream);
}

private protected override bool TryGetObjectFileRange(
int sectionIndex,
long sectionOffset,
int size,
out long fileOffset)
{
fileOffset = 0;
if ((uint)sectionIndex >= (uint)_sections.Count ||
sectionOffset < 0 ||
size < 0)
{
return false;
}

CoffSectionHeader header = _sections[sectionIndex].Header;
if (header.PointerToRawData == 0 ||
sectionOffset > header.SizeOfRawData ||
size > header.SizeOfRawData - sectionOffset)
{
return false;
}

fileOffset = checked(header.PointerToRawData + sectionOffset);
return true;
}

protected struct CoffHeader
{
public Machine Machine { get; set; }
Expand Down
37 changes: 35 additions & 2 deletions src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private protected sealed record ChecksumsToCalculate(int SectionIndex, long Offs
private protected readonly NodeFactory _nodeFactory;
private protected readonly ObjectWritingOptions _options;
private protected readonly OutputInfoBuilder _outputInfoBuilder;
private readonly Action<object, int, long, object, bool> _recordIncrementalNode;
private readonly Action<Func<int, long, int, long?>> _completeIncrementalLayout;
private readonly bool _isSingleFileCompilation;
protected readonly Utf8StringBuilder _utf8StringBuilder = new();

Expand All @@ -48,11 +50,18 @@ private protected sealed record ChecksumsToCalculate(int SectionIndex, long Offs
// Symbol table
private readonly Dictionary<Utf8String, SymbolDefinition> _definedSymbols = new();

private protected ObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder = null)
private protected ObjectWriter(
NodeFactory factory,
ObjectWritingOptions options,
OutputInfoBuilder outputInfoBuilder = null,
Action<object, int, long, object, bool> recordIncrementalNode = null,
Action<Func<int, long, int, long?>> completeIncrementalLayout = null)
{
_nodeFactory = factory;
_options = options;
_outputInfoBuilder = outputInfoBuilder;
_recordIncrementalNode = recordIncrementalNode;
_completeIncrementalLayout = completeIncrementalLayout;
_isSingleFileCompilation = _nodeFactory.CompilationModuleGroup.IsSingleFileCompilation;

// Padding byte for code sections (NOP for x86/x64)
Expand Down Expand Up @@ -81,6 +90,16 @@ private protected ObjectWriter(NodeFactory factory, ObjectWritingOptions options
/// </remarks>
private protected virtual ObjectNodeSection GetEmitSection(ObjectNodeSection section) => section;

private protected virtual bool TryGetObjectFileRange(
int sectionIndex,
long sectionOffset,
int size,
out long fileOffset)
{
fileOffset = 0;
return false;
}

private protected SectionWriter GetOrCreateSection(ObjectNodeSection section)
=> GetOrCreateSection(section, default, default);

Expand Down Expand Up @@ -399,7 +418,8 @@ public virtual void EmitObject(Stream outputFileStream, IReadOnlyCollection<Depe
}

ObjectNodeSection section = node.GetSection(_nodeFactory);
SectionWriter sectionWriter = ShouldShareSymbol(node, section) ?
bool isComdat = ShouldShareSymbol(node, section);
SectionWriter sectionWriter = isComdat ?
GetOrCreateSection(section, currentSymbolName, currentSymbolName) :
GetOrCreateSection(section);

Expand All @@ -408,6 +428,13 @@ public virtual void EmitObject(Stream outputFileStream, IReadOnlyCollection<Depe
sectionWriter.EmitAlignment(nodeContents.Alignment);
}

_recordIncrementalNode?.Invoke(
node,
sectionWriter.SectionIndex,
sectionWriter.Position,
nodeContents,
isComdat);

bool isMethod = node is IPCodeSymbolNode;
long thumbBit = _nodeFactory.Target.Architecture == TargetArchitecture.ARM && isMethod ? 1 : 0;

Expand Down Expand Up @@ -615,6 +642,12 @@ public virtual void EmitObject(Stream outputFileStream, IReadOnlyCollection<Depe
_outputInfoBuilder.AddSection(outputSection);
}
}

_completeIncrementalLayout?.Invoke(
(int sectionIndex, long sectionOffset, int size) =>
TryGetObjectFileRange(sectionIndex, sectionOffset, size, out long fileOffset) ?
fileOffset :
null);
}

private protected virtual void RecordMethodDeclaration(INodeWithTypeSignature node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ItemGroup>
<Compile Include="DependencyGraphTests.cs" />
<Compile Include="DevirtualizationTests.cs" />
<Compile Include="IncrementalCompilationTests.cs" />
<Compile Include="SwiftLoweringTests.cs" />
</ItemGroup>
</Project>
Loading
Loading