weak pthread symbols in libgcc/gthr-posix.h cause issues
Szabolcs Nagy
nsz@port70.net
Sun Nov 16 21:08:00 GMT 2014
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
More information about the Gcc
mailing list