Skip empty sections when calculating a R2R PE file layout #122820
Merged
+14
−2
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