]> source.dussan.org Git - tigervnc.git/commitdiff
Add option to enable thread sanitizer
authorPierre Ossman <ossman@cendio.se>
Fri, 13 Nov 2015 13:06:35 +0000 (14:06 +0100)
committerPierre Ossman <ossman@cendio.se>
Fri, 27 Nov 2015 10:11:22 +0000 (11:11 +0100)
CMakeLists.txt
cmake/StaticBuild.cmake

index 7fb7b1e60ed0ae33e3e22bdcf31ac1108f345e67..f2e7d50e44a66e87167201e1ee88319d6ca6bd24 100644 (file)
@@ -80,6 +80,12 @@ if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
 endif()
 
+option(ENABLE_TSAN "Enable thread sanitizer support" OFF)
+if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8)
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
+endif()
+
 if(NOT DEFINED BUILD_WINVNC)
   set(BUILD_WINVNC 1)
 endif()
index 5a3d9987323662e62a59e2a9aa8ca2ea0c98931a..6db0e14b46b5e4dcb97f75d3bde4dc365760aa37 100644 (file)
@@ -119,6 +119,13 @@ if(BUILD_STATIC_GCC)
   if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-Bstatic -lasan -Wl,-Bdynamic -ldl -lm -lpthread")
   endif()
+  if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8)
+    # libtsan redefines some C++ symbols which then conflict with a
+    # statically linked libstdc++. Work around this by allowing multiple
+    # definitions. The linker will pick the first one (i.e. the one
+    # from libtsan).
+    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-z -Wl,muldefs -Wl,-Bstatic -ltsan -Wl,-Bdynamic -ldl -lm")
+  endif()
   if(WIN32)
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt")
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -luser32 -lkernel32 -ladvapi32 -lshell32")