Skip to content

Commit 663ec93

Browse files
authored
Support 16 KB page sizes on Android (#81596)
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
1 parent a76ee5e commit 663ec93

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,8 @@ function(add_swift_target_library name)
25042504
list(APPEND swiftlib_link_flags_all "-shared")
25052505
# TODO: Instead of `lib${name}.so` find variable or target property which already have this value.
25062506
list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so")
2507+
# Ensure compatibility with Android 15+ devices using 16KB memory pages.
2508+
list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384")
25072509
endif()
25082510

25092511
if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def swift_flags(self, args):
164164
android_toolchain_path = self.ndk_toolchain_path(args)
165165

166166
flags += '-sdk %s/sysroot ' % (android_toolchain_path)
167-
flags += '-tools-directory %s/bin' % (android_toolchain_path)
167+
flags += '-tools-directory %s/bin ' % (android_toolchain_path)
168+
flags += '-Xclang-linker -Wl,-z,max-page-size=16384'
168169
return flags
169170

170171
def cmake_options(self, args):

0 commit comments

Comments
 (0)