-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix singlefile on OSX ARM64 #68845
Fix singlefile on OSX ARM64 #68845
Changes from all commits
0d928ae
14aae0c
1426d16
b8e8cae
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 |
---|---|---|
|
@@ -599,12 +599,19 @@ protected override BlobBuilder SerializeSection(string name, SectionLocation loc | |
|
||
if (!_target.IsWindows) | ||
{ | ||
const int RVAAlign = 1 << RVABitsToMatchFilePos; | ||
if (outputSectionIndex > 0) | ||
{ | ||
sectionStartRva = Math.Max(sectionStartRva, _sectionRVAs[outputSectionIndex - 1] + _sectionRawSizes[outputSectionIndex - 1]); | ||
|
||
// when assembly is stored in a singlefile bundle, an additional skew is introduced | ||
// as the streams inside the bundle are not necessarily page aligned as we do not | ||
// know the actual page size on the target system. | ||
// We may need one page gap of unused VA space before the next section starts. | ||
// We will assume the page size is <= RVAAlign | ||
sectionStartRva += RVAAlign; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand the layout mechanism more now. The way we construct On ARM64 the file from a bundle will start at an offset that is 4K aligned. On systems with 4K page size (i.e. default Ubuntu) such aligned offset will be as good as starting form 0. Thus we do not see asserts on Linux. On OSX ARM64 the page size is 16K, so we may need to "spill" a section past the end of the target VA region and that may cause VA regions to overlap, which trigger a failure in the loader and an assert. I think we can assume that 64K is enough to cover any reasonable page size and leaving 64K unused VA gap between sections will ensure that we will not overlap. |
||
} | ||
|
||
const int RVAAlign = 1 << RVABitsToMatchFilePos; | ||
sectionStartRva = AlignmentHelper.AlignUp(sectionStartRva, RVAAlign); | ||
|
||
int rvaAdjust = (location.PointerToRawData - sectionStartRva) & (RVAAlign - 1); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,17 +57,17 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer | |
throw new ArgumentException($"Invalid input: Unsupported Target Framework Version {targetFrameworkVersion}"); | ||
} | ||
|
||
if (IsLinux && Arch == Architecture.Arm64) | ||
if (IsWindows) | ||
{ | ||
// We align assemblies in the bundle at 4K so that we can use mmap on Linux without changing the page alignment of ARM64 R2R code. | ||
// We align assemblies in the bundle at 4K - per requirements of memory mapping API (MapViewOfFile3, et al). | ||
// This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity. | ||
// See https://github.com/dotnet/runtime/issues/41832. | ||
AssemblyAlignment = 4096; | ||
} | ||
else if (IsWindows) | ||
else if (Arch == Architecture.Arm64) | ||
{ | ||
// We align assemblies in the bundle at 4K - per requirements of memory mapping API (MapViewOfFile3, et al). | ||
// We align assemblies in the bundle at 4K so that we can use mmap on Unix without changing the page alignment of ARM64 R2R code. | ||
// This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity. | ||
// See https://github.com/dotnet/runtime/issues/41832. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once you get past the assert, you may still see crashes. I think they were because of this. We align files in the bundle on 4K for Linux ARM64, to make sure that I think the same applies to OSX as well as it is specific to instruction set. The fix could be older than Apple Silicon and therefore covered Linux only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that on osx-arm64 or unusually configured linux-arm64 systems, it is not 4K page aligned but something like 16K? In which case, can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in a compile-time tool. It cold be a completely different platform/os. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this is because of |
||
AssemblyAlignment = 4096; | ||
} | ||
else | ||
|
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.
The does not change how we map. I just renamed
prevSectionEnd
and made it always aligned. I think it is more readable.