Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Replace the link command for libpthread.a so ...



details:   https://anonhg.NetBSD.org/src/rev/ee23c051c93f
branches:  trunk
changeset: 451131:ee23c051c93f
user:      maya <maya%NetBSD.org@localhost>
date:      Tue May 07 18:12:53 2019 +0000

description:
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:

 lib/libpthread/Makefile |  16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diffs (30 lines):

diff -r a5017c1e0922 -r ee23c051c93f lib/libpthread/Makefile
--- a/lib/libpthread/Makefile   Tue May 07 15:23:32 2019 +0000
+++ b/lib/libpthread/Makefile   Tue May 07 18:12:53 2019 +0000
@@ -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 @@
 
 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



Home | Main Index | Thread Index | Old Index