|
| 1 | +From 8db43c6290ee04145264c04728a030dd74f87452 |
| 2 | +From: Marc Prud'hommeaux < [email protected]> |
| 3 | +Date: Sun, 18 May 2025 19:10:36 -0400 |
| 4 | +Subject: Support 16 KB page sizes on Android |
| 5 | + |
| 6 | +Android 15+ requires that native libraries be compiled with a linker flag to support 16 KB page sizes. See: https://developer.android.com/guide/practices/page-sizes#compile-r26-lower |
| 7 | + |
| 8 | +diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 9 | +index ce113989ad75d..089f5f30acbb5 100644 |
| 10 | +--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 11 | ++++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 12 | +@@ -2469,6 +2469,8 @@ function(add_swift_target_library name) |
| 13 | + list(APPEND swiftlib_link_flags_all "-shared") |
| 14 | + # TODO: Instead of `lib${name}.so` find variable or target property which already have this value. |
| 15 | + list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so") |
| 16 | ++ # Ensure compatibility with Android 15+ devices using 16KB memory pages. |
| 17 | ++ list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384") |
| 18 | + endif() |
| 19 | + |
| 20 | + if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY) |
| 21 | +diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 22 | +index fba09416ddb90..7f3f35ec8097c 100644 |
| 23 | +--- a/swift/utils/swift_build_support/swift_build_support/targets.py |
| 24 | ++++ b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 25 | +@@ -164,7 +164,8 @@ def swift_flags(self, args): |
| 26 | + android_toolchain_path = self.ndk_toolchain_path(args) |
| 27 | + |
| 28 | + flags += '-sdk %s/sysroot ' % (android_toolchain_path) |
| 29 | +- flags += '-tools-directory %s/bin' % (android_toolchain_path) |
| 30 | ++ flags += '-tools-directory %s/bin ' % (android_toolchain_path) |
| 31 | ++ flags += '-Xclang-linker -Wl,-z,max-page-size=16384' |
| 32 | + return flags |
| 33 | + |
| 34 | + def cmake_options(self, args): |
0 commit comments