Skip to content

Commit

Permalink
i#2154 Android64: Link static c++ runtime library (#7239)
Browse files Browse the repository at this point in the history
Android splits the C++ STL runtime into a separate library which is not
provided as a standard system library. Applications are expected to
statically link the STL library (libc++_static.a) or distribute the
dynamic library (libc++_shared.so) with the application [1].

All C++ targets should now be linking the static runtime libraries.

[1]
https://developer.android.com/ndk/guides/cpp-support#important_considerations

Issue: #2154, #1874
  • Loading branch information
jackgallagher-arm authored Feb 13, 2025
1 parent cf221c4 commit a09c4c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions make/DynamoRIOConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@ function (_DR_set_compile_flags target is_client extra_flags static_DR)
set(extra_flags "${extra_flags} -fno-stack-protector")
endif (flag_present)

if (ANDROID AND tgt_cxx)
# We use static C++ runtime libraries on Android so we need to wrap the libc
# allocation functions. See https://dynamorio.org/using.html#subsec_no_loader.
string(APPEND tgt_link_flags " -Xlinker -wrap=malloc -Xlinker -wrap=realloc -Xlinker -wrap=free")
endif ()

endif (is_client)

if (NOT APPLE AND NOT ANDROID) # no .gnu.hash support on Android
Expand Down
5 changes: 5 additions & 0 deletions make/toolchain-android-llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_LIBRARY_ARCHITECTURE ${TARGET_ABI})

# Use static C++ runtime libraries.
set(CMAKE_ANDROID_STL_TYPE "c++_static")
string(APPEND CMAKE_CXX_FLAGS_INIT " -stdlib=libc++")
string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -static-libstdc++")

0 comments on commit a09c4c9

Please sign in to comment.