-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix alignment padding and add test for saving managed resources #110915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f21da2f
d199ed7
c011569
f857e01
cb2efb3
e8cbf27
306bfb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||
| using System.Diagnostics; | ||||||||
| using System.Reflection.Internal; | ||||||||
| using System.Reflection.Metadata; | ||||||||
| using System.Reflection.Metadata.Ecma335; | ||||||||
|
|
||||||||
| namespace System.Reflection.PortableExecutable | ||||||||
| { | ||||||||
|
|
@@ -40,8 +41,8 @@ internal sealed class ManagedTextSection | |||||||
| public int MetadataSize { get; } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// The size of managed resource data stream. | ||||||||
| /// Aligned to <see cref="ManagedResourcesDataAlignment"/>. | ||||||||
| /// The size of managed resource data stream (unaligned). | ||||||||
|
||||||||
| result = BitArithmetic.Align(result, MappedFieldDataAlignment); |
Line 131 in 1ce82e7
| result = BitArithmetic.Align(result, Is32Bit ? 4 : 8); //optional padding to make startup stub's target address align on word or double word boundary |
Line 185 in 07e4c1b
| return OffsetToILStream + BitArithmetic.Align(ILStreamSize, 4); |
If we don't align it for the user, the user would need an extra LOC to do the alignment for the somewhat common case of using resources, and that extra LOC that would be needed is not obvious to the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if they do the emitted assembly would be bad anyways.
I don't believe the lack of alignment breaks anything, unless there is some platform-specific alignment limitations that I'm not aware of -- e.g. the test added here worked before the alignment was added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. If the alignment is not needed then why are we adding it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was an Assert that was failing so we either need to remove it or add the alignment \ padding. Since there was a ManagedResourcesDataAlignment public const I decided to use that (it wasn't used before). Finally, the assert was checking if alignment to 4 while the public const is 8.
I do not know why the const was added, or why the alignment and checks are there in part. Git history shows this existed 8+ years ago as part of large commits. Likely the alignment was added for efficiency when reading the subsequent data. The code may have assumed the caller would align the data, but if so then the code should have thrown and not just asserted.
Uh oh!
There was an error while loading. Please reload this page.