diff --git a/docs/design/coreclr/botr/readytorun-platform-native-envelope.md b/docs/design/coreclr/botr/readytorun-platform-native-envelope.md index 7f13348ec172a3..9bd1410420ff37 100644 --- a/docs/design/coreclr/botr/readytorun-platform-native-envelope.md +++ b/docs/design/coreclr/botr/readytorun-platform-native-envelope.md @@ -13,9 +13,11 @@ The tentative high-level design is outlined below. As we implement this support, ## crossgen2: producing Mach-O object files Mach‑O support will only be supported for composite ReadyToRun when the target OS is macOS. It will be opt-in via a new `crossgen2` flag: + - `--obj-format macho` `crossgen2` will: + - Produce a Mach-O object file as the composite R2R image with the `RTR_HEADER` export for the `READYTORUN_HEADER`. - Mark each input IL assembly as a component R2R assembly: `READYTORUN_FLAG_COMPONENT`. - Mark each input IL assembly with a new flag indicating that the associated composite image is in the platform-native format: `READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE` @@ -28,20 +30,14 @@ There's a few cases in the R2R format that are not natively represented in the M #### Sections -Sections folded into `__TEXT,__text` that is in other sections in the PE envelope: - -- CLR metadata: In the PE format, put in .cormeta, corresponds to the PE Header's "COR Header directory" -- Win32 Resources: In the PE format, put in .rsrc, corresponds to the PE Header's "Win32 Resources Header directory" -- Managed Unwind Info: In the Mach-O format, this section is expected to be in the Mach-O unwind format. The unwind info used by the runtime must be in the Windows unwind format. -- GC Info: Entries correspond to the unwind info. Data moved out of `__TEXT,__text`: - Precompiled managed code has been moved into `__TEXT,__managedcode`. `__TEXT,__text` gets special treatment by the linker and `__TEXT,__managedcode` matches NativeAOT. +- Read-only data such as jump tables, CLR metadata, Win32 Resources, managed unwind info, gc info, and the R2R headers are moved to `__TEXT,__const` Data that stays in the corresponding locations as the PE envelope: -- Read-only data such as jump tables and the R2R headers: `__TEXT,__const` - Read-write data, such as fixup tables: `__DATA,__data` - Import thunks: `__TEXT,__text` 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 65c3151dabd59b..b515c093ba5240 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 8b7f6036a9f111..54ff003ae967de 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) @@ -104,6 +99,26 @@ 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; + } + + // 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 @@ -342,6 +357,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) @@ -355,16 +383,19 @@ private protected override void EmitSymbolTable(IDictionary field.IsNull + ? (field = Utf8String.Concat(_nodeFactory.NameMangler.CompilationUnitPrefix.AsSpan(), "__ExportDirectory"u8)) + : field; + 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; @@ -586,8 +622,6 @@ private void EmitExportDirectory(SectionWriter sectionWriter) Utf8String namePointerTableSymbol = new Utf8String(GenerateSymbolNameForReloc("namePointerTable")); Utf8String ordinalPointerTableSymbol = new Utf8String(GenerateSymbolNameForReloc("ordinalPointerTable")); - Debug.Assert(sectionWriter.Position == 0); - // +0x00: reserved sectionWriter.WriteLittleEndian(0); // +0x04: time/date stamp @@ -702,7 +736,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 @@ -756,30 +790,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(); @@ -830,6 +851,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); @@ -889,7 +926,7 @@ private unsafe void ResolveRelocations(int sectionIndex, List> 12) & 0x1f_ffff; + long delta = ((long)symbolImageOffset - sourcePageRVA >> 12) & 0x1f_ffff; Relocation.WriteValue(reloc.Type, pData, delta); break; } @@ -907,7 +944,7 @@ private unsafe void ResolveRelocations(int sectionIndex, List 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;