From 029e0f012dbdd74bcda4ccb216e53a4069fa06f8 Mon Sep 17 00:00:00 2001 From: sylar Date: Tue, 10 Dec 2024 18:17:33 +0800 Subject: [PATCH] fix: add missed extra link flags to support to enable 16K page size for android --- android/src/main/cpp/CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/android/src/main/cpp/CMakeLists.txt b/android/src/main/cpp/CMakeLists.txt index aeab9d278..4d7ef47cb 100644 --- a/android/src/main/cpp/CMakeLists.txt +++ b/android/src/main/cpp/CMakeLists.txt @@ -29,7 +29,20 @@ target_link_libraries(${LIBRARY_NAME} ) # Support Android 15 16k page size -target_link_options(${LIBRARY_NAME} PRIVATE "-Wl,-z,max-page-size=16384") +if (${ANDROID_ABI} STREQUAL "arm64-v8a" OR ${ANDROID_ABI} STREQUAL "x86_64") + target_link_options(${LIBRARY_NAME} PRIVATE "-Wl,-z,max-page-size=16384") + + # https://github.com/llvm/llvm-project/pull/66042 + # the default linker is llvm lld since ndk r22, and gnu ld is used before ndk r22 + # so we need to add extra flags for 16K when ANDROID_NDK_MAJOR less than 22 and the linker is not lld + # coz the ld linker need to set common-page-size=16384 to align all sections to 16K page size + if(ANDROID_NDK_MAJOR LESS 22 AND NOT CMAKE_SHARED_LINKER_FLAGS MATCHES "-fuse-ld=lld" AND NOT CMAKE_MODULE_LINKER_FLAGS MATCHES "-fuse-ld=lld" AND NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-fuse-ld=lld") + message(STATUS "ndk version is ${ANDROID_NDK_MAJOR} and use ld linker, add -Wl,-z,common-page-size=16384") + set_target_properties(${LIBRARY_NAME} PROPERTIES + LINK_FLAGS "-Wl,-z,common-page-size=16384" + ) + endif() +endif() set(THIRD_PARTY_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/include/iris"