Skip to content

[5.6][android] Move the string and other tags in pointers to the second byte because Android enabled memory tagging #42178

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

Merged
merged 1 commit into from
Aug 1, 2022

Conversation

finagolfin
Copy link
Member

@finagolfin finagolfin commented Apr 5, 2022

Cherrypick of #40779

Explanation: Starting with Android 11, AArch64 placed a tag in the top byte of pointers to allocations, which has been slowly rolling out to more devices and collides with Swift's tags. Moving these tags to the second byte works around this problem.

Scope: With the exception of the two KeyPath changes, which @jckarter suggested and said he wanted for all platforms, this pull does not modify any platform other than Android AArch64.

SR Issue: None

Risk: low

Testing: I've been applying most of this pull to the native Swift toolchain which I maintain that runs on Android devices for the last couple months, termux/termux-packages@5d98fde, with the toolchain now finally working on Android 11+ devices with tagging enabled and without any user complaint.

Reviewer: @milseman

Once this is in the official 5.6 compiler build, my Swift 5.6 Android AArch64 SDK should start working on tagged devices too.

@finagolfin finagolfin requested a review from a team as a code owner April 5, 2022 06:02
@finagolfin
Copy link
Member Author

@milseman, now that this is in trunk, can we get this in the next 5.6 point release?

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

Code in the stdlib LGTM. You'll want a green checkmark from @jckarter as well.

Note that my review is not a recommendation about what should be in what releases, etc. It's a review of the stdlib code that equally applies to trunk.

@finagolfin
Copy link
Member Author

@jckarter, if you would approve the compiler side of this pull, I'd like to get it in for the next 5.6 point release.

@airspeedswift
Copy link
Member

Once 5.6 was released, the 5.6 branch should only be for major regressions or security fixes, so I don't think we can take this change onto that branch. I understand this unlocks important use cases for an architecture, but given support for this platform is still in bringup mode, it's hard to justify merging this (even if there was a release vehicle for another 5.6 compiler, which it's not clear there will be before 5.7 now that that has branched). I suggest bringing this onto the 5.7 branch.

@finagolfin
Copy link
Member Author

finagolfin commented Apr 19, 2022

the 5.6 branch should only be for major regressions or security fixes, so I don't think we can take this change onto that branch. I understand this unlocks important use cases for an architecture, but given support for this platform is still in bringup mode, it's hard to justify merging this

This isn't a regression or security fix, but it fixes a major incompatibility introduced on Android AArch64 since Android 11 for devices that have memory tagging enabled. In my house, that's two out of three devices running Android 11+ where Swift had stopped working because tagging was enabled.

even if there was a release vehicle for another 5.6 compiler, which it's not clear there will be before 5.7 now that that has branched

Historically, the March release ships several point releases till the September release, ie 5.4.3 shipped last Sept. 9. Are you saying that's changing and 5.7 will ship much earlier?

The only reasons I submitted this PR is because most of it is exclusive to Android AArch64 so it doesn't affect any other platform, and I distribute an Android SDK that can be used with the official shipping 5.6 compiler for linux, but this fix requires changes to the compiler.

If you'd like, I can remove the two KeyPath changes that are applied to all platforms and then this patch only affects Android AArch64, with all changes scoped with #if os(Android) && arch(arm64) and if (IGM.Triple.isAndroid() && IGM.Triple.getArch() == llvm::Triple::aarch64).

That would represent zero risk to the 5.6 branch on existing supported platforms, but fix a major incompatibility on Android AArch64. Please let me know what you think.

…te because Android enabled memory tagging

Starting with Android 11, AArch64 placed a tag in the top byte of pointers to
allocations, which has been slowly rolling out to more devices and collides
with Swift's tags. Moving these tags to the second byte works around this
problem.
var misalign = Int(bitPattern: baseAddress) % alignment
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

@airspeedswift, rebased and made this KeyPath change I mentioned in my last comment, so this pull now only affects Android AArch64 and will have no effect on any other platform.

@finagolfin
Copy link
Member Author

Ping @airspeedswift, can we get this in? It only affects Android AArch64 now, so represents zero risk to other platforms.

@finagolfin
Copy link
Member Author

@shahmishal, I'd like to get this into 5.6.3, please let me know what you think.

@shahmishal
Copy link
Member

@swift-ci test

Copy link
Member

@shahmishal shahmishal left a comment

Choose a reason for hiding this comment

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

Approved for Swift 5.6.3

Copy link
Member

@shahmishal shahmishal left a comment

Choose a reason for hiding this comment

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

Approved for Swift 5.6.3

@finagolfin
Copy link
Member Author

Mac CI failure with Swift Docc is unrelated.

@finagolfin
Copy link
Member Author

@shahmishal, can we get this merged before the release?

@shahmishal shahmishal merged commit bea2507 into swiftlang:release/5.6 Aug 1, 2022
@finagolfin finagolfin deleted the tags branch August 1, 2022 23:14
@finagolfin
Copy link
Member Author

Thanks for getting this in, @shahmishal and @milseman, now I need to update my Swift 5.6 Android SDK to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants