Skip empty sections when calculating a R2R PE file layout#122820
Merged
jkoritzinsky merged 2 commits intomainfrom Jan 5, 2026
Merged
Skip empty sections when calculating a R2R PE file layout#122820jkoritzinsky merged 2 commits intomainfrom
jkoritzinsky merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
LayoutSectionsto 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
_outputSectionLayoutfor empty sections
jkoritzinsky
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
LayoutSectionsmethod, thevirtualAddresscounter was incremented to include a 64 kB padding for all sections, including the empty onessizeOfImageto include unnecessary 64 kB padding for each empty section on non-Windows platforms.Solution
LayoutSectionsto 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.dllOriginal assembly size: 16 kB
After compiling to Composite R2R on Linux & Mac:
System.Web.dllR2R Image Size