This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++ -Wl,--as-needed -pthread behaviour


On 24 September 2013 02:22, Alan Modra wrote:
>
> Try compiling that testcase with -static rather than -Wl,--as-needed.
> You'll hit std::system_error just like you do here.  I believe that is
> a libstdc++ bug, and can be solved by making libstdc++.a use strong
> references to pthread symbols from std::thread::join() (and perhaps
> other objects that provide c++ thread support, if there are such).

It's the std::thread constructor template that needs pthread_create.
std::thread::join() needs pthread_join.

It's complicated by the fact that the source code doesn't mention
pthread_create, it uses __gthread_create instead, which is the weak
reference.

> libstdc++.a objects that are just testing "is this program threaded"
> should continue to use weak references.
>
> Solving the problem with --as-needed and libstdc++.so isn't so easy.
> One solution might be to split off thread support from libstdc++.so.6.

Yes, I've suggested that before.  It has the additional benefit that
users don't need to say -pthread to use C++11 threads (they shouldn't
need to care that it uses pthreads under the covers) they could just
say something like -lstdc++thr where that lib would depend on
libpthread.so.

It has the huge disadvantage of breaking the ABI by removing symbols
from libstdc++.so

> Otherwise we'd need to solve the transitive reference somehow.
> ie. Teach the linker that a reference to std::thread::join() means
> that pthread_create is required.  One obvious way to do that is have
> the compiler reference pthread_create in objects that use
> std::thread::join().

How would we have the compiler do that?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]