Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): enable Safe ICF to optimize binary size #2858

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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