[PATCH] D123691: [GTest] Change detection of libpthread

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 10:11:04 PDT 2022


nemanjai created this revision.
nemanjai added reviewers: EricWF, PowerPC.
nemanjai added a project: PowerPC.
Herald added subscribers: steven.zhang, mgorny.
Herald added a project: All.
nemanjai requested review of this revision.
Herald added a project: LLVM.

We currently use CMake's `find_library` function to detect whether `libpthread` exists on the system to determine if `pthread` should be added on the link step. However, there are configurations in which CMake's path checking fails to find the library even though the toolchain has it.

One such case is with Clang 14.0.0 on PowerPC. Due to a recent change, the build puts `libc++` and related libraries in a subdirectory that appears to depend on the default target triple. CMake then uses that subdirectory to determine the architecture and adds that name to its search paths. However, the triple for the system GNU toolchain is different so CMake fails to find it.
Namely, Clang 14.0.0's default target triple and the subdirectory name is `powerpc64le-unknown-linux-gnu` whereas the system GNU toolchain has `powerpc64le-linux-gnu`. Clang's driver has no trouble finding either the GNU includes/libraries or Clang's own. But CMake seems to get this wrong.

The net result of this is that we can't do a shared libraries build of ToT with Clang 14.0.0.

This patch proposes using `HAVE_LIBPTHREAD` which CMake seems to determine by compiling a test file with `-lpthread` (or perhaps `-pthread`, I can't really get CMake to tell me how it is figuring this out). If that variable tells CMake that the build compiler accepts the pthread option, it seems reasonable to depend on that variable to determine if we should add it to the link step when building the `llvm_gtest` library.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123691

Files:
  llvm/utils/unittest/CMakeLists.txt


Index: llvm/utils/unittest/CMakeLists.txt
===================================================================
--- llvm/utils/unittest/CMakeLists.txt
+++ llvm/utils/unittest/CMakeLists.txt
@@ -34,8 +34,7 @@
 set(LLVM_REQUIRES_RTTI 1)
 add_definitions( -DGTEST_HAS_RTTI=0 )
 
-find_library(LLVM_PTHREAD_LIBRARY_PATH pthread)
-if (LLVM_PTHREAD_LIBRARY_PATH)
+if (HAVE_LIBPTHREAD)
   list(APPEND LIBS pthread)
 endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123691.422548.patch
Type: text/x-patch
Size: 417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220413/0b30f4f2/attachment.bin>


More information about the llvm-commits mailing list