Module Name:    src
Committed By:   maya
Date:           Tue May  7 18:12:53 UTC 2019

Modified Files:
        src/lib/libpthread: Makefile

Log Message:
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!


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/lib/libpthread/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/Makefile
diff -u src/lib/libpthread/Makefile:1.92 src/lib/libpthread/Makefile:1.93
--- src/lib/libpthread/Makefile:1.92	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/Makefile	Tue May  7 18:12:53 2019
@@ -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

Reply via email to