[PATCH] D45359: [cmake] Improve pthread_[gs]etname_np detection code
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 6 02:54:06 PDT 2018
labath created this revision.
labath added reviewers: zturner, kparzysz, danalbert.
Herald added subscribers: krytarowski, mgorny, srhines.
Due to some android peculiarities, in some build configurations
(statically linked executables targeting older release) we could detect
the presence of these functions (because they are present in libc.a,
where check_library_exists searches), but then fail to build because the
headers did not include the definition.
This attempts to remedy that by upgrading the check_library_exists to
check_symbol_exists, which will check that the function is declared too.
I am hoping that a more thorough check will make the messy #ifdef we
have accumulated in the code obsolete, so I optimistically try to remove
it.
Repository:
rL LLVM
https://reviews.llvm.org/D45359
Files:
cmake/config-ix.cmake
lib/Support/Unix/Threading.inc
Index: lib/Support/Unix/Threading.inc
===================================================================
--- lib/Support/Unix/Threading.inc
+++ lib/Support/Unix/Threading.inc
@@ -204,13 +204,11 @@
Name.append(buf, buf + strlen(buf));
#elif defined(__linux__)
-#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
#if HAVE_PTHREAD_GETNAME_NP
constexpr uint32_t len = get_max_thread_name_length_impl();
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
Name.append(Buffer, Buffer + strlen(Buffer));
#endif
#endif
-#endif
}
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -260,12 +260,15 @@
# This check requires _GNU_SOURCE
check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY)
check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT)
-if(HAVE_LIBPTHREAD)
- check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
- check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
-elseif(PTHREAD_IN_LIBC)
- check_library_exists(c pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
- check_library_exists(c pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
+if (NOT PURE_WINDOWS)
+ if (LLVM_PTHREAD_LIB)
+ list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
+ endif()
+ check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP)
+ check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
+ if (LLVM_PTHREAD_LIB)
+ list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
+ endif()
endif()
# available programs checks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45359.141301.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/6c221df3/attachment.bin>
More information about the llvm-commits
mailing list