diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/GCRefMapNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/GCRefMapNode.cs index 7cab71737766d9..476049f45ca652 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/GCRefMapNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/GCRefMapNode.cs @@ -34,6 +34,8 @@ public GCRefMapNode(ImportSectionNode importSection) public int Offset => 0; + public bool IsEmpty => _methods.Count == 0; + public void AddImport(Import import) { lock (_methods) @@ -53,9 +55,9 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) if (_methods.Count == 0 || relocsOnly) { return new ObjectData( - data: Array.Empty(), - relocs: Array.Empty(), - alignment: 1, + data: Array.Empty(), + relocs: Array.Empty(), + alignment: 1, definedSymbols: new ISymbolDefinitionNode[] { this }); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ImportSectionNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ImportSectionNode.cs index e2356ea2816f84..6fb78cf67757f3 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ImportSectionNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ImportSectionNode.cs @@ -41,7 +41,6 @@ protected override int GetAlignmentRequirement(NodeFactory factory) private readonly byte _entrySize; private readonly string _name; private readonly bool _emitPrecode; - private readonly bool _emitGCRefMap; private bool _materializedSignature; @@ -52,12 +51,11 @@ public ImportSectionNode(string name, ReadyToRunImportSectionType importType, Re _flags = flags; _entrySize = entrySize; _emitPrecode = emitPrecode; - _emitGCRefMap = emitGCRefMap; _imports = new ImportTable(_name + "_ImportBegin", entrySize); _signatures = new ArrayOfEmbeddedPointersNode(_name + "_SigBegin", new EmbeddedObjectNodeComparer(CompilerComparer.Instance)); _signatureList = new List(); - _gcRefMap = _emitGCRefMap ? new GCRefMapNode(this) : null; + _gcRefMap = emitGCRefMap ? new GCRefMapNode(this) : null; } public void MaterializeSignature(NodeFactory r2rFactory) @@ -89,10 +87,7 @@ public void AddImport(NodeFactory factory, Import import) _signatureList.Add(import.ImportSignature.Target); } - if (_emitGCRefMap) - { - _gcRefMap.AddImport(import); - } + _gcRefMap?.AddImport(import); } public string Name => _name; @@ -135,8 +130,10 @@ public override void EncodeData(ref ObjectDataBuilder dataBuilder, NodeFactory f dataBuilder.EmitUInt(0); } - if (_emitGCRefMap) + // If we emit an Rva for an empty gcrefmap, it will have no size header and be impossible for r2rdump to read correctly + if (_gcRefMap?.IsEmpty == false) { + // This indirectly generates the AuxiliaryDataRva by emitting a placeholder 0 which will be replaced later dataBuilder.EmitReloc(_gcRefMap, RelocType.IMAGE_REL_BASED_ADDR32NB, 0); } else @@ -149,7 +146,7 @@ public override IEnumerable GetStaticDependencies(NodeFacto { yield return new DependencyListEntry(_imports, "Import section fixup data"); yield return new DependencyListEntry(_signatures, "Import section signatures"); - if (_emitGCRefMap) + if (_gcRefMap != null) { yield return new DependencyListEntry(_gcRefMap, "GC ref map"); } diff --git a/src/tests/Common/CLRTest.CrossGen.targets b/src/tests/Common/CLRTest.CrossGen.targets index 9f27f49c925194..2742228b6a598f 100644 --- a/src/tests/Common/CLRTest.CrossGen.targets +++ b/src/tests/Common/CLRTest.CrossGen.targets @@ -110,8 +110,7 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then done echo -o:"$__OutputFile" >> "$__ResponseFile" - ## Enable once #114504 is fixed - ## echo -O >> "$__ResponseFile" + echo -O >> "$__ResponseFile" echo --targetarch:$(TargetArchitecture) >> "$__ResponseFile" echo --targetos:$(TargetOS) >> "$__ResponseFile" echo --verify-type-and-field-layout >> "$__ResponseFile"