Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid marking pthread_atfork() as weak if provided by libc_nonshared.a.
On Linux, pthread_atfork() is provided not by libpthread.so, but by libc_nonshared.a (for glibc >= 2.28) or by libpthread_nonshared.a (for glibc <= 2.27), and using "#pragma weak pthread_atfork" will cause pthread_atfork to be undefined (and have an address of NULL) even if the relevant lib*_nonshared.a was explicitly specified to the linker. This is explained by this paragraph from Chapter 4, section "Symbol Table", of the System V ABI specification, as pointed out by Hugo Grostabussiat: When the link editor searches archive libraries [see ``Archive File'' in Chapter 7], it extracts archive members that contain definitions of undefined global symbols. The member's definition may be either a global or a weak symbol. The link editor does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value. Therefore, if either of these lib*_nonshared.a libraries exists, we should avoid marking pthread_atfork as weak. We were doing this correctly for glibc <= 2.27, as we were checking for libpthread_nonshared.a, but not for libc_nonshared.a, so we would still mark pthread_atfork as a weak symbol on machines that provide libc_nonshared.a but not libpthread_nonshared.a, that is, on glibc >= 2.28 machines without a dummy backward compatibility version of libpthread_nonshared.a installed. This patch makes us do the right thing for glibc >= 2.28 as well, and was derived from patches provided by Rolf Eike Beer <[email protected]> and Antal Nemes <[email protected]>. Thanks to Hugo Grostabussiat <[email protected]>, Henrik Grindal Bakken <[email protected]> and Tomáš Mózes <[email protected]> for the discussion and testing. Reported-by: Changqing Li <[email protected]> Signed-off-by: Lennert Buytenhek <[email protected]>
- Loading branch information