This is the mail archive of the mailing list for the GCC 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]

weak pthread symbols in libgcc/gthr-posix.h cause issues

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

see this analysis for more details and crashing example code:

the static linking issue there was fixed by unconditionally disabling
the weak symbols in libgcc/gthr.h when building the toolchain:


i sent this report to the libstdc++ list first but got redirected here:

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

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