Skip to content

Conversation

@davidnguyen-tech
Copy link
Member

@davidnguyen-tech davidnguyen-tech commented Jan 2, 2026

This PR updates PEObjectWriter.

The changes are independent from #122511

Problem

R2R PE files were bloated with empty space between sections.

Cause

Although we didn't directly emit empty sections into the R2R PE file, we still allocated a 64 kB padding for each empty section on non-Windows platforms:

  • In the LayoutSections method, the virtualAddress counter was incremented to include a 64 kB padding for all sections, including the empty ones
  • This caused sizeOfImage to include unnecessary 64 kB padding for each empty section on non-Windows platforms.

Solution

  • Modified LayoutSections to skip VA allocation in PE file layout for empty sections - after this change, we don't add 64 kB padding before the empty sections anymore.

Results

Observed assembly: System.Web.dll

Original assembly size: 16 kB

After compiling to Composite R2R on Linux & Mac:

dotnet/runtime version System.Web.dll R2R Image Size
release/10.0 4 kB
main 918 kB
main with this PR applied 600 kB (~35% decrease)
#122511 branch 262 kB
#122511 branch with this PR applied 70 kB (~73% decrease)

Copilot AI review requested due to automatic review settings January 2, 2026 15:51
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 2, 2026
@davidnguyen-tech davidnguyen-tech added area-crossgen2-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes R2R PE file layout by skipping virtual address allocation for empty sections, reducing unnecessary file size bloat.

Key changes:

  • Modified LayoutSections to skip VA allocation and size calculations for empty sections
  • Empty sections now receive zero VA/size in the output layout instead of consuming 64 kB padding
  • Maintains section index correspondence by still adding entries to _outputSectionLayout for empty sections

@jkoritzinsky jkoritzinsky merged commit 5422d6d into main Jan 5, 2026
116 of 119 checks passed
@jkotas jkotas deleted the skip-empty-sections-in-pe-layout branch January 6, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants