Repository: dotnet/runtime
File: src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs (C#)

Code before:
        {
            _outputPath = outputPath;
            _requestedSectionAlignment = sectionAlignment;
            _coffTimestamp = coffTimestamp;
        }

        public void AddExportedSymbol(string symbol)
        {
            if (!string.IsNullOrEmpty(symbol))
            {
                _exportedSymbolNames.Add(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
            base.CreateSection(section, comdatName: default, symbolName, sectionIndex, sectionStream);

            if (_requestedSectionAlignment != 0)
            {
                UpdateSectionAlignment(sectionIndex, _requestedSectionAlignment);
            }
        }

Review comment (suggestion):
Nit: This is order-dependent. If the code is moved or reordered, it may change the emitting strategy. Consider adding explicit conditions.

Code after:
        public PEObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder, string outputPath, int sectionAlignment, int? coffTimestamp)
            : base(factory, options, outputInfoBuilder)
        {
            _outputPath = outputPath;
            _requestedSectionAlignment = sectionAlignment;
            _coffTimestamp = coffTimestamp;
        }

        public void AddExportedSymbol(string symbol)
        {
            if (!string.IsNullOrEmpty(symbol))
            {
                _exportedSymbolNames.Add(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
            base.CreateSection(section, comdatName: default, symbolName, sectionIndex, sectionStream);

            if (_requestedSectionAlignment != 0)
            {
                UpdateSectionAlignment(sectionIndex, _requestedSectionAlignment);
            }
        }

        private struct PEOptionalHeader
        {
            public bool IsPE32Plus { get; }