Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix issues where the module index GUID table isn't properly computed …
…- Since there are two possible places where the module indices must be up to date, ensure that they are finalized before either Node writes its data - Ensure that module indices are precomputed when needed from inlinee data
  • Loading branch information
davidwrighton authored and github-actions committed Sep 20, 2021
commit 22729694874a388b95a699baededfa7f751e6ba6
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private void PublishCode()
_methodCodeNode.InitializeDebugLocInfos(_debugLocInfos);
_methodCodeNode.InitializeDebugVarInfos(_debugVarInfos, _compilation.TypeSystemContext.Target);
#if READYTORUN
_methodCodeNode.InitializeInliningInfo(_inlinedMethods.ToArray());
_methodCodeNode.InitializeInliningInfo(_inlinedMethods.ToArray(), _compilation.NodeFactory);

// Detect cases where the instruction set support used is a superset of the baseline instruction set specification
var baselineSupport = _compilation.InstructionSetSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
Expand Down Expand Up @@ -63,6 +64,11 @@ public class ManifestMetadataTableNode : HeaderTableNode
/// </summary>
private int _nextModuleId;

/// <summary>
/// Modules which need to exist in set of modules visible
/// </summary>
private ConcurrentBag<EcmaModule> _modulesWhichMustBeIndexable = new ConcurrentBag<EcmaModule>();

/// <summary>
/// Set to true after GetData has been called. After that, ModuleToIndex may be called no more.
/// </summary>
Expand Down Expand Up @@ -136,6 +142,19 @@ public int ModuleToIndex(EcmaModule module)
return ModuleToIndexInternal(module);
}

public void EnsureModuleIndexable(ModuleDesc module)
{
if (_emissionCompleted)
{
throw new InvalidOperationException("Adding a new assembly after signatures have been materialized.");
}

if (module is EcmaModule ecmaModule && _nodeFactory.CompilationModuleGroup.VersionsWithModule(ecmaModule))
{
_modulesWhichMustBeIndexable.Add(ecmaModule);
}
}

private int ModuleToIndexInternal(EcmaModule module)
{
AssemblyName assemblyName = module.Assembly.GetName();
Expand Down Expand Up @@ -170,22 +189,34 @@ public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilde
sb.Append("ManifestMetadataTableNode");
}

public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
private void ComputeLastSetOfModuleIndices()
{
if (relocsOnly)
{
return new ObjectData(Array.Empty<byte>(), null, 1, null);
}

if (!_emissionCompleted)
{
foreach (ISignatureEmitter emitter in _signatureEmitters)
{
emitter.MaterializeSignature();
}

EcmaModule [] moduleArray = _modulesWhichMustBeIndexable.ToArray();
Array.Sort(moduleArray, (EcmaModule moduleA, EcmaModule moduleB) => moduleA.CompareTo(moduleB));
foreach (var module in moduleArray)
{
ModuleToIndex(module);
}

_emissionCompleted = true;
}
}

public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
{
if (relocsOnly)
{
return new ObjectData(Array.Empty<byte>(), null, 1, null);
}

ComputeLastSetOfModuleIndices();

MetadataBuilder metadataBuilder = new MetadataBuilder();

Expand Down Expand Up @@ -277,6 +308,8 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)

internal byte[] GetManifestAssemblyMvidTableData()
{
ComputeLastSetOfModuleIndices();

byte[] manifestAssemblyMvidTable = new byte[ManifestAssemblyMvidTableSize];
for (int i = 0; i < _manifestAssemblyMvids.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Internal.JitInterface;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler.DependencyAnalysis.ReadyToRun
{
Expand Down Expand Up @@ -45,6 +46,34 @@ protected override void OnMarked(NodeFactory context)
InitializeFrameInfos(Array.Empty<FrameInfo>());
}
_lateTriggeredCompilation = context.CompilationCurrentPhase != 0;
RegisterInlineeModuleIndices(context);
}

private void RegisterInlineeModuleIndices(NodeFactory factory)
{
if (_inlinedMethods != null)
{
foreach (var inlinee in _inlinedMethods)
{
MethodDesc inlineeDefinition = inlinee.GetTypicalMethodDefinition();
if (!(inlineeDefinition is EcmaMethod ecmaInlineeDefinition))
{
// We don't record non-ECMA methods because they don't have tokens that
// diagnostic tools could reason about anyway.
continue;
}

if (!factory.CompilationModuleGroup.VersionsWithMethodBody(inlinee))
{
// We cannot record inlining info across version bubble as cross-bubble assemblies
// are not guaranteed to preserve token values. Only non-versionable methods may be
// inlined across the version bubble.
Debug.Assert(inlinee.IsNonVersionable());
continue;
}
factory.ManifestMetadataTable.EnsureModuleIndexable(ecmaInlineeDefinition.Module);
}
}
}

public override int DependencyPhaseForDeferredStaticComputation => _lateTriggeredCompilation ? 2 : 0;
Expand Down Expand Up @@ -316,10 +345,12 @@ public override int CompareToImpl(ISortableNode other, CompilerComparer comparer
return comparer.Compare(_method, otherNode._method);
}

public void InitializeInliningInfo(MethodDesc[] inlinedMethods)
public void InitializeInliningInfo(MethodDesc[] inlinedMethods, NodeFactory factory)
{
Debug.Assert(_inlinedMethods == null);
_inlinedMethods = inlinedMethods;
if (this.Marked)
RegisterInlineeModuleIndices(factory);
}

public int Offset => 0;
Expand Down