Skip to content

Commit

Permalink
feat(android): enable Safe ICF to optimize binary size (Tencent#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
medns authored and pba-cra committed Feb 1, 2023
1 parent e4721b3 commit b59e880
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions android/sdk/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 core
Expand Down
9 changes: 9 additions & 0 deletions buildconfig/cmake/compiler_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b59e880

Please sign in to comment.