Skip to content

Commit db6f208

Browse files
committed
[Android] Link native shared libraries with 16k page alignment
Fixes: #103360 Context: https://developer.android.com/guide/practices/page-sizes Context: https://github.com/android/ndk/wiki/Changelog-r27#announcements Sometime next year Google will start requiring that all the `.so` libraries included in applications submitted to the Play Store to be aligned to 16k page boundary (as opposed to the current one of 4k). Make changes to cmake scripts used to build both the BCL native libraries and the MonoVM so that the resulting shared libraries have the correct alignment.
1 parent 101c0da commit db6f208

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/mono/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,16 @@ else()
506506
message(FATAL_ERROR "TARGET_ARCH='${TARGET_ARCH}' not supported.")
507507
endif()
508508

509+
if(TARGET_ANDROID AND (TARGET_AMD64 OR TARGET_ARM64))
510+
# Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
511+
# This applies only to 64-bit binaries
512+
message("Android: TARGET_ARCH == ${TARGET_ARCH}")
513+
if((TARGET_ARCH STREQUAL "arm64") OR (TARGET_ARCH STREQUAL "x86_64"))
514+
message("Android: adding 16k alignment options")
515+
add_link_options(LINKER:-z,max-page-size=16384)
516+
endif()
517+
endif()
518+
509519
# arm64 MacCatalyst runtime host or AOT target is more like Apple mobile targets than x64
510520
if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64))
511521
set(TARGET_APPLE_MOBILE 1)

src/native/libs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
5858
if (CROSS_ROOTFS)
5959
include_directories(SYSTEM "${CROSS_ROOTFS}/usr/include")
6060
endif ()
61+
62+
# Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
63+
# This applies only to 64-bit binaries
64+
if(CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
65+
add_link_options(-Wl,-z,max-page-size=16384)
66+
endif()
6167
endif ()
6268

6369
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE)

0 commit comments

Comments
 (0)