summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authormaya <maya@NetBSD.org>2019-05-07 18:12:53 +0000
committermaya <maya@NetBSD.org>2019-05-07 18:12:53 +0000
commit0f4c3e69429ecc39eba762e3246fbb6a67cb9016 (patch)
tree30bb0f096bc8e16dfe5f97929d14470cab6bd500 /lib/libpthread
parent20de25a8ef9373d1f742ae7cbf056ee25d49fcb0 (diff)
Replace the link command for libpthread.a so that we create a single section
with all the libpthread symbols in it. This makes -lpthread behave like to -Wl,--whole-archive -lpthread. This avoids a situation where threaded static binaries use some libc thread stubs, which are racy. Fixes PR lib/54001: call_once2_32, call_once2_static test cases failing on amd64 since gcc7 import. Suggested by Jonathan Wakely, thanks!
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/Makefile16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/libpthread/Makefile b/lib/libpthread/Makefile
index fb762f57854..ad745d35255 100644
--- a/lib/libpthread/Makefile
+++ b/lib/libpthread/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.92 2019/04/24 11:43:19 kamil Exp $
+# $NetBSD: Makefile,v 1.93 2019/05/07 18:12:53 maya Exp $
#
NOSANITIZER= # defined
@@ -269,6 +269,20 @@ MLINKS+= tss.3 tss_set.3
INCS+= threads.h
+# PR lib/54001: create libpthread.a as a single large object, with all the
+# symbols in one section. ensures that if any libpthread function is used,
+# you get all of them from libpthread, and not the libc stubs.
+#
+# This makes -lpthread equivalent to -Wl,--whole-archive -lpthread
+
+__archivebuild: .USE
+ ${_MKTARGET_BUILD}
+ @rm -f ${.TARGET}
+ ${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
+ ${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o
+
+CLEANFILES+= ${.TARGET}.o
+
.include <bsd.lib.mk>
.else