This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
weak pthread symbols in libgcc/gthr-posix.h cause issues
- From: Szabolcs Nagy <nsz at port70 dot net>
- To: gcc at gcc dot gnu dot org
- Cc: Jonathan Wakely <jwakely at redhat dot com>, Rich Felker <dalias at libc dot org>
- Date: Sun, 16 Nov 2014 21:42:55 +0100
- Subject: weak pthread symbols in libgcc/gthr-posix.h cause issues
- Authentication-results: sourceware.org; auth=none
the weakref magic in libgcc/gthr-posix.h is not guaranteed to work
which can at least break libstdc++ with static linking and dlopen
there are several bugs here:
- fallback code (unknown posix systems) should assume multi-threaded
application instead of using a fragile threadedness test
- determining threadedness with weak symbols is broken for dynamic
loading and static linking as well (dlopened library can pull in pthread
dependency at runtime, and with static linking a symbol does not indicate
the availability of another)
- using symbols through weak references at runtime is wrong with static
linking (it just happens to work with hacks that put a single .o into
libpthread.a)
see this analysis for more details and crashing example code:
http://www.openwall.com/lists/musl/2014/10/18/5
the static linking issue there was fixed by unconditionally disabling
the weak symbols in libgcc/gthr.h when building the toolchain:
#define GTHREAD_USE_WEAK 0
i sent this report to the libstdc++ list first but got redirected here:
https://gcc.gnu.org/ml/libstdc++/2014-11/msg00122.html
the static linking issue there was worked around by using linker flags
'-Wl,--whole-archive -lpthread -Wl,--no-whole-archive'
i think upstream should fix this properly