From 99ee6eeca2dcf8123f17e4fcb5576330634058c1 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Thu, 19 Sep 2024 18:53:57 +1000 Subject: [PATCH] Enable Android 16 KB page size support (#22076) ### Description Add linker flags to support 16KB page size support on Android. See https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment ### Motivation and Context #21837 --- cmake/adjust_global_compile_flags.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/adjust_global_compile_flags.cmake b/cmake/adjust_global_compile_flags.cmake index 6eb784a4063e..c04d67ea4ce3 100644 --- a/cmake/adjust_global_compile_flags.cmake +++ b/cmake/adjust_global_compile_flags.cmake @@ -1,11 +1,15 @@ # work around Android NDK bug which doesn't include -O flag for Release configuration # https://github.com/android/ndk/issues/1740 # TODO: remove this when the NDK version(s) we support get fixed -if (CMAKE_SYSTEM_NAME STREQUAL "Android") +if (ANDROID) # NB: attempting to match the effects of this fix: https://android-review.googlesource.com/c/platform/ndk/+/2168845 string(APPEND CMAKE_C_FLAGS_RELEASE " -O3") string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3") string(APPEND CMAKE_ASM_FLAGS_RELEASE " -O3") + + # Build shared libraries with support for 16 KB ELF alignment + # https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384") endif() # Suggested by https://gitlab.kitware.com/cmake/cmake/-/issues/20132