Commit 506dd336 authored by Peio Rigaux's avatar Peio Rigaux

made sanitizer work either for android and for desktop (tested on linux) by...

made sanitizer work either for android and for desktop (tested on linux) by setting sanitizer flags in a specific config, and forcing them in the cache, to be reused by submodules
parent c0cca118
......@@ -74,7 +74,6 @@ else()
linphone_builder_get_autotools_configuration()
endif()
# Add external projects
linphone_builder_add_projects()
linphone_builder_add_dummy_libraries_generation()
......@@ -85,7 +84,6 @@ else()
include(${LINPHONE_BUILDER_ADDITIONAL_CONFIG_STEPS})
endif()
# Give a feature summary
feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
......
......@@ -25,6 +25,7 @@ lcb_git_tag_latest("linphone")
lcb_git_tag("3b88f2749d59e5346de08e121fba1d797c55ddaa")
lcb_external_source_paths("mbedtls" "externals/mbedtls" "external/mbedtls")
lcb_may_be_found_on_system(YES)
lcb_sanitizable(YES)
lcb_ignore_warnings(YES)
lcb_linking_type("-DUSE_STATIC_MBEDTLS_LIBRARY=NO" "-DUSE_SHARED_MBEDTLS_LIBRARY=YES")
......
......@@ -31,4 +31,5 @@ lcb_plugin(YES)
lcb_dependencies("ms2")
lcb_cmake_options(
"-DENABLE_AAUDIO=${ENABLE_AAUDIO}"
"-DENABLE_SANITIZER=${ENABLE_SANITIZER}"
)
......@@ -31,4 +31,5 @@ lcb_plugin(YES)
lcb_dependencies("ms2")
lcb_cmake_options(
"-DENABLE_CAMERA2=${ENABLE_CAMERA2}"
"-DENABLE_SANITIZER=${ENABLE_SANITIZER}"
)
......@@ -74,6 +74,8 @@ list(APPEND LINPHONE_BUILDER_EP_VARS
CMAKE_BUILD_WITH_INSTALL_RPATH:BOOL
CMAKE_BUNDLE_OUTPUT_DIRECTORY:PATH
CMAKE_C_COMPILER_LAUNCHER:PATH
CMAKE_C_FLAGS:STRING
CMAKE_CXX_FLAGS:STRING
CMAKE_C_FLAGS_DEBUG:STRING
CMAKE_C_FLAGS_MINSIZEREL:STRING
CMAKE_C_FLAGS_RELEASE:STRING
......@@ -98,6 +100,7 @@ list(APPEND LINPHONE_BUILDER_EP_VARS
CMAKE_INSTALL_RPATH:PATH
CMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL
CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH
CMAKE_MODULE_LINKER_FLAGS:STRING
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING
......@@ -109,6 +112,7 @@ list(APPEND LINPHONE_BUILDER_EP_VARS
CMAKE_STAGING_PREFIX:STRING
CMAKE_PROGRAM_PATH:STRING
CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH
CMAKE_SHARED_LINKER_FLAGS:STRING
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING
......@@ -352,7 +356,6 @@ macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER INCLUDE_AFTER DE
endif()
endmacro()
macro(linphone_builder_apply_flags)
if (CMAKE_CONFIGURATION_TYPES)
FOREACH(CONFIG_NAME ${CMAKE_CONFIGURATION_TYPES})
......@@ -360,7 +363,7 @@ macro(linphone_builder_apply_flags)
linphone_builder_apply_flags_for_build_type(${CONFIG_NAME_UPPER})
ENDFOREACH(CONFIG_NAME)
else()
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
linphone_builder_apply_flags_for_build_type(${BUILD_TYPE})
endif()
endmacro()
......@@ -470,15 +473,6 @@ macro(linphone_builder_apply_extra_flags_for_build_type PROJNAME BUILD_TYPE)
set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
endif()
if(ENABLE_SANITIZER AND EP_${PROJNAME}_SANITIZABLE)
set(sanitize_flags "-fsanitize=address,undefined")
set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
unset(sanitize_flags)
endif()
endif()
unset(BUILD_TYPE)
endmacro()
......
#!/system/bin/sh
HERE="$(cd "$(dirname "$0")" && pwd)"
export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1,symbolize=1,fast_unwind_on_malloc=0
export LD_PRELOAD=$HERE/libclang_rt.asan-@SANITIZER_ARCH@-android.so
"$@"
......@@ -142,10 +142,28 @@ if(ENABLE_SANITIZER)
if(SANITIZER_ARCH MATCHES "^arm")
set(SANITIZER_ARCH "arm")
endif()
file(GLOB_RECURSE _clang_rt_library "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/*/clang/*/lib/linux/libclang_rt.asan-${SANITIZER_ARCH}-android.so")
if(_clang_rt_library)
list(GET _clang_rt_library 0 _clang_rt_library)
file(COPY ${_clang_rt_library} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
#DO NOT REMOVE NOW !!!
# It SEEMS to be useless as the sanitizer builds without these lines on ndk 20 and sdk 28.
# Need to check with others versions.
#we search for liblog.so in the folder of the ndk, then if it is found we add it to the linker flags
#find_library(log_library log PATHS "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/sysroot/")
#if(NOT DEFINED log_library-NOTFOUND)
#set(CMAKE_EXE_LINKER_FLAGS "${_clang_rt_library} ${log_library} ${CMAKE_EXE_LINKER_FLAGS}")
# message("if find library config android")
# message("if find library config android CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
# message("if find library config android _clang_rt_library = ${_clang_rt_library}")
# message("if find library config android log_library = ${log_library}")
#else()
# message(fatal_error "LOG LIBRARY NOT FOUND. It is mandatory for the Android Sanitizer")
#endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/android/wrap.sh.cmake" "${CMAKE_INSTALL_PREFIX}/lib/wrap.sh" @ONLY)
endif()
endif()
......
#####################################################################################################################################
# !Warning: be SURE YOU REALLY KNOW what you are doing before modifying this file!
#####################################################################################################################################
#New behaviour uses CMAKE_EXE_LINKER FLAGS FOR check_compile (we need it to avoid link errors)
#Old behaviour does not
#cmake_policy(SET CMP0056 NEW)
if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang" OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(AUTHOR_WARNING "The sanitizer isn't currently supported for other compilers than Clang")
endif()
set(sanitize_flags "-fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(sanitize_linker_flags "-fsanitize=address,undefined")
if (LINPHONESDK_PLATFORM STREQUAL "Android" OR DEFINED ANDROID)
#For some (unknow) reason, when -llog is passed in the linker flags, cmake seems
#to reset the linker flags. That's why it is actualy passed in compiler flags with -Wl
set(sanitize_flags "${sanitize_flags} -Wl,-llog")
else()
set(sanitize_linker_flags "${sanitize_linker_flags} -lasan -lubsan")
endif()
# these link options are prepended by a semicolon if the following quotes are missing.
# we must set this quotes to prevent cmake from considering the given set as a list append
# see https://cmake.org/cmake/help/v3.16/manual/cmake-language.7.html#cmake-language-variables
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${sanitize_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${sanitize_flags}")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${sanitize_linker_flags})
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${sanitize_linker_flags}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${sanitize_linker_flags}")
#We need to put all these variables in cache so that cmake-builder external
# project variables passing includes correct values initially (from cache)
# (used very early in the build by toolchains)
#if this is not done the variables are reset
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE)
unset(sanitize_flags)
unset(sanitize_linker_flags)
......@@ -32,6 +32,6 @@ lcb_add_option("Sqlite" "Enable bc version of sqlite3" ON)
lcb_add_option("Zlib" "Enable bc version of zlib" ON)
lcb_add_option("Soci mysql" "Enable mysql support of SOCI" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT IOS AND NOT ANDROID)
lcb_add_option("Sanitizer" "Enable Clang sanitizer" "${DEFAULT_VALUE_ENABLE_SANITIZER}")
endif()
#if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT IOS)
lcb_add_option("Sanitizer" "Enable Clang sanitizer" NO)
#endif()
......@@ -34,25 +34,28 @@ string(REGEX MATCH "Pkg\\.Revision = ([0-9]+)\\.([0-9]+)\\." NDK_VERSION_MATCH "
set(CMAKE_ANDROID_NDK_VERSION ${CMAKE_MATCH_1})
set(CMAKE_ANDROID_NDK_VERSION_MINOR ${CMAKE_MATCH_2})
if(NOT ANDROID_NATIVE_API_LEVEL)
if(ENABLE_AAUDIO)
set(ANDROID_NATIVE_API_LEVEL "android-28")
elseif(ENABLE_CAMERA2)
# android-26 is required if using capture filter included preview display, otherwise android-24 is enough
set(ANDROID_NATIVE_API_LEVEL "android-24")
#ANDROID_PLATFORM_LEVEL
if(NOT ANDROID_PLATFORM)
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
#set(ANDROID_NATIVE_API_LEVEL "android-17")
set(ANDROID_PLATFORM_LEVEL "android-17")
set(ANDROID_PLATFORM "android-17")
else()
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
set(ANDROID_NATIVE_API_LEVEL "android-17")
else()
# Starting with NDK 19, API 17 no longer exists
set(ANDROID_NATIVE_API_LEVEL "android-21")
endif()
# Starting with NDK 19, API 17 no longer exists
#set(ANDROID_NATIVE_API_LEVEL "android-21")
set(ANDROID_PLATFORM_LEVEL "android-21")
set(ANDROID_PLATFORM "android-21")
endif()
endif()
set(ANDROID_CPP_FEATURES "rtti exceptions")
set(ANDROID_STL "c++_shared")
#IF ANDROID_PLATFORM != the default one (official toolchain , cached values, or default values)
#: delete the -D__ANDROID_API__ and replace it in the cached CFLAGS flags
include("${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake")
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
......@@ -72,7 +75,3 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")
set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(CMAKE_CXX_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(CMAKE_SHARED_LINKER_FLAGS_ASAN "-fsanitize=address")
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