This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++ -Wl,--as-needed -pthread behaviour
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: Matthias Klose <doko at ubuntu dot com>, gcc Development <gcc at gcc dot gnu dot org>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 24 Sep 2013 14:45:08 +0200
- Subject: Re: g++ -Wl,--as-needed -pthread behaviour
- Authentication-results: sourceware.org; auth=none
- References: <52402F23 dot 4030206 at ubuntu dot com> <20130924012209 dot GM30130 at bubble dot grove dot modra dot org> <CAH6eHdRRYmG123oMHfD5gzv-iTEQpvUMzDmSWCJTJdq4+_s6Ww at mail dot gmail dot com> <20130924122406 dot GO30970 at tucnak dot zalov dot cz> <CAH6eHdR=383LBOrCJgLD9qt_SCK=DkqL510z4M5aO_ECF=-stQ at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Sep 24, 2013 at 01:34:52PM +0100, Jonathan Wakely wrote:
> On 24 September 2013 13:24, Jakub Jelinek wrote:
> > On Tue, Sep 24, 2013 at 01:13:53PM +0100, Jonathan Wakely wrote:
> >> It's the std::thread constructor template that needs pthread_create.
> >> std::thread::join() needs pthread_join.
> >
> > Are any references to that needed in libstdc++.so.6, or just in headers?
>
> It's called from libstdc++-v3/src/c++11/thread.cc which ends up in
> libstdc++.so.6
Ah, then it has to use __gthread_create.
> > Having libstdc++.so.6 depend on libpthread.so is not a good idea, the
> > latter might be possible by just referencing pthread_* instead of
> > __gthread_* where you actually require it.
>
> For targets that don't use gthr-posix.h __gthread_create is not a
> wrapper for pthread_create.
Grep tells me that other gthr* headers don't define __gthread_create at all.
Anyway, either we just declare that people who use --as-needed without
thinking about the consequences get what they deserve, or you'd need to
keep the current std::thread::_M_start_thread as is in libstdc++.so.6, but
in newer headers inline it, perhaps under a different name (using pthread_create
rather than the wrapper).
I guess for other routines it isn't really needed, thread::join if
nobody started a thread doesn't look like a good idea, similarly detach.
Jakub