Skip to content

Commit

Permalink
feat(android): enable Safe ICF to optimize binary size (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
medns committed Jan 12, 2023
1 parent 3cc03d6 commit 31e62ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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
3 changes: 3 additions & 0 deletions framework/android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 31e62ec

Please sign in to comment.