Skip to content
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

Merged
merged 4 commits into from
May 4, 2022
Merged

Fix singlefile on OSX ARM64 #68845

merged 4 commits into from
May 4, 2022

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented May 4, 2022

Fixes: #67062 , #68654

@ghost
Copy link

ghost commented May 4, 2022

Tagging subscribers to this area: @agocke, @vitek-karas, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: VSadov
Assignees: VSadov
Labels:

area-Single-File

Milestone: -

@VSadov VSadov requested a review from trylek May 4, 2022 00:03
prevSectionEnd = (char*)loadedHeader + headerSize; // the first "section" for our purposes is the header
void* prevSectionEndAligned;
// the first "section" for our purposes is the header
prevSectionEndAligned = ALIGN_UP((char*)loadedHeader + headerSize, GetVirtualPageSize());
Copy link
Member Author

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.

// 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;
Copy link
Member Author

@VSadov VSadov May 4, 2022

Choose a reason for hiding this comment

The 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 sectionStartRva guarantees that sections will not overlap - that is if the file starts form offset 0.
That is not the case in a singlefile bundle. In the bundle everything has an additional file-wide offset when we map.

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.
Same could happen on unusually configured Linuxes with larger page sizes.

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.

// This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity.
// See https://github.com/dotnet/runtime/issues/41832.
Copy link
Member Author

@VSadov VSadov May 4, 2022

Choose a reason for hiding this comment

The 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 ADRP assembly instructions are stable without performing relocations.

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.

Copy link
Member

Choose a reason for hiding this comment

The 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 GetVirtualPageSize() instead of hardcoded 4K here?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.
We do not want arbitrary big alignment too, since it will increase the total size of the single file app.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also this is because of ADRP instruction, which operates with 4k offsets regardless of OS page.

@VSadov
Copy link
Member Author

VSadov commented May 4, 2022

It would be nice to run Installer OSX ARM64 tests with this, but I think they are disabled in CI and broken.

When I tried running Installer tests locally they failed before even running - the restore scripts failed.
Something about targeting 3.1 and OSX ARM64, which is not a valid combination, etc...

Hosting01/runtime/.dotnet/sdk/6.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(129,5): error NETSDK1084: There is no application host available for the specified RuntimeIdentifier 'osx-arm64'. [/Users/vs/Hosting01/runtime/src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj]

@dotnet dotnet deleted a comment from azure-pipelines bot May 4, 2022
Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Vlad for fixing this!

@VSadov
Copy link
Member Author

VSadov commented May 4, 2022

Thanks!!

@VSadov VSadov merged commit d44343b into dotnet:main May 4, 2022
@VSadov VSadov deleted the osxSF branch May 4, 2022 21:57
@am11 am11 mentioned this pull request May 5, 2022
VSadov added a commit to VSadov/runtime that referenced this pull request May 27, 2022
* Same alignment in the bundle on OSX as on Linux

* Extra VA gap between section in casse we run from sf bundle

* Rename prevSectionEnd -> prevSectionEndAligned and make it aligned.

* Suppress assert for now on OSX
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET 7 osx-arm64 single-file crashing with sigsegv
3 participants