This is an archive of the discontinued LLVM Phabricator instance.

[lld] Ensure we link to the threading library used by std::thread (e.g. pthreads).
AbandonedPublic

Authored by dsanders on Oct 28 2015, 5:17 PM.

Details

Summary

This fixes the BUILD_SHARED_LIBS=ON build. We must link to the threading
library even when LLVM_ENABLE_THREADS is OFF.

Diff Detail

Event Timeline

dsanders updated this revision to Diff 38699.Oct 28 2015, 5:17 PM
dsanders retitled this revision from to [lld] Ensure we link to the threading library used by std::thread (e.g. pthreads)..
dsanders updated this object.
dsanders added subscribers: atanasyan, llvm-commits.
ruiu edited edge metadata.Oct 29 2015, 6:52 AM

Currently LLD does not spawn threads using std::thread if LLVM_ENABLE_THREADS=OFF, but it surely includes <thread> even if the flag is OFF. Is anyone who thinks that's wrong in the first place?

I'm OK with this patch, but I'd like to get experts opinions.

FWIW, it seems odd that we'd need pthreads when we don't use threads. I've just had a look at the preprocessed source for COFF/SymbolTable.cpp and the pthread_create reference comes from this line:

__asm ("" : : "r" (&pthread_create));

which was in the <thread> that was included by <future>.

In D14165#277751, @ruiu wrote:

I'm OK with this patch, but I'd like to get experts opinions.

FWIW, this solves pr25064 (https://llvm.org/bugs/show_bug.cgi?id=25064).

Which C++ library is that? On my system (gcc 4.9) running

grep -r '&pthread_create' /usr/include/c++/

finds nothing.

And in the preprocessed file:

$ grep pthread_create SymbolTable.ii
extern int pthread_create (pthread_t *restrict newthread,
static typeof(pthread_create) gthrw_pthread_create attribute
((weakref("pthread_create")));

return __gthrw_pthread_create (__threadid, __null, __func, __args);

Cheers,
Rafael

It's the libstdc++-4.9-dev in Debian Jessie (amd64). The package version is 4.9.2-10.

dsanders abandoned this revision.Jul 18 2019, 6:59 PM