From 2ed596c87a514fc3dee998cb89c263ed15ff7b74 Mon Sep 17 00:00:00 2001 From: Andrey Somsikov Date: Tue, 9 Jun 2020 20:11:44 +0300 Subject: [PATCH] Use default thread sanitizer linkage (#833) GCC and CLang *default* sanitizer linkage differs (static vs. dynamic). Prefer default behavior as alternate seen having issues. Default (GN)U linker fails with unresolved symbols linking Clang built binaries with sanitizer enabled. Force use LLVM linker lld for Clang builds. Sanitizer instrumentation and link flags should be retained for all binaries. Updating samples cmake configuration to keep those flags after unset logic at the ie_build_samples(). --- cmake/sanitizer.cmake | 10 ++++++++-- inference-engine/CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/sanitizer.cmake b/cmake/sanitizer.cmake index a010378..104f2d5 100644 --- a/cmake/sanitizer.cmake +++ b/cmake/sanitizer.cmake @@ -27,8 +27,14 @@ endif() if (ENABLE_THREAD_SANITIZER) set(SANITIZER_COMPILER_FLAGS "-g -fsanitize=thread -fno-omit-frame-pointer") - set(SANITIZER_LINKER_FLAGS "-fsanitize=thread -static-libsan") - + set(SANITIZER_LINKER_FLAGS "-fsanitize=thread") + if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$" AND NOT WIN32) + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -fuse-ld=lld") + else() + set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -static-libsan") + endif() + endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_COMPILER_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_COMPILER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}") diff --git a/inference-engine/CMakeLists.txt b/inference-engine/CMakeLists.txt index 412a2bf..39ff413 100644 --- a/inference-engine/CMakeLists.txt +++ b/inference-engine/CMakeLists.txt @@ -79,7 +79,7 @@ function(ie_build_samples) MINGW64 CMAKE_BUILD_TYPE CMAKE_MACOSX_RPATH) unset(${var}) endforeach() - + include(sanitizer) add_subdirectory(samples) endfunction() -- 2.7.4