Skip to content

Apply patches for 16KB page size for https://github.com/swiftlang/swift/pull/81596 #12

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions swift-ci/sdks/android/patches/apply-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
patches_dir=$(dirname $(realpath -- "${BASH_SOURCE[0]}"))
cd ${1}

# https://github.com/swiftlang/swift/pull/81596
git apply -v -C1 ${patches_dir}/page-size-16KB-81398-AddSwiftStdlib.patch
git apply -v -C1 ${patches_dir}/page-size-16KB-81398-targets.patch

case "${BUILD_SCHEME}" in
swift-*-branch)
git apply -v -C1 ${patches_dir}/swift-android.patch
Expand All @@ -20,3 +24,4 @@ esac

# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 8db43c6290ee04145264c04728a030dd74f87452 Mon Sep 17 00:00:00 2001
From: Marc Prud'hommeaux <[email protected]>
Date: Sun, 18 May 2025 19:10:36 -0400
Subject: [PATCH] Support 16 KB page sizes on Android

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
---
stdlib/cmake/modules/AddSwiftStdlib.cmake | 2 ++
1 file changed, 2 insertions(+)

diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
index ce113989ad75d..089f5f30acbb5 100644
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -2469,6 +2469,8 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-shared")
# TODO: Instead of `lib${name}.so` find variable or target property which already have this value.
list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so")
+ # Ensure compatibility with Android 15+ devices using 16KB memory pages.
+ list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384")
endif()

if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)
13 changes: 13 additions & 0 deletions swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index fba09416ddb..3fbc51955f4 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -165,6 +165,7 @@ class AndroidPlatform(Platform):

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

def cmake_options(self, args):

2 changes: 2 additions & 0 deletions swift-ci/sdks/android/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ for arch in $archs; do
--libdispatch-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \
--foundation-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \
--cross-compile-append-host-target-to-destdir=False


# --extra-cmake-options='-DCMAKE_EXTRA_LINK_FLAGS="-Wl,-z,max-page-size=16384"'
# need to remove symlink that gets created in the NDK to the previous arch's build
# or else we get errors like:
Expand Down
Loading