summaryrefslogtreecommitdiffstats
path: root/Modules/FindThreads.cmake
diff options
context:
space:
mode:
authorJerryShih <bignose1007@gmail.com>2018-11-17 19:15:17 (GMT)
committerJerryShih <bignose1007@gmail.com>2018-12-03 08:05:59 (GMT)
commite9a1ddc594de6e6251bf06d732775dae2cabe4c8 (patch)
treee251dc19fa839c1930c3af39bac958ee0bba0cca /Modules/FindThreads.cmake
parentbe9ad8279a29893943b342cc5ffdbf9868fb1b4c (diff)
downloadCMake-e9a1ddc594de6e6251bf06d732775dae2cabe4c8.zip
CMake-e9a1ddc594de6e6251bf06d732775dae2cabe4c8.tar.gz
CMake-e9a1ddc594de6e6251bf06d732775dae2cabe4c8.tar.bz2
FindThreads: Replace the pthread symbol checking in libc.
With asan build, we will have the pthread_create() symbol in libc. However, libasan doesn't have full pthread implementation. We can't assume that we have the pthread implementation in libc using pthread_create() symbol. Replace the pthread_create() with pthread_kill() as a quick fix.
Diffstat (limited to 'Modules/FindThreads.cmake')
-rw-r--r--Modules/FindThreads.cmake16
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index dfb683f..691b1b7 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -131,9 +131,17 @@ else()
#
set(CMAKE_HAVE_THREADS_LIBRARY)
if(NOT THREADS_HAVE_PTHREAD_ARG)
- # Check if pthread functions are in normal C library
- CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE)
- if(CMAKE_HAVE_LIBC_CREATE)
+ # Check if pthread functions are in normal C library.
+ # If the pthread functions already exist in C library, we could just use
+ # them instead of linking to the additional pthread library. We could
+ # try to check any pthread symbol name, but here is an exception. If we
+ # use clang asan build, we will find the pthread_create() symbol in the
+ # libc(libasan). However, it doesn't have the full pthread implementation.
+ # So, we can't assume that we have the pthread implementation in libc
+ # using the pthread_create() checking here. Then, we turn to check the
+ # pthread_kill() symbol instead.
+ CHECK_SYMBOL_EXISTS(pthread_kill pthread.h CMAKE_HAVE_LIBC_PTHREAD_KILL)
+ if(CMAKE_HAVE_LIBC_PTHREAD_KILL)
set(CMAKE_THREAD_LIBS_INIT "")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
@@ -159,7 +167,7 @@ else()
endif()
endif()
-if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE)
+if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD_KILL)
set(CMAKE_USE_PTHREADS_INIT 1)
set(Threads_FOUND TRUE)
endif()