Issue 87778
Summary libc++ does not link to pthread with GNU ld and older glibc
Labels libc++
Assignees
Reporter andreyv
    Commit 36bb134ac79c91129d6ea551953ce67ed776123d removed the explicit linking of `pthread` and other libraries in libc++ on GNU/Linux. This is fine with glibc version 2.34 or later, as libpthread functionality [has been moved to libc](https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS;h=da4b2223e946368018dfb5ad73532ebf7dd84181;hb=HEAD#l1048). However, with older glibc versions libc++ now fails to link:
```
[ 98%] Linking CXX shared library llvm-18.1.3.build/lib/x86_64-unknown-linux-gnu/libc++.so
CMakeFiles/cxx_shared.dir/condition_variable.cpp.o: In function `std::__1::notify_all_at_thread_exit(std::__1::condition_variable&, std::__1::unique_lock<std::__1::mutex>)':
condition_variable.cpp:(.text._ZNSt3__125notify_all_at_thread_exitERNS_18condition_variableENS_11unique_lockINS_5mutexEEE+0x19): undefined reference to `pthread_getspecific'
condition_variable.cpp:(.text._ZNSt3__125notify_all_at_thread_exitERNS_18condition_variableENS_11unique_lockINS_5mutexEEE+0x3e): undefined reference to `pthread_setspecific'
condition_variable.cpp:(.text._ZNSt3__125notify_all_at_thread_exitERNS_18condition_variableENS_11unique_lockINS_5mutexEEE+0x4a): undefined reference to `pthread_getspecific'
```

libc++ sources have code such as
```cpp
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
#endif
```
But this looks to be an LLVM extension and is not supported by the GNU linker, which is used by default when building libc++ on GNU/Linux.

Other libraries removed in the commit may have similar issues.

A workaround is to use `-DLIBCXX_ADDITIONAL_LIBRARIES=pthread`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to