diff --git a/buildconfig/cmake/compiler_toolchain.cmake b/buildconfig/cmake/compiler_toolchain.cmake index 6b6c8e771b5..2249ffe42c4 100644 --- a/buildconfig/cmake/compiler_toolchain.cmake +++ b/buildconfig/cmake/compiler_toolchain.cmake @@ -47,6 +47,15 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # based on LLVM 12 -Os) if (ANDROID_NDK) + # Android NDK default to -fno-addrsig + # in order to support linkers other than LLD [1], + # but we only uses LLD linker, so enable faddrsing to produce + # a special section `.llvm_addrsig` to support ICF (Identical Code Folding) [2]. + # + # [1] https://reviews.llvm.org/D56456 + # [2] https://github.com/android/ndk/issues/1670#issuecomment-1040941456 + list(APPEND COMPILE_OPTIONS -faddrsig) + if (${ANDROID_ABI} STREQUAL "armeabi-v7a") list(APPEND COMPILE_OPTIONS -mfloat-abi=softfp) elseif (${ANDROID_ABI} STREQUAL "arm64-v8a") diff --git a/framework/android/src/main/cpp/CMakeLists.txt b/framework/android/src/main/cpp/CMakeLists.txt index c06881b534f..b2ee9794947 100644 --- a/framework/android/src/main/cpp/CMakeLists.txt +++ b/framework/android/src/main/cpp/CMakeLists.txt @@ -46,6 +46,9 @@ if (${ANDROID_STL} STREQUAL "c++_static") "-Wl,--exclude-libs,libc++_static.a" "-Wl,--exclude-libs,libc++abi.a") endif () +# enable Safe ICF (Identical Code Folding) to optimize binary size +target_link_options(${PROJECT_NAME} PRIVATE + "-Wl,--icf=safe") # endregion # region vfs