[Bug libstdc++/58909] C++11's condition variables fail with static linking

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jul 22 08:55:39 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58909

--- Comment #26 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you create a new thread of execution then you'll get a non-weak reference to
pthread_create, which should cause libpthread.so to be linked even with
-Wl,--as-needed (and for static linking it will work if libpthread.a has a
single .o with all symbols).

If you don't actually have multiple threads in your program, then things like
condition_variable and once_flag can end up using the stubs in libc.so.6 which
are no-ops. But since you don't have multiple threads, it's probably not a
major problem. Most uses of std::once_flag would be better done with a local
static variable anyway (the exception being non-static data members of
classes).

With glibc 2.34 the problem goes away, so I'm not sure it's worth investing
much effort in libstdc++ trying to work around the problems with weak symbols.


More information about the Gcc-bugs mailing list