diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNodeSection.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNodeSection.cs index a226d8f4af2e1f..edc11ea248cf43 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNodeSection.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNodeSection.cs @@ -32,7 +32,6 @@ public ObjectNodeSection(string name, SectionType type, string comdatName) public ObjectNodeSection(string name, SectionType type) : this(name, type, null) { } - public static readonly ObjectNodeSection XDataSection = new ObjectNodeSection("xdata", SectionType.ReadOnly); public static readonly ObjectNodeSection DataSection = new ObjectNodeSection("data", SectionType.Writeable); public static readonly ObjectNodeSection ReadOnlyDataSection = new ObjectNodeSection("rdata", SectionType.ReadOnly); public static readonly ObjectNodeSection FoldableReadOnlyDataSection = new ObjectNodeSection("rdata", SectionType.ReadOnly); @@ -51,10 +50,5 @@ public ObjectNodeSection(string name, SectionType type) : this(name, type, null) public static readonly ObjectNodeSection ModulesWindowsContentSection = new ObjectNodeSection(".modules$I", SectionType.ReadOnly); public static readonly ObjectNodeSection ModulesUnixContentSection = new ObjectNodeSection("__modules", SectionType.Writeable); - - public static readonly ObjectNodeSection DebugDirectorySection = new ObjectNodeSection("debug", SectionType.Debug); - public static readonly ObjectNodeSection CorMetaSection = new ObjectNodeSection("cormeta", SectionType.ReadOnly); - public static readonly ObjectNodeSection Win32ResourcesSection = new ObjectNodeSection("rsrc", SectionType.ReadOnly); - public static readonly ObjectNodeSection PDataSection = new ObjectNodeSection("pdata", SectionType.ReadOnly); } } diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs index 62297efb6973e0..aa1bf19be261c5 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs @@ -38,7 +38,7 @@ public virtual int CompareToImpl(ISortableNode other, CompilerComparer comparer) throw new NotImplementedException("Multiple nodes of this type are not supported"); } - protected enum ObjectNodePhase + protected internal enum ObjectNodePhase { /// /// Nodes should only be placed in this phase if they have strict output ordering requirements that @@ -49,7 +49,7 @@ protected enum ObjectNodePhase Late, } - protected enum ObjectNodeOrder + protected internal enum ObjectNodeOrder { // // The ordering of this sequence of nodes is deliberate and currently required for @@ -66,7 +66,9 @@ protected enum ObjectNodeOrder ImportSectionsTableNode, ImportSectionNode, MethodEntrypointTableNode, - + DebugDirectoryNode, + RuntimeFunctionsGCInfoNode, + RuntimeFunctionsTableNode, // // NativeAOT Nodes diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/CoffObjectWriter.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/CoffObjectWriter.cs index dda356a81abd5a..525a32bcf408b7 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/CoffObjectWriter.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/CoffObjectWriter.cs @@ -89,6 +89,8 @@ private protected override void CreateSection(ObjectNodeSection section, Utf8Str { SectionType.ReadOnly => SectionCharacteristics.MemRead | SectionCharacteristics.ContainsInitializedData, + SectionType.UnwindData => + SectionCharacteristics.MemRead | SectionCharacteristics.ContainsInitializedData, SectionType.Writeable => SectionCharacteristics.MemRead | SectionCharacteristics.MemWrite | SectionCharacteristics.ContainsInitializedData, @@ -102,7 +104,7 @@ private protected override void CreateSection(ObjectNodeSection section, Utf8Str } }; - if (section == DebugTypesSection || section == ObjectNodeSection.DebugDirectorySection) + if (section == DebugTypesSection) { sectionHeader.SectionCharacteristics = SectionCharacteristics.MemRead | SectionCharacteristics.ContainsInitializedData | diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs index 02046f9358fa97..1afd4adbabc39d 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs @@ -65,6 +65,18 @@ private protected ObjectWriter(NodeFactory factory, ObjectWritingOptions options protected internal abstract void UpdateSectionAlignment(int sectionIndex, int alignment); + /// + /// Get the section in the image where nodes in the passed in section should actually be emitted. + /// + /// A node's requested section. + /// The section to actually emit the node into. + /// + /// Sections in an image can be very expensive, and unlike linkable formats, + /// sections cannot be merged after the fact. + /// This method allows formats that want to merge sections during emit to do so. + /// + private protected virtual ObjectNodeSection GetEmitSection(ObjectNodeSection section) => section; + private protected SectionWriter GetOrCreateSection(ObjectNodeSection section) => GetOrCreateSection(section, default, default); @@ -87,6 +99,8 @@ private protected SectionWriter GetOrCreateSection(ObjectNodeSection section, Ut int sectionIndex; SectionData sectionData; + section = GetEmitSection(section); + if (!comdatName.IsNull || !_sectionNameToSectionIndex.TryGetValue(section.Name, out sectionIndex)) { sectionData = new SectionData(section.Type == SectionType.Executable ? _insPaddingByte : (byte)0); @@ -426,6 +440,11 @@ public virtual void EmitObject(Stream outputFileStream, IReadOnlyCollection> _resolvableRelocations = []; - private int _pdataSectionIndex = NoSectionIndex; - private int _debugSectionIndex = NoSectionIndex; - private int _exportSectionIndex = NoSectionIndex; private int _baseRelocSectionIndex = NoSectionIndex; - private int _corMetaSectionIndex = NoSectionIndex; - private int _rsrcSectionIndex = NoSectionIndex; // Base relocation (.reloc) bookkeeping private readonly SortedDictionary> _baseRelocMap = new(); private Dictionary _definedSymbols = []; private HashSet _exportedSymbolNames = new(); + private Dictionary _wellKnownSymbols = new(); private long _coffHeaderOffset; public PEObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder, string outputPath, int sectionAlignment, int? coffTimestamp) @@ -102,6 +97,33 @@ public void AddExportedSymbol(string symbol) } } + private protected override ObjectNodeSection GetEmitSection(ObjectNodeSection section) + { + // Put executable code into .text for PE files as AV software really + // doesn't like executable code in non-standard sections. + if (section == ObjectNodeSection.ManagedCodeWindowsContentSection) + { + return ObjectNodeSection.TextSection; + } + + // RISC-V has a limited addressing range (±2GB) for relocs. + // Don't merge rdata into text to avoid relocation overflow. + if (_nodeFactory.Target.Architecture == TargetArchitecture.RiscV64) + { + return section; + } + + // We want to reduce the number of sections in the PE files we emit, + // so merge the read-only data section into the .text section. + if (section == ObjectNodeSection.ReadOnlyDataSection) + { + return ObjectNodeSection.TextSection; + } + + // Otherwise, use the requested section. + return section; + } + private protected override void CreateSection(ObjectNodeSection section, Utf8String comdatName, Utf8String symbolName, int sectionIndex, Stream sectionStream) { // COMDAT sections are not supported in PE files @@ -340,6 +362,19 @@ private enum ImageDirectoryEntry Reserved = 15, } + private protected override void RecordWellKnownSymbol(Utf8String currentSymbolName, SortableDependencyNode.ObjectNodeOrder classCode) + { + if (classCode is SortableDependencyNode.ObjectNodeOrder.Win32ResourcesNode + or SortableDependencyNode.ObjectNodeOrder.CorHeaderNode + or SortableDependencyNode.ObjectNodeOrder.DebugDirectoryNode + or SortableDependencyNode.ObjectNodeOrder.RuntimeFunctionsTableNode) + { + // These nodes represent directories in the PE header. + // We need to know what symbol name they have so we know where they are located during emit. + _wellKnownSymbols.Add(classCode, currentSymbolName); + } + } + private protected override void EmitSymbolTable(IDictionary definedSymbols, SortedSet undefinedSymbols) { if (undefinedSymbols.Count > 0) @@ -353,16 +388,19 @@ private protected override void EmitSymbolTable(IDictionary $"{_nodeFactory.NameMangler.CompilationUnitPrefix}__ExportDirectory"; + private void LayoutSections(bool recordFinalLayout, out ushort numberOfSections, out uint sizeOfHeaders, out uint sizeOfImage, out uint sizeOfInitializedData, out uint sizeOfCode) { bool isPE32Plus = _nodeFactory.Target.PointerSize == 8; @@ -542,12 +582,6 @@ private protected override unsafe void EmitRelocations(int sectionIndex, List exports = [.._exportedSymbolNames]; exports.Sort(StringComparer.Ordinal); @@ -567,8 +601,6 @@ private void EmitExportDirectory(SectionWriter sectionWriter) string namePointerTableSymbol = GenerateSymbolNameForReloc("namePointerTable"); string ordinalPointerTableSymbol = GenerateSymbolNameForReloc("ordinalPointerTable"); - Debug.Assert(sectionWriter.Position == 0); - // +0x00: reserved sectionWriter.WriteLittleEndian(0); // +0x04: time/date stamp @@ -683,7 +715,7 @@ private protected override void EmitObjectFile(Stream outputFileStream) #if READYTORUN // On R2R, we encode the target OS into the machine bits to ensure we don't try running // linux or mac R2R code on Windows, or vice versa. - machine = (Machine) ((ushort)machine ^ (ushort)_nodeFactory.Target.MachineOSOverrideFromTarget()); + machine = (Machine)((ushort)machine ^ (ushort)_nodeFactory.Target.MachineOSOverrideFromTarget()); #endif // COFF File Header @@ -737,30 +769,17 @@ private protected override void EmitObjectFile(Stream outputFileStream) // before writing if needed. var dataDirs = new OptionalHeaderDataDirectories(); // Populate data directories if present. - if (_rsrcSectionIndex != NoSectionIndex) - { - dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.Resource, (uint)_outputSectionLayout[_rsrcSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_rsrcSectionIndex].Length); - } - if (_pdataSectionIndex != NoSectionIndex) - { - dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.Exception, (uint)_outputSectionLayout[_pdataSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_pdataSectionIndex].Length); - } - if (_exportSectionIndex != NoSectionIndex) - { - dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.Export, (uint)_outputSectionLayout[_exportSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_exportSectionIndex].Length); - } + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, ImageDirectoryEntry.Resource, SortableDependencyNode.ObjectNodeOrder.Win32ResourcesNode); + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, ImageDirectoryEntry.Debug, SortableDependencyNode.ObjectNodeOrder.DebugDirectoryNode); + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, ImageDirectoryEntry.CLRRuntimeHeader, SortableDependencyNode.ObjectNodeOrder.CorHeaderNode); + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, ImageDirectoryEntry.Exception, SortableDependencyNode.ObjectNodeOrder.RuntimeFunctionsTableNode); + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, ImageDirectoryEntry.Export, ExportDirectorySymbol); + if (_baseRelocSectionIndex != NoSectionIndex) { dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.BaseRelocation, (uint)_outputSectionLayout[_baseRelocSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_baseRelocSectionIndex].Length); } - if (_debugSectionIndex != NoSectionIndex) - { - dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.Debug, (uint)_outputSectionLayout[_debugSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_debugSectionIndex].Length); - } - if (_corMetaSectionIndex != NoSectionIndex) - { - dataDirs.SetIfNonEmpty((int)ImageDirectoryEntry.CLRRuntimeHeader, (uint)_outputSectionLayout[_corMetaSectionIndex].VirtualAddress, (uint)_outputSectionLayout[_corMetaSectionIndex].Length); - } + peOptional.Write(outputFileStream, dataDirs); CoffStringTable stringTable = new(); @@ -811,6 +830,22 @@ private protected override void EmitObjectFile(Stream outputFileStream) outputFileStream.SetLength(sizeOfImage); } + private void PopulateDataDirectoryForWellKnownSymbolIfPresent(OptionalHeaderDataDirectories dataDirs, ImageDirectoryEntry directory, SortableDependencyNode.ObjectNodeOrder wellKnownSymbol) + { + if (_wellKnownSymbols.TryGetValue(wellKnownSymbol, out Utf8String symbolName)) + { + PopulateDataDirectoryForWellKnownSymbolIfPresent(dataDirs, directory, symbolName); + } + } + + private void PopulateDataDirectoryForWellKnownSymbolIfPresent(OptionalHeaderDataDirectories dataDirs, ImageDirectoryEntry directory, Utf8String symbolName) + { + if (_definedSymbols.TryGetValue(symbolName, out SymbolDefinition symbol)) + { + dataDirs.SetIfNonEmpty((int)directory, checked((uint)(_outputSectionLayout[symbol.SectionIndex].VirtualAddress + (ulong)symbol.Value)), (uint)symbol.Size); + } + } + private protected override void EmitChecksumsForObject(Stream outputFileStream, List checksumRelocations, ReadOnlySpan originalOutput) { base.EmitChecksumsForObject(outputFileStream, checksumRelocations, originalOutput); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.Aot.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.Aot.cs index ebc36125afe188..8975efcde17728 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.Aot.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.Aot.cs @@ -56,12 +56,14 @@ internal partial class CoffObjectWriter : ObjectWriter private CodeViewTypesBuilder _debugTypesBuilder; // Exception handling + private static readonly ObjectNodeSection XDataSection = new ObjectNodeSection("xdata", SectionType.ReadOnly); + private static readonly ObjectNodeSection PDataSection = new ObjectNodeSection("pdata", SectionType.UnwindData); private SectionWriter _pdataSectionWriter; private protected override void CreateEhSections() { // Create .pdata - _pdataSectionWriter = GetOrCreateSection(ObjectNodeSection.PDataSection); + _pdataSectionWriter = GetOrCreateSection(PDataSection); } private protected override void EmitUnwindInfo( @@ -95,14 +97,14 @@ private protected override void EmitUnwindInfo( if (shareSymbol) { // Produce an associative COMDAT symbol. - xdataSectionWriter = GetOrCreateSection(ObjectNodeSection.XDataSection, currentSymbolName, unwindSymbolName); - pdataSectionWriter = GetOrCreateSection(ObjectNodeSection.PDataSection, currentSymbolName, default); + xdataSectionWriter = GetOrCreateSection(XDataSection, currentSymbolName, unwindSymbolName); + pdataSectionWriter = GetOrCreateSection(PDataSection, currentSymbolName, default); } else { // Produce a COMDAT section for each unwind symbol and let linker // do the deduplication across the ones with identical content. - xdataSectionWriter = GetOrCreateSection(ObjectNodeSection.XDataSection, unwindSymbolName, unwindSymbolName); + xdataSectionWriter = GetOrCreateSection(XDataSection, unwindSymbolName, unwindSymbolName); pdataSectionWriter = _pdataSectionWriter; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedCorHeaderNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedCorHeaderNode.cs index 5b4df6872e3ba9..233407d2208045 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedCorHeaderNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedCorHeaderNode.cs @@ -24,14 +24,7 @@ public CopiedCorHeaderNode(EcmaModule sourceModule) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedFieldRvaNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedFieldRvaNode.cs index 4accb7487377e4..cc1d3737ac16e1 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedFieldRvaNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedFieldRvaNode.cs @@ -26,14 +26,7 @@ public CopiedFieldRvaNode(EcmaModule module, int rva) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedManagedResourcesNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedManagedResourcesNode.cs index a0367e0dec2b36..e046ce8dc31966 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedManagedResourcesNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedManagedResourcesNode.cs @@ -20,14 +20,7 @@ public CopiedManagedResourcesNode(EcmaModule module) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMetadataBlobNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMetadataBlobNode.cs index e18fd800555f9d..b760eb4490ffaa 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMetadataBlobNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMetadataBlobNode.cs @@ -27,14 +27,7 @@ public CopiedMetadataBlobNode(EcmaModule sourceModule) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs index d35993fdf0441f..3054c704883a3d 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs @@ -24,14 +24,7 @@ public CopiedMethodILNode(EcmaMethod method) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedStrongNameSignatureNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedStrongNameSignatureNode.cs index 124a21ca1abe85..f3582103052621 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedStrongNameSignatureNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedStrongNameSignatureNode.cs @@ -23,14 +23,7 @@ public CopiedStrongNameSignatureNode(EcmaModule module) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put the CLR metadata into the correct section for the PE writer to - // hook up the CLR header entry in the PE header. - // Don't emit a separate section for other formats to reduce cost. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.CorMetaSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugDirectoryNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugDirectoryNode.cs index 7c304148cfee81..b1246973b0bd81 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugDirectoryNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugDirectoryNode.cs @@ -54,14 +54,14 @@ public DebugDirectoryNode(EcmaModule sourceModule, string outputFileName, bool s public override ObjectNodeSection GetSection(NodeFactory factory) { - return ObjectNodeSection.DebugDirectorySection; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false; protected internal override int Phase => (int)ObjectNodePhase.Ordered; - public override int ClassCode => 315358387; + public override int ClassCode => (int)ObjectNodeOrder.DebugDirectoryNode; public override bool StaticDependenciesAreComputed => true; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ManifestAssemblyMvidHeaderNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ManifestAssemblyMvidHeaderNode.cs index 20240ee78f3ee2..96ce435250cdcb 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ManifestAssemblyMvidHeaderNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ManifestAssemblyMvidHeaderNode.cs @@ -21,7 +21,7 @@ public ManifestAssemblyMvidHeaderNode(ManifestMetadataTableNode manifestNode) _manifestNode = manifestNode; } - public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.TextSection; + public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection; public override bool IsShareable => false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodColdCodeNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodColdCodeNode.cs index 80047a4c6b0789..4b75d00300cd0f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodColdCodeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodColdCodeNode.cs @@ -24,13 +24,9 @@ public MethodColdCodeNode(MethodDesc owningMethod) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put executable code into .text for PE files as AV software really - // doesn't like executable code in non-standard sections. - // - // For other formats, use the managed code section for managed code. return factory.Format switch { - ReadyToRunContainerFormat.PE => ObjectNodeSection.TextSection, + ReadyToRunContainerFormat.PE => ObjectNodeSection.ManagedCodeWindowsContentSection, _ => ObjectNodeSection.ManagedCodeUnixContentSection }; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs index 79e6076914004b..ee86a7943a67dc 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs @@ -303,13 +303,9 @@ protected override string GetName(NodeFactory factory) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Put executable code into .text for PE files as AV software really - // doesn't like executable code in non-standard sections. - // - // For other formats, use the managed code section for managed code. return factory.Format switch { - ReadyToRunContainerFormat.PE => ObjectNodeSection.TextSection, + ReadyToRunContainerFormat.PE => ObjectNodeSection.ManagedCodeWindowsContentSection, _ => ObjectNodeSection.ManagedCodeUnixContentSection }; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsGCInfoNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsGCInfoNode.cs index caec889983266e..aad3718edb6938 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsGCInfoNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsGCInfoNode.cs @@ -14,19 +14,13 @@ public RuntimeFunctionsGCInfoNode() public HashSet Deduplicator; - public override int ClassCode => 316678892; + protected internal override int Phase => (int)ObjectNodePhase.Ordered; + + public override int ClassCode => (int)ObjectNodeOrder.RuntimeFunctionsGCInfoNode; public override ObjectNodeSection GetSection(NodeFactory factory) { - // We may want to emit info into the XData section if we produce native - // unwind info for another format. Don't put this into the XData section - // unless we're producing PEs, where we will also emit the unwind info - // into the PData section. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.XDataSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool StaticDependenciesAreComputed => true; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsTableNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsTableNode.cs index 7f9cb32327fc88..bd2f062fc59be4 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsTableNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/RuntimeFunctionsTableNode.cs @@ -25,13 +25,7 @@ public RuntimeFunctionsTableNode(NodeFactory nodeFactory) public override ObjectNodeSection GetSection(NodeFactory factory) { - // This table is always in the Windows UnwindInfo format. - // As a result, we can't put it in the PData section for non-PE formats. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.PDataSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) @@ -174,7 +168,9 @@ public int TableSizeExcludingSentinel } } - public override int ClassCode => -855231428; + protected internal override int Phase => (int)ObjectNodePhase.Ordered; + + public override int ClassCode => (int)ObjectNodeOrder.RuntimeFunctionsTableNode; internal const int SentinelSizeAdjustment = -4; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Win32ResourcesNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Win32ResourcesNode.cs index 75b3ffc0fb2582..376cb4312979b8 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Win32ResourcesNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Win32ResourcesNode.cs @@ -21,14 +21,7 @@ public Win32ResourcesNode(ResourceData resourceData) public override ObjectNodeSection GetSection(NodeFactory factory) { - // Don't emit Win32 resources into a special section unless we're producing PEs. - // The PE writer knows how to hook up the lookup for these resources, but other - // formats don't need the cost of an additional section. - return factory.Format switch - { - ReadyToRunContainerFormat.PE => ObjectNodeSection.Win32ResourcesSection, - _ => ObjectNodeSection.ReadOnlyDataSection - }; + return ObjectNodeSection.ReadOnlyDataSection; } public override bool IsShareable => false;