Commit 2798f74a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Build Android ASAN sanitizer

parent e07a13f5
......@@ -73,7 +73,7 @@ Otherwise, you can use the `cmake-gui` or `ccmake` commands to configure all the
Some customization are particularly important:
1. `CMAKE_BUILD_TYPE`: By default it is set to `RelWithDebInfo` to build in release mode keeping the debug information. You might want to set it to `Debug` to ease the debugging.
1. `CMAKE_BUILD_TYPE`: By default it is set to `RelWithDebInfo` to build in release mode keeping the debug information. You might want to set it to `Debug` to ease the debugging. On Android, use `ASAN` to make a build linking with the Android Adress Sanitizer (https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid).
2. `LINPHONESDK_PLATFORM`: The platform for which you want to build the Linphone SDK. It must be one of: `Android`, `IOS`.
3. `LINPHONESDK_ANDROID_ARCHS`: A comma-separated list of the architectures for which you want to build the Android Linphone SDK for.
4. `LINPHONESDK_IOS_ARCHS`: Same as `LINPHONESDK_ANDROID_ARCHS` but for an iOS build.
......
Subproject commit 6c7ac258b180c87fd93550ac53ef315f010a4da1
Subproject commit 18a3aa45ee0bf0056fde0b4bbae5e1b130e54485
......@@ -36,14 +36,19 @@ execute_process(
foreach(_arch ${_archs})
if(_arch STREQUAL "arm")
set(_libarch "armeabi")
set(_asan_libarch "arm")
elseif(_arch STREQUAL "armv7")
set(_libarch "armeabi-v7a")
set(_asan_libarch "arm")
elseif(_arch STREQUAL "arm64")
set(_libarch "arm64-v8a")
set(_asan_libarch "aarch64")
elseif(_arch STREQUAL "x86")
set(_libarch "x86")
set(_asan_libarch "i686")
elseif(_arch STREQUAL "x86_64")
set(_libarch "x86_64")
set(_asan_libarch "x86_64")
else()
message(FATAL_ERROR "Unknown architecture ${_arch}")
endif()
......@@ -71,6 +76,21 @@ foreach(_arch ${_archs})
)
endforeach()
if(CMAKE_BUILD_TYPE STREQUAL "ASAN")
file(GLOB _asan_libs "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/*/lib/linux/libclang_rt.asan-${_asan_libarch}-android.so")
foreach(_asan_lib ${_asan_libs})
configure_file(${LINPHONESDK_DIR}/cmake/Android/wrap.sh.in ${LINPHONESDK_BUILD_DIR}/libs/${_libarch}/wrap.sh)
configure_file(${LINPHONESDK_DIR}/cmake/Android/wrap.sh.in ${LINPHONESDK_BUILD_DIR}/libs-debug/${_libarch}/wrap.sh)
execute_process(
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${_asan_lib}" "libs/${_libarch}/"
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${_asan_lib}" "libs-debug/${_libarch}/"
WORKING_DIRECTORY "${LINPHONESDK_BUILD_DIR}"
)
endforeach()
endif()
execute_process(
COMMAND "sh" "WORK/android-${_arch}/strip.sh" "libs/${_libarch}/*.so"
WORKING_DIRECTORY "${LINPHONESDK_BUILD_DIR}"
......
......@@ -32,6 +32,12 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
WORKING_DIRECTORY "${LINPHONESDK_BUILD_DIR}"
RESULT_VARIABLE _gradle_assemble_result
)
elseif(CMAKE_BUILD_TYPE STREQUAL "ASAN")
execute_process(
COMMAND "${LINPHONESDK_DIR}/cmake/Android/gradlew" "assembleDebug"
WORKING_DIRECTORY "${LINPHONESDK_BUILD_DIR}"
RESULT_VARIABLE _gradle_assemble_result
)
else()
execute_process(
COMMAND "${LINPHONESDK_DIR}/cmake/Android/gradlew" "assemble"
......
#!/system/bin/sh
HERE="$(cd "$(dirname "$0")" && pwd)"
export ASAN_OPTIONS=log_to_syslog=true,allow_user_segv_handler=1,verbosity=9,detect_leaks=true,leak_check_at_exit=true
export LD_PRELOAD=$HERE/libclang_rt.asan-${_asan_libarch}-android.so
exec "$@"
\ No newline at end of file
......@@ -29,7 +29,7 @@ endif()
set(LINPHONESDK_ANDROID_MIN_SUPPORTED_NDK 16)
set(LINPHONESDK_ANDROID_MAX_SUPPORTED_NDK 19)
set(LINPHONESDK_ANDROID_MAX_SUPPORTED_NDK 20)
cmake_minimum_required(VERSION 3.10)
......
......@@ -77,7 +77,7 @@ endforeach()
add_custom_target(copy-libs ALL
"${CMAKE_COMMAND}" "-DLINPHONESDK_DIR=${LINPHONESDK_DIR}" "-DLINPHONESDK_BUILD_DIR=${CMAKE_BINARY_DIR}" "-DLINPHONESDK_ANDROID_ARCHS=${LINPHONESDK_ANDROID_ARCHS}" "-P" "${LINPHONESDK_DIR}/cmake/Android/CopyLibs.cmake"
"${CMAKE_COMMAND}" "-DLINPHONESDK_DIR=${LINPHONESDK_DIR}" "-DLINPHONESDK_BUILD_DIR=${CMAKE_BINARY_DIR}" "-DLINPHONESDK_ANDROID_ARCHS=${LINPHONESDK_ANDROID_ARCHS}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" "-DCMAKE_ANDROID_NDK=${CMAKE_ANDROID_NDK}" "-P" "${LINPHONESDK_DIR}/cmake/Android/CopyLibs.cmake"
COMMENT "Copying libs"
DEPENDS ${_android_build_targets}
)
......
Subproject commit 422b34f22d8f03f61ba5252de6f7456d03c06fc2
Subproject commit aeec550f98f2aeb7341c2ca110b3c07e917e7d8f
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment