NetBSD-Bugs archive

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

Re: lib/59685: libcrypto should not depend on libpthread



The following reply was made to PR lib/59685; it has been noted by GNATS.

From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: Christos Zoulas <christos%zoulas.com@localhost>
Cc: gnats-bugs%NetBSD.org@localhost, netbsd-bugs%NetBSD.org@localhost, joerg%NetBSD.org@localhost
Subject: Re: lib/59685: libcrypto should not depend on libpthread
Date: Sat, 4 Oct 2025 14:42:40 +0000

 This is a multi-part message in MIME format.
 --=_aD0stfJJ+WVg8+9bTfy4bTTT5i9m1xYu
 
 > Date: Sat, 4 Oct 2025 03:10:06 +0000
 > From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
 > 
 > I can't find any record of rationale.  I can't think of a good reason
 > why a library like libcrypto shouldn't be able to have a call to
 > pthread_create that is dynamically gated on thread configuration, so
 > that multithreaded applications linking against libpthread will work
 > but single-threaded applications can still use it without linking
 > against libpthread. [...]
 
 Here's a good reason: it is useful to detect the mistake of #including
 <pthread.h> and calling pthread_create without linking against
 libpthread, and it is useful to detect it at link-time rather than
 only at run-time.
 
 So, we could let libraries opt into having a pthread_create stub in
 non-threaded applications by defining a feature macro, say
 _NETBSD_PTHREAD_CREATE_WEAK:
 
 	/* library.c */
 	#define _NETBSD_PTHREAD_CREATE_WEAK
 
 	#include <pthread.h>
 
 	... if (max_threads > 0) error = pthread_create(...) ...
 
 Defining _NETBSD_PTHREAD_CREATE_WEAK will make pthread.h expose a
 macro
 
 	#define	pthread_create	__libc_thr_create
 
 so pthread_create expands to a symbol __libc_thr_create which is
 defined in libc to always fail.  libc already defines this symbol
 weakly[*]; libpthread already overrides it with a strong alias to the
 real pthread_create.
 
 Applications which _don't_ opt into _NETBSD_PTHREAD_CREATE_WEAK will
 fail to link if you forget to link against libpthread, due to missing
 pthread_create symbol -- this preserves the link-time error detection.
 
 
 The attached patch series implements this, and adds some automatic
 tests for:
 (a) link-time pthread error detection,
 (b) using a library with weak pthread_create in a non-threaded test
     program (pthread_create fails gracefully), and
 (c) using a library with weak pthread_create in a threaded test
     program (pthread_create works).
 The patch series also makes libc's __libc_thr_create stub fail
 gracefully, rather than raise SIGABRT, in non-threaded applications,
 like all the other stubs.
 
 Net change to libc symbols:
 +__libc_thr_attr_destroy
 +__libc_thr_attr_init
 +__libc_thr_attr_setdetachstate
 +__libc_thr_detach
 +__libc_thr_join
 +__libc_thr_detach_stub (for consistency with other stubs)
 +__libc_thr_join_stub (for consistency with other stubs)
 
 Net change to libpthread symbols:
 +__libc_thr_attr_destroy
 +__libc_thr_attr_init
 +__libc_thr_attr_setdetachstate
 +__libc_thr_detach
 +__libc_thr_join
 
 Net change to pthread.h declarations:
 
 +__libc_thr_attr_destroy
 +__libc_thr_attr_init
 +__libc_thr_attr_setdetachstate
 +__libc_thr_detach
 +__libc_thr_join
 
 Net change to pthread.h macros, if you don't define
 _NETBSD_PTHREAD_CREATE_WEAK:
 
 +#define pthread_attr_destroy __libc_thr_attr_destroy
 +#define pthread_attr_init __libc_thr_attr_init
 +#define pthread_attr_setdetachstate __libc_thr_attr_setdetachstate
 +#define pthread_detach __libc_thr_detach
 +#define pthread_join __libc_thr_join
 
 Additional change to pthread.h macros if you do define it:
 
 +#define pthread_create __libc_thr_create
 
 
 [*] Currently __libc_thr_create raises SIGABRT uncondiitonally, but I
     don't see any reason why it shouldn't just fail with EOPNOTSUPP or
     ENOSYS or whatever in non-threaded applications, and currently
     there are no applications which can even call __libc_thr_create
     without reaching into libc internals.
 
 --=_aD0stfJJ+WVg8+9bTfy4bTTT5i9m1xYu
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr59685-libcryptolibpthreadstubs-v2"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr59685-libcryptolibpthreadstubs-v2.patch"
 
 # HG changeset patch
 # User Taylor R Campbell <riastradh%NetBSD.org@localhost>
 # Date 1759546071 0
 #      Sat Oct 04 02:47:51 2025 +0000
 # Branch trunk
 # Node ID 5702b7021d2976bdb1bc35f51e4f97a4a319aaef
 # Parent  a0306dcafaf26c32d79b45df1e2a5c7fbf8b84e1
 # EXP-Topic riastradh-pr59685-libcryptolibpthreadstubs
 libc: Expose some more pthread stubs.
 
 Additionally, provide the option for pthread.h to expose
 pthread_create so that libc can provide a weak stub for it, if you
 define _NETBSD_PTHREAD_CREATE_WEAK.
 
 This allows libraries to use the functions without linking against
 libpthread for applications that don't need threads.  For example,
 with OpenSSL's libcrypto, as long as you don't try to raise
 OSSL_set_max_threads above 0, it won't ever try pthread_create.
 
 New pthread.h macros defined:
 
 pthread_attr_destroy		__libc_thr_attr_destroy
 pthread_attr_init		__libc_thr_attr_init
 pthread_attr_setdetachstate	__libc_thr_attr_setdetachstate
 pthread_detach			__libc_thr_detach
 pthread_join			__libc_thr_join
 
 New pthread.h macros defined if _NETBSD_PTHREAD_CREATE_WEAK is
 defined first:
 
 pthread_create			__libc_thr_create
 
 New symbols defined by libc as weak aliases for stubs that always
 fail but can be overridden by libpthread:
 
 __libc_thr_attr_destroy
 __libc_thr_attr_init
 __libc_thr_attr_setdetachstate
 __libc_thr_detach
 __libc_thr_join
 
 Note that libc already defined __libc_thr_create.
 
 New internal stubs, not for overriding:
 
 __libc_thr_detach_stub
 __libc_thr_join_stub
 
 These were formerly called __libc_pthread_detach and
 __libc_pthread_join, respectively, and libc has defined weak aliases
 pthread_detach and pthread_join for them since 2013.  I retained all
 four of those symbols, but defined new ones in the __ namespace that
 match the pattern for other thread stubs to avoid raising questions
 about why the pattern seems to be broken.  I left a comment noting
 this fact too.
 
 New pthread strong aliases to override the libc symbols:
 
 __libc_thr_attr_destroy
 __libc_thr_attr_init
 __libc_thr_attr_setdetachstate
 __libc_thr_detach
 __libc_thr_join
 
 Note that pthread already defined a strong __libc_thr_create alias
 for the real pthread_create, so there is no need to add a new one.
 
 PR lib/59685: libcrypto should not depend on libpthread
 
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libc/include/reentrant.h
 --- a/lib/libc/include/reentrant.h	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libc/include/reentrant.h	Sat Oct 04 02:47:51 2025 +0000
 @@ -204,8 +204,6 @@ int	__libc_thr_once(once_t *, void (*)(v
  int	__libc_thr_sigsetmask(int, const sigset_t *, sigset_t *);
  thr_t	__libc_thr_self(void);
  int	__libc_thr_yield(void);
 -void	__libc_thr_create(thr_t *, const thrattr_t *,
 -	    void *(*)(void *), void *);
  void	__libc_thr_exit(void *) __attribute__((__noreturn__));
  int	*__libc_thr_errno(void);
  int	__libc_thr_setcancelstate(int, int *);
 @@ -267,6 +265,8 @@ thr_t	__libc_thr_self_stub(void);
  int	__libc_thr_yield_stub(void);
  int	__libc_thr_create_stub(thr_t *, const thrattr_t *,
  	    void *(*)(void *), void *);
 +int	__libc_thr_detach_stub(thr_t);
 +int	__libc_thr_join_stub(thr_t, void **);
  void	__libc_thr_exit_stub(void *) __dead;
  int	*__libc_thr_errno_stub(void);
  int	__libc_thr_setcancelstate_stub(int, int *);
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libc/thread-stub/thread-stub.c
 --- a/lib/libc/thread-stub/thread-stub.c	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libc/thread-stub/thread-stub.c	Sat Oct 04 02:47:51 2025 +0000
 @@ -43,8 +43,6 @@
 =20
  #define	__LIBC_THREAD_STUBS
 =20
 -#define pthread_join	__libc_pthread_join
 -#define pthread_detach	__libc_pthread_detach
  #include "namespace.h"
  #include "reentrant.h"
  #include "tsd.h"
 @@ -70,11 +68,33 @@ do {					\
  #define	CHECK_NOT_THREADED()	/* nothing */
  #endif
 =20
 -__weak_alias(pthread_join, __libc_pthread_join)
 -__weak_alias(pthread_detach, __libc_pthread_detach)
 +/*
 + * These aliases are probably not necessary but have been there
 + * historically, probably by mistake.
 + */
 +__weak_alias(pthread_join, __libc_thr_join)
 +__weak_alias(pthread_detach, __libc_thr_detach)
 +
 +/*
 + * These aliases appear to have been an accident -- nothing has ever
 + * exposed them in a .h file, and they have probably never been used.
 + */
 +__strong_alias(__libc_pthread_join, __libc_thr_join)
 +__strong_alias(__libc_pthread_detach, __libc_thr_detach)
 +
 +/*
 + * These aliases are exposed by pthread.h and overridden by libpthread.
 + * This way libraries can have calls to pthread_create/join/detach
 + * without linking against libpthread, but they will fail at runtime in
 + * applications not linked against libpthread.  (Libraries linked
 + * against libpthread themselves, of course, will work, and carry the
 + * dependency to the application.)
 + */
 +__weak_alias(__libc_thr_join, __libc_thr_join_stub)
 +__weak_alias(__libc_thr_detach, __libc_thr_detach_stub)
 =20
  int
 -pthread_join(pthread_t thread, void **valptr)
 +__libc_thr_join_stub(pthread_t thread, void **valptr)
  {
 =20
  	if (thread =3D=3D pthread_self())
 @@ -83,7 +103,7 @@ pthread_join(pthread_t thread, void **va
  }
 =20
  int
 -pthread_detach(pthread_t thread)
 +__libc_thr_detach_stub(pthread_t thread)
  {
 =20
  	if (thread =3D=3D pthread_self())
 @@ -94,6 +114,12 @@ pthread_detach(pthread_t thread)
  __weak_alias(pthread_setname_np, __libc_mutex_catchall_stub)
  __weak_alias(pthread_setaffinity_np, __libc_mutex_catchall_stub)
 =20
 +/* thread creation attributes */
 +
 +__weak_alias(__libc_thr_attr_init, __libc_mutex_catchall_stub)
 +__weak_alias(__libc_thr_attr_setdetachstate, __libc_mutex_catchall_stub)
 +__weak_alias(__libc_thr_attr_destroy, __libc_mutex_catchall_stub)
 +
  /* mutexes */
 =20
  int __libc_mutex_catchall_stub(mutex_t *);
 @@ -419,9 +445,9 @@ int
  	/* LINTED deliberate lack of effect */
  	(void)a;
 =20
 -	DIE();
 +	CHECK_NOT_THREADED();
 =20
 -	return (EOPNOTSUPP);
 +	return EOPNOTSUPP;
  }
 =20
  __dead void
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libpthread/pthread.c
 --- a/lib/libpthread/pthread.c	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libpthread/pthread.c	Sat Oct 04 02:47:51 2025 +0000
 @@ -142,6 +142,8 @@ int _sys___sigprocmask14(int, const sigs
 =20
  __strong_alias(__libc_thr_self,pthread_self)
  __strong_alias(__libc_thr_create,pthread_create)
 +__strong_alias(__libc_thr_detach,pthread_detach)
 +__strong_alias(__libc_thr_join,pthread_join)
  __strong_alias(__libc_thr_exit,pthread_exit)
  __strong_alias(__libc_thr_errno,pthread__errno)
  __strong_alias(__libc_thr_setcancelstate,pthread_setcancelstate)
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libpthread/pthread.h
 --- a/lib/libpthread/pthread.h	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libpthread/pthread.h	Sat Oct 04 02:47:51 2025 +0000
 @@ -303,17 +303,21 @@ int	pthread_cond_has_waiters_np(pthread_
   * program. This permits code, particularly libraries that do not
   * directly use threads but want to be thread-safe in the presence of
   * threaded callers, to use pthread mutexes and the like without
 - * unnecessairly including libpthread in their linkage.
 + * unnecessarily including libpthread in their linkage.
   *
 - * Left out of this list are functions that can't sensibly be trivial
 - * or no-op stubs in a single-threaded process (pthread_create,
 - * pthread_kill, pthread_detach), functions that normally block and
 - * wait for another thread to do something (pthread_join), and
 - * functions that don't make sense without the previous functions
 - * (pthread_attr_*). The pthread_cond_wait and pthread_cond_timedwait
 - * functions are useful in implementing certain protection mechanisms,
 - * though a non-buggy app shouldn't end up calling them in
 - * single-threaded mode.
 + * A common mistake is to include pthread.h but not link against
 + * libpthread in applications that create threads.  Since threading
 + * adds substantial overhead to basic libc functionality like stdio, we
 + * don't want to make libpthread default, but we do want to catch this
 + * mistake.  We catch it by not defining pthread_create in libc or
 + * renaming it to a stub that is defined in libc by default.
 + *
 + * However, some libraries (like openssl libcrypto) will _optionally_
 + * create threads in threaded applications.  These libraries can
 + * request the stub by defining _PTHREAD_CREATE_WEAK, so they can be
 + * used by threaded applications -- which need to link against
 + * libpthread themselves to avoid runtime errors -- and non-threaded
 + * applications which don't link against libpthread at all.
   *
   * The rename is done as:
   * #define pthread_foo	__libc_foo
 @@ -331,6 +335,38 @@ int	pthread_cond_has_waiters_np(pthread_
 =20
  #ifndef __LIBPTHREAD_SOURCE__
  __BEGIN_DECLS
 +int	__libc_thr_create(pthread_t * __restrict,
 +	    const pthread_attr_t * __restrict, void *(*)(void *),
 +	    void * __restrict);
 +int	__libc_thr_detach(pthread_t);
 +int	__libc_thr_join(pthread_t, void **);
 +
 +int	__libc_thr_attr_init(pthread_attr_t *);
 +int	__libc_thr_attr_setdetachstate(pthread_attr_t *, int);
 +int	__libc_thr_attr_destroy(pthread_attr_t *);
 +__END_DECLS
 +
 +/*
 + * If _NETBSD_PTHREAD_CREATE_WEAK is defined, make pthread_create
 + * expand to a symbol which is defined as a weak alias by libc, so
 + * libraries can opt into using it for threaded applications without
 + * requiring non-threaded applications to be linked against libpthread.
 + * Otherwise, if you include pthread.h _without_ defining
 + * _NETBSD_PTHREAD_CREATE_WEAK and try to call pthread_create without
 + * linking against libpthread, the linker will detect this as an error.
 + */
 +#ifdef _NETBSD_PTHREAD_CREATE_WEAK
 +#define	pthread_create	__libc_thr_create
 +#endif
 +
 +#define	pthread_detach	__libc_thr_detach
 +#define	pthread_join	__libc_thr_join
 +
 +#define	pthread_attr_init		__libc_thr_attr_init
 +#define	pthread_attr_setdetachstate	__libc_thr_attr_setdetachstate
 +#define	pthread_attr_destroy		__libc_thr_attr_destroy
 +
 +__BEGIN_DECLS
  int	__libc_mutex_init(pthread_mutex_t * __restrict, const pthread_mutexatt=
 r_t * __restrict);
  int	__libc_mutex_lock(pthread_mutex_t *);
  int	__libc_mutex_trylock(pthread_mutex_t *);
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libpthread/pthread_attr.c
 --- a/lib/libpthread/pthread_attr.c	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libpthread/pthread_attr.c	Sat Oct 04 02:47:51 2025 +0000
 @@ -48,6 +48,10 @@
  #include "pthread.h"
  #include "pthread_int.h"
 =20
 +__strong_alias(__libc_thr_attr_init, pthread_attr_init)
 +__strong_alias(__libc_thr_attr_setdetachstate, pthread_attr_setdetachstate)
 +__strong_alias(__libc_thr_attr_destroy, pthread_attr_destroy)
 +
  __weak_alias(pthread_attr_get_np, _pthread_attr_get_np)
 =20
  static struct pthread_attr_private *pthread__attr_init_private(
 diff -r a0306dcafaf2 -r 5702b7021d29 lib/libpthread/pthread_mi.expsym
 --- a/lib/libpthread/pthread_mi.expsym	Sat May 17 00:34:43 2025 +0000
 +++ b/lib/libpthread/pthread_mi.expsym	Sat Oct 04 02:47:51 2025 +0000
 @@ -23,13 +23,18 @@
  __libc_rwlock_trywrlock
  __libc_rwlock_unlock
  __libc_rwlock_wrlock
 +__libc_thr_attr_destroy
 +__libc_thr_attr_init
 +__libc_thr_attr_setdetachstate
  __libc_thr_create
  __libc_thr_curcpu
 +__libc_thr_detach
  __libc_thr_equal
  __libc_thr_errno
  __libc_thr_exit
  __libc_thr_getspecific
  __libc_thr_init
 +__libc_thr_join
  __libc_thr_keycreate
  __libc_thr_keydelete
  __libc_thr_once
 # HG changeset patch
 # User Taylor R Campbell <riastradh%NetBSD.org@localhost>
 # Date 1759582282 0
 #      Sat Oct 04 12:51:22 2025 +0000
 # Branch trunk
 # Node ID 35a38791da7ae3485d2b7df8e8513dc232aadf26
 # Parent  5702b7021d2976bdb1bc35f51e4f97a4a319aaef
 # EXP-Topic riastradh-pr59685-libcryptolibpthreadstubs
 libpthread: Test pthread_create link errors without -(l)pthread.
 
 Prompted by:
 
 PR lib/59685: libcrypto should not depend on libpthread
 
 diff -r 5702b7021d29 -r 35a38791da7a distrib/sets/lists/tests/mi
 --- a/distrib/sets/lists/tests/mi	Sat Oct 04 02:47:51 2025 +0000
 +++ b/distrib/sets/lists/tests/mi	Sat Oct 04 12:51:22 2025 +0000
 @@ -4928,6 +4928,7 @@
  ./usr/tests/usr.bin/cc/t_msan_shadow			tests-usr.bin-tests	compattestfile,=
 atf
  ./usr/tests/usr.bin/cc/t_msan_stack			tests-usr.bin-tests	compattestfile,a=
 tf
  ./usr/tests/usr.bin/cc/t_msan_unpoison			tests-usr.bin-tests	compattestfil=
 e,atf
 +./usr/tests/usr.bin/cc/t_pthread_abuse			tests-usr.bin-tests	compattestfil=
 e,atf
  ./usr/tests/usr.bin/cc/t_tsan_data_race			tests-usr.bin-tests	compattestfi=
 le,atf
  ./usr/tests/usr.bin/cc/t_tsan_heap_use_after_free	tests-usr.bin-tests	comp=
 attestfile,atf
  ./usr/tests/usr.bin/cc/t_tsan_lock_order_inversion	tests-usr.bin-tests	com=
 pattestfile,atf
 diff -r 5702b7021d29 -r 35a38791da7a tests/usr.bin/cc/Makefile
 --- a/tests/usr.bin/cc/Makefile	Sat Oct 04 02:47:51 2025 +0000
 +++ b/tests/usr.bin/cc/Makefile	Sat Oct 04 12:51:22 2025 +0000
 @@ -26,6 +26,7 @@ TESTS_SH+=3D	$(UBSAN_TESTS)
  TESTS_SH+=3D	t_ctype_abuse
  TESTS_SH+=3D	t_hello
  TESTS_SH+=3D	t_libgomp
 +TESTS_SH+=3D	t_pthread_abuse
 =20
  TESTS_SH+=3D	t_fuzzer_oom
  TESTS_SH+=3D	t_fuzzer_simple
 diff -r 5702b7021d29 -r 35a38791da7a tests/usr.bin/cc/t_pthread_abuse.sh
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/usr.bin/cc/t_pthread_abuse.sh	Sat Oct 04 12:51:22 2025 +0000
 @@ -0,0 +1,79 @@
 +#	$NetBSD$
 +#
 +# Copyright (c) 2025 The NetBSD Foundation, Inc.
 +# All rights reserved.
 +#
 +# Redistribution and use in source and binary forms, with or without
 +# modification, are permitted provided that the following conditions
 +# are met:
 +# 1. Redistributions of source code must retain the above copyright
 +#    notice, this list of conditions and the following disclaimer.
 +# 2. Redistributions in binary form must reproduce the above copyright
 +#    notice, this list of conditions and the following disclaimer in the
 +#    documentation and/or other materials provided with the distribution.
 +#
 +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMI=
 TED
 +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICUL=
 AR
 +# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF T=
 HE
 +# POSSIBILITY OF SUCH DAMAGE.
 +#
 +
 +pthread_abuse_head()
 +{
 +
 +	atf_set "descr" \
 +	    "Test that pthread_create calls without -lpthread fail to link"
 +	atf_set "require.progs" "cc"
 +}
 +pthread_abuse_body()
 +{
 +
 +	cat >test.c <<'EOF'
 +#include <err.h>
 +#include <pthread.h>
 +#include <stdlib.h>
 +
 +static void *
 +start(void *cookie)
 +{
 +	return cookie;
 +}
 +
 +int
 +main(void)
 +{
 +	int cookie =3D 123;
 +	pthread_t t;
 +	void *result;
 +	int error;
 +
 +	error =3D pthread_create(&t, NULL, &start, &cookie);
 +	if (error)
 +		errc(EXIT_FAILURE, error, "pthread_create");
 +	error =3D pthread_join(t, &result);
 +	if (error)
 +		errc(EXIT_FAILURE, error, "pthread_join");
 +	return (result =3D=3D &cookie ? 0 : EXIT_FAILURE);
 +}
 +EOF
 +	atf_check -s not-exit:0 \
 +	    -e match:'undefined reference to.*pthread_create' \
 +	    cc -o test test.c
 +	atf_check cc -o test test.c -lpthread
 +	atf_check ./test
 +	atf_check cc -o test test.c -pthread
 +	atf_check ./test
 +}
 +
 +atf_init_test_cases()
 +{
 +
 +	atf_add_test_case pthread_abuse
 +}
 # HG changeset patch
 # User Taylor R Campbell <riastradh%NetBSD.org@localhost>
 # Date 1759585108 0
 #      Sat Oct 04 13:38:28 2025 +0000
 # Branch trunk
 # Node ID 482501fe3793ece2812ad62746d01f89c513873d
 # Parent  35a38791da7ae3485d2b7df8e8513dc232aadf26
 # EXP-Topic riastradh-pr59685-libcryptolibpthreadstubs
 libpthread: Test pthread stubs in threaded vs non-threaded programs.
 
 PR lib/59685: libcrypto should not depend on libpthread
 
 diff -r 35a38791da7a -r 482501fe3793 distrib/sets/lists/debug/mi
 --- a/distrib/sets/lists/debug/mi	Sat Oct 04 12:51:22 2025 +0000
 +++ b/distrib/sets/lists/debug/mi	Sat Oct 04 13:38:28 2025 +0000
 @@ -2426,6 +2426,8 @@
  ./usr/libdata/debug/usr/tests/lib/libpthread/t_thrd.debug		tests-lib-tests=
 		debug,atf,compattestfile
  ./usr/libdata/debug/usr/tests/lib/libpthread/t_timedmutex.debug		tests-lib=
 -tests		debug,atf,compattestfile
  ./usr/libdata/debug/usr/tests/lib/libpthread/t_tss.debug		tests-lib-tests	=
 	debug,atf,compattestfile
 +./usr/libdata/debug/usr/tests/lib/libpthread/weak/t_pthread_weak_nothread.=
 debug		tests-lib-tests		debug,atf,compattestfile
 +./usr/libdata/debug/usr/tests/lib/libpthread/weak/t_pthread_weak_threaded.=
 debug		tests-lib-tests		debug,atf,compattestfile
  ./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_dummy.debug		tests-obso=
 lete		obsolete
  ./usr/libdata/debug/usr/tests/lib/libpthread_dbg/t_threads.debug	tests-obs=
 olete		obsolete
  ./usr/libdata/debug/usr/tests/lib/librefuse/t_refuse_opt.debug		tests-lib-=
 debug		debug,atf,compattestfile
 diff -r 35a38791da7a -r 482501fe3793 distrib/sets/lists/debug/shl.mi
 --- a/distrib/sets/lists/debug/shl.mi	Sat Oct 04 12:51:22 2025 +0000
 +++ b/distrib/sets/lists/debug/shl.mi	Sat Oct 04 13:38:28 2025 +0000
 @@ -373,6 +373,7 @@
  ./usr/libdata/debug/usr/tests/lib/libc/tls/libh_tls_dynamic.so.1.debug	tes=
 ts-lib-debug		debug,compattestfile,atf
  ./usr/libdata/debug/usr/tests/lib/libc/tls/t_tls_dlopen.debug		tests-lib-d=
 ebug		debug,compattestfile,atf
  ./usr/libdata/debug/usr/tests/lib/libc/tls/t_tls_dynamic.debug		tests-lib-=
 debug		debug,compattestfile,atf
 +./usr/libdata/debug/usr/tests/lib/libpthread/weak/libh_pthread_weak.so.1.d=
 ebug		tests-lib-debug		debug,compattestfile,atf
  ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_=
 helper_symver_dso.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
  ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_=
 helper_symver_dso.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
  ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_=
 helper_symver_dso.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
 diff -r 35a38791da7a -r 482501fe3793 distrib/sets/lists/tests/mi
 --- a/distrib/sets/lists/tests/mi	Sat Oct 04 12:51:22 2025 +0000
 +++ b/distrib/sets/lists/tests/mi	Sat Oct 04 13:38:28 2025 +0000
 @@ -144,6 +144,7 @@
  ./usr/libdata/debug/usr/tests/lib/libprop		tests-lib-debug		compattestfile=
 ,atf
  ./usr/libdata/debug/usr/tests/lib/libpthread		tests-lib-debug		compattestf=
 ile,atf
  ./usr/libdata/debug/usr/tests/lib/libpthread/dlopen	tests-lib-debug		compa=
 ttestfile,atf
 +./usr/libdata/debug/usr/tests/lib/libpthread/weak	tests-lib-debug		compatt=
 estfile,atf
  ./usr/libdata/debug/usr/tests/lib/libpthread_dbg	tests-obsolete		obsolete
  ./usr/libdata/debug/usr/tests/lib/librefuse		tests-lib-debug		compattestfi=
 le,atf
  ./usr/libdata/debug/usr/tests/lib/librt			tests-lib-debug		compattestfile,=
 atf
 @@ -4201,6 +4202,11 @@
  ./usr/tests/lib/libpthread/t_thread_local_dtor		tests-lib-tests		compattes=
 tfile,atf
  ./usr/tests/lib/libpthread/t_timedmutex			tests-lib-tests		compattestfile,=
 atf
  ./usr/tests/lib/libpthread/t_tss			tests-lib-tests		compattestfile,atf
 +./usr/tests/lib/libpthread/weak				tests-lib-tests		compattestfile,atf
 +./usr/tests/lib/libpthread/weak/Atffile			tests-lib-tests		compattestfile,=
 atf
 +./usr/tests/lib/libpthread/weak/Kyuafile		tests-lib-tests		compattestfile,=
 atf,kyua
 +./usr/tests/lib/libpthread/weak/t_pthread_weak_nothread	tests-lib-tests		c=
 ompattestfile,atf
 +./usr/tests/lib/libpthread/weak/t_pthread_weak_threaded	tests-lib-tests		c=
 ompattestfile,atf
  ./usr/tests/lib/libpthread_dbg				tests-obsolete		obsolete
  ./usr/tests/lib/libpthread_dbg/Atffile			tests-obsolete		obsolete
  ./usr/tests/lib/libpthread_dbg/Kyuafile			tests-obsolete		obsolete
 diff -r 35a38791da7a -r 482501fe3793 distrib/sets/lists/tests/shl.mi
 --- a/distrib/sets/lists/tests/shl.mi	Sat Oct 04 12:51:22 2025 +0000
 +++ b/distrib/sets/lists/tests/shl.mi	Sat Oct 04 13:38:28 2025 +0000
 @@ -10,6 +10,8 @@
  ./usr/tests/lib/libc/tls/libh_tls_dynamic.so.1	tests-lib-tests		compattest=
 file,atf
  ./usr/tests/lib/libc/tls/t_tls_dlopen		tests-lib-tests		compattestfile,atf
  ./usr/tests/lib/libc/tls/t_tls_dynamic		tests-lib-tests		compattestfile,atf
 +./usr/tests/lib/libpthread/weak/libh_pthread_weak.so	tests-lib-tests		comp=
 attestfile,atf
 +./usr/tests/lib/libpthread/weak/libh_pthread_weak.so.1	tests-lib-tests		co=
 mpattestfile,atf
  ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_helper_symver_dso.=
 so	tests-libexec-tests	compattestfile,atf
  ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso0/libh_helper_symver_dso.=
 so.1	tests-libexec-tests	compattestfile,atf
  ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso.=
 so	tests-libexec-tests	compattestfile,atf
 diff -r 35a38791da7a -r 482501fe3793 etc/mtree/NetBSD.dist.tests
 --- a/etc/mtree/NetBSD.dist.tests	Sat Oct 04 12:51:22 2025 +0000
 +++ b/etc/mtree/NetBSD.dist.tests	Sat Oct 04 13:38:28 2025 +0000
 @@ -126,6 +126,7 @@
  ./usr/libdata/debug/usr/tests/lib/libprop
  ./usr/libdata/debug/usr/tests/lib/libpthread
  ./usr/libdata/debug/usr/tests/lib/libpthread/dlopen
 +./usr/libdata/debug/usr/tests/lib/libpthread/weak
  ./usr/libdata/debug/usr/tests/lib/librefuse
  ./usr/libdata/debug/usr/tests/lib/librt
  ./usr/libdata/debug/usr/tests/lib/librumpclient
 @@ -341,6 +342,7 @@
  ./usr/tests/lib/libprop
  ./usr/tests/lib/libpthread
  ./usr/tests/lib/libpthread/dlopen
 +./usr/tests/lib/libpthread/weak
  ./usr/tests/lib/librefuse
  ./usr/tests/lib/librt
  ./usr/tests/lib/librumpclient
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/Makefile
 --- a/tests/lib/libpthread/Makefile	Sat Oct 04 12:51:22 2025 +0000
 +++ b/tests/lib/libpthread/Makefile	Sat Oct 04 13:38:28 2025 +0000
 @@ -69,5 +69,6 @@ FILESDIR=3D	${TESTSDIR}
  FILES=3D		d_mach
 =20
  SUBDIR=3D		dlopen
 +SUBDIR=3D		weak
 =20
  .include <bsd.test.mk>
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/Makefile
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/Makefile	Sat Oct 04 13:38:28 2025 +0000
 @@ -0,0 +1,8 @@
 +#	$NetBSD$
 +#
 +
 +SUBDIR+=3D	lib
 +SUBDIR+=3D	.WAIT
 +SUBDIR+=3D	test
 +
 +.include <bsd.subdir.mk>
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/Makefile.inc
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 @@ -0,0 +1,1 @@
 +.include "${.PARSEDIR}/../../Makefile.inc"
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/lib/Makefile
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/lib/Makefile	Sat Oct 04 13:38:28 2025 +0000
 @@ -0,0 +1,20 @@
 +#	$NetBSD$
 +#
 +
 +MKPROFILE=3D	no		# XXX hack -- should be NOPROFILE
 +NOLINT=3D		# defined
 +NOMAN=3D		# defined
 +NOSTATICLIB=3D	# defined
 +
 +LIB=3D		h_pthread_weak
 +SRCS+=3D		h_pthread_weak.c
 +
 +LDADD+=3D		-latf-c
 +
 +LIBDIR=3D		${TESTSBASE}/lib/libpthread/weak
 +SHLIBDIR=3D	${TESTSBASE}/lib/libpthread/weak
 +SHLIB_MAJOR=3D	1
 +
 +LIBISCXX=3D	yes
 +
 +.include <bsd.lib.mk>
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/lib/h_pthrea=
 d_weak.c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/lib/h_pthread_weak.c	Sat Oct 04 13:38:28 20=
 25 +0000
 @@ -0,0 +1,83 @@
 +/*	$NetBSD$	*/
 +
 +/*-
 + * Copyright (c) 2025 The NetBSD Foundation, Inc.
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
 RS
 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
 ITED
 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
 LAR
 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
 RS
 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
 THE
 + * POSSIBILITY OF SUCH DAMAGE.
 + */
 +
 +#include <sys/cdefs.h>
 +__RCSID("$NetBSD$");
 +
 +#define	_PTHREAD_CREATE_WEAK
 +
 +#include "h_pthread_weak.h"
 +
 +#include <atf-c.h>
 +#include <pthread.h>
 +
 +#include "h_macros.h"
 +
 +static void *
 +start(void *cookie)
 +{
 +	return cookie;
 +}
 +
 +void
 +test_mutex(void)
 +{
 +	pthread_mutex_t mtx;
 +
 +	RZ(pthread_mutex_init(&mtx, NULL));
 +	RZ(pthread_mutex_lock(&mtx));
 +	RZ(pthread_mutex_unlock(&mtx));
 +	RZ(pthread_mutex_destroy(&mtx));
 +}
 +
 +void
 +test_thread_creation(void)
 +{
 +	int cookie =3D 123;
 +	pthread_attr_t attr;
 +	pthread_t t;
 +	void *result;
 +
 +	RZ(pthread_attr_init(&attr));
 +	RZ(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
 +	RZ(pthread_create(&t, NULL, &start, &cookie));
 +	RZ(pthread_attr_destroy(&attr));
 +	RZ(pthread_join(t, &result));
 +	ATF_CHECK_EQ(result, &cookie);
 +}
 +
 +void
 +test_thread_creation_failure(void)
 +{
 +	int cookie =3D 123;
 +	pthread_t t;
 +	int error;
 +
 +	error =3D pthread_create(&t, NULL, &start, &cookie);
 +	ATF_CHECK_MSG(error !=3D 0, "pthread_create unexpectedly succeeded");
 +}
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/lib/h_pthrea=
 d_weak.h
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/lib/h_pthread_weak.h	Sat Oct 04 13:38:28 20=
 25 +0000
 @@ -0,0 +1,36 @@
 +/*	$NetBSD$	*/
 +
 +/*-
 + * Copyright (c) 2025 The NetBSD Foundation, Inc.
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
 RS
 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
 ITED
 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
 LAR
 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
 RS
 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
 THE
 + * POSSIBILITY OF SUCH DAMAGE.
 + */
 +
 +#ifndef	H_PTHREAD_WEAK_H
 +#define	H_PTHREAD_WEAK_H
 +
 +void test_mutex(void);
 +void test_thread_creation(void);
 +void test_thread_creation_failure(void);
 +
 +#endif	/* H_PTHREAD_WEAK_H */
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/test/Makefile
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/test/Makefile	Sat Oct 04 13:38:28 2025 +0000
 @@ -0,0 +1,23 @@
 +#	$NetBSD$
 +#
 +
 +TESTSDIR=3D	${TESTSBASE}/lib/libpthread/weak
 +
 +TESTS_C+=3D	t_pthread_weak_nothread
 +TESTS_C+=3D	t_pthread_weak_threaded
 +
 +CPPFLAGS+=3D	-I${.CURDIR}/../lib
 +
 +.include <bsd.own.mk>		# PRINTOBJDIR
 +
 +.if !defined(H_PTHREAD_WEAK_OBJDIR)
 +H_PTHREAD_WEAK_OBJDIR!=3D	cd ../lib && ${PRINTOBJDIR}
 +.MAKEOVERRIDES+=3D	H_PTHREAD_WEAK_OBJDIR
 +.endif
 +
 +LDADD+=3D		-L${H_PTHREAD_WEAK_OBJDIR}
 +LDADD+=3D		-Wl,-rpath,${TESTSBASE}/lib/libpthread/weak
 +LDADD+=3D		-lh_pthread_weak
 +LDADD.t_pthread_weak_threaded+=3D	-lpthread
 +
 +.include <bsd.test.mk>
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/test/t_pthre=
 ad_weak_nothread.c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/test/t_pthread_weak_nothread.c	Sat Oct 04 1=
 3:38:28 2025 +0000
 @@ -0,0 +1,65 @@
 +/*	$NetBSD$	*/
 +
 +/*-
 + * Copyright (c) 2025 The NetBSD Foundation, Inc.
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
 RS
 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
 ITED
 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
 LAR
 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
 RS
 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
 THE
 + * POSSIBILITY OF SUCH DAMAGE.
 + */
 +
 +#include <sys/cdefs.h>
 +__RCSID("$NetBSD$");
 +
 +#include <atf-c.h>
 +
 +#include "h_pthread_weak.h"
 +
 +ATF_TC(mutex);
 +ATF_TC_HEAD(mutex, tc)
 +{
 +	atf_tc_set_md_var(tc, "descr",
 +	    "Test mutex usage in library with _PTHREAD_CREATE_WEAK");
 +}
 +ATF_TC_BODY(mutex, tc)
 +{
 +	test_mutex();
 +}
 +
 +ATF_TC(thread_creation_failure);
 +ATF_TC_HEAD(thread_creation_failure, tc)
 +{
 +	atf_tc_set_md_var(tc, "descr",
 +	    "Test pthread_create via library fails in no-thread application");
 +}
 +ATF_TC_BODY(thread_creation_failure, tc)
 +{
 +	test_thread_creation_failure();
 +}
 +
 +ATF_TP_ADD_TCS(tp)
 +{
 +	ATF_TP_ADD_TC(tp, mutex);
 +	ATF_TP_ADD_TC(tp, thread_creation_failure);
 +
 +	return atf_no_error();
 +}
 +
 diff -r 35a38791da7a -r 482501fe3793 tests/lib/libpthread/weak/test/t_pthre=
 ad_weak_threaded.c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 +++ b/tests/lib/libpthread/weak/test/t_pthread_weak_threaded.c	Sat Oct 04 1=
 3:38:28 2025 +0000
 @@ -0,0 +1,65 @@
 +/*	$NetBSD$	*/
 +
 +/*-
 + * Copyright (c) 2025 The NetBSD Foundation, Inc.
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
 RS
 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
 ITED
 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
 LAR
 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
 RS
 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
 THE
 + * POSSIBILITY OF SUCH DAMAGE.
 + */
 +
 +#include <sys/cdefs.h>
 +__RCSID("$NetBSD$");
 +
 +#include <atf-c.h>
 +
 +#include "h_pthread_weak.h"
 +
 +ATF_TC(mutex);
 +ATF_TC_HEAD(mutex, tc)
 +{
 +	atf_tc_set_md_var(tc, "descr",
 +	    "Test mutex usage in library with _PTHREAD_CREATE_WEAK");
 +}
 +ATF_TC_BODY(mutex, tc)
 +{
 +	test_mutex();
 +}
 +
 +ATF_TC(thread_creation);
 +ATF_TC_HEAD(thread_creation, tc)
 +{
 +	atf_tc_set_md_var(tc, "descr",
 +	    "Test pthread_create via library in threaded application");
 +}
 +ATF_TC_BODY(thread_creation, tc)
 +{
 +	test_thread_creation();
 +}
 +
 +ATF_TP_ADD_TCS(tp)
 +{
 +	ATF_TP_ADD_TC(tp, mutex);
 +	ATF_TP_ADD_TC(tp, thread_creation);
 +
 +	return atf_no_error();
 +}
 +
 # HG changeset patch
 # User Taylor R Campbell <riastradh%NetBSD.org@localhost>
 # Date 1759587558 0
 #      Sat Oct 04 14:19:18 2025 +0000
 # Branch trunk
 # Node ID 14dfe4989904762502528845ad2a5d8836941afd
 # Parent  482501fe3793ece2812ad62746d01f89c513873d
 # EXP-Topic riastradh-pr59685-libcryptolibpthreadstubs
 openssl: Stop dragging libpthread into every libcrypto user.
 
 With the new _NETBSD_PTHREAD_CREATE_WEAK, libcrypto can have a call
 to pthread_create without linking against libpthread, so it is not
 necessary to link all libcrypto users against libpthread too.
 
 Applications that link against libcrypto but not libpthread can't use
 threaded OpenSSL functionality, of course -- OSSL_set_max_threads
 will always fail in such applications.
 
 This reverts all the makefile churn that I found for unnecessary
 libpthread linkage since the openssl 3.5 import.
 
 PR lib/59685: libcrypto should not depend on libpthread
 
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/apache2/openssl/bin/Ma=
 kefile
 --- a/crypto/external/apache2/openssl/bin/Makefile	Sat Oct 04 13:38:28 2025=
  +0000
 +++ b/crypto/external/apache2/openssl/bin/Makefile	Sat Oct 04 14:19:18 2025=
  +0000
 @@ -65,7 +65,6 @@ verify.c \
  version.c \
  x509.c \
 =20
 -CPPFLAGS+=3D -pthread
  CPPFLAGS+=3D -I${OPENSSLSRC} -I${.CURDIR}/../include
  CPPFLAGS+=3D -I${OPENSSLSRC}/include -I${OPENSSLSRC}/apps/include
 =20
 @@ -74,8 +73,8 @@ PROGDPLIBS+=3D    apps ${OPENSSLSRC}/../li
  PROGDPLIBS+=3D    ssl ${OPENSSLSRC}/../lib/libssl
  PROGDPLIBS+=3D    crypto ${OPENSSLSRC}/../lib/libcrypto
 =20
 -LDADD+=3D	-lcrypt -lpthread
 -DPADD+=3D	${LIBCRYPT} ${LIBPTHREAD}
 +LDADD+=3D	-lcrypt
 +DPADD+=3D	${LIBCRYPT}
 =20
  CRYPTODIST=3D	${NETBSDSRCDIR}/crypto
  .include "${NETBSDSRCDIR}/crypto/Makefile.openssl"
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/apache2/openssl/dist/c=
 rypto/thread/api.c
 --- a/crypto/external/apache2/openssl/dist/crypto/thread/api.c	Sat Oct 04 1=
 3:38:28 2025 +0000
 +++ b/crypto/external/apache2/openssl/dist/crypto/thread/api.c	Sat Oct 04 1=
 4:19:18 2025 +0000
 @@ -62,6 +62,15 @@ int OSSL_set_max_threads(OSSL_LIB_CTX *c
      tdata =3D OSSL_LIB_CTX_GET_THREADS(ctx);
      if (tdata =3D=3D NULL)
          return 0;
 +#ifdef __NetBSD__
 +    /*
 +     * Applications must link against libpthread in order to enable
 +     * openssl thread support.
 +     */
 +    extern int __isthreaded;	/* XXX */
 +    if (!__isthreaded)
 +        return 0;
 +#endif
 =20
      ossl_crypto_mutex_lock(tdata->lock);
      tdata->max_threads =3D max_threads;
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/apache2/openssl/lib/li=
 bcrypto/Makefile
 --- a/crypto/external/apache2/openssl/lib/libcrypto/Makefile	Sat Oct 04 13:=
 38:28 2025 +0000
 +++ b/crypto/external/apache2/openssl/lib/libcrypto/Makefile	Sat Oct 04 14:=
 19:18 2025 +0000
 @@ -25,7 +25,6 @@ USE_FIPS=3D	no
  .include <bsd.own.mk>
  .include <bsd.shlib.mk>
 =20
 -CPPFLAGS+=3D -pthread
  CPPFLAGS+=3D -Dlib${LIB} -I. -I${OPENSSLSRC}/crypto -I${OPENSSLSRC}
  CPPFLAGS+=3D -I${OPENSSLSRC}/include -I${OPENSSLSRC}/crypto/include
  CPPFLAGS+=3D -I${OPENSSLSRC}/crypto/asn1 -I${OPENSSLSRC}/crypto/evp
 @@ -51,7 +50,6 @@ CPPFLAGS+=3D -I${OPENSSLSRC}/providers/imp
 =20
  AFLAGS+=3D-DELF
  LIBDPLIBS+=3D crypt ${NETBSDSRCDIR}/lib/libcrypt
 -LIBDPLIBS+=3D pthread ${NETBSDSRCDIR}/lib/libpthread
 =20
  OS_VERSION!=3D ${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
 =20
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/apache2/openssl/lib/li=
 bcrypto/thread.inc
 --- a/crypto/external/apache2/openssl/lib/libcrypto/thread.inc	Sat Oct 04 1=
 3:38:28 2025 +0000
 +++ b/crypto/external/apache2/openssl/lib/libcrypto/thread.inc	Sat Oct 04 1=
 4:19:18 2025 +0000
 @@ -16,3 +16,5 @@ SRCS +=3D ${THREAD_SRCS}
  CPPFLAGS.${cryptosrc} +=3D -I${OPENSSLSRC}/crypto/thread
  CPPFLAGS.${cryptosrc} +=3D -I${OPENSSLSRC}/crypto/thread/arch ${THREADCPPF=
 LAGS}
  .endfor
 +
 +CPPFLAGS.thread_posix.c+=3D	-D_NETBSD_PTHREAD_CREATE_WEAK
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/apache2/openssl/lib/li=
 bssl/thread.inc
 --- a/crypto/external/apache2/openssl/lib/libssl/thread.inc	Sat Oct 04 13:3=
 8:28 2025 +0000
 +++ b/crypto/external/apache2/openssl/lib/libssl/thread.inc	Sat Oct 04 14:1=
 9:18 2025 +0000
 @@ -11,3 +11,5 @@ SRCS +=3D ${THREAD_SRCS}
  CPPFLAGS.${cryptosrc} +=3D -I${OPENSSLSRC}/crypto/thread
  CPPFLAGS.${cryptosrc} +=3D -I${OPENSSLSRC}/crypto/thread/arch ${THREADCPPF=
 LAGS}
  .endfor
 +
 +CPPFLAGS.thread_posix.c+=3D	-D_NETBSD_PTHREAD_CREATE_WEAK
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/bsd/heimdal/Makefile.i=
 nc
 --- a/crypto/external/bsd/heimdal/Makefile.inc	Sat Oct 04 13:38:28 2025 +00=
 00
 +++ b/crypto/external/bsd/heimdal/Makefile.inc	Sat Oct 04 14:19:18 2025 +00=
 00
 @@ -22,8 +22,8 @@ DPLIBROKEN=3D	roken ${HEIMBASE}/lib/librok
  DPLIBSL=3D	sl ${HEIMBASE}/lib/libsl
  DPLIBVERS=3D	vers ${HEIMBASE}/lib/libvers
  DPLIBWIND=3D	wind ${HEIMBASE}/lib/libwind
 -KRB5LDADD=3D	-lcrypto -lcrypt -lpthread
 -KRB5DPADD=3D	${LIBCRYPTO} ${LIBCRYPT} ${LIBPTHREAD}
 +KRB5LDADD=3D	-lcrypto -lcrypt
 +KRB5DPADD=3D	${LIBCRYPTO} ${LIBCRYPT}
  HDBLDADD=3D	-lsqlite3 -lm
  HDBDPADD=3D	${LIBSQLITE3} ${LIBM}
 =20
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/bsd/heimdal/bin/hxtool=
 /Makefile
 --- a/crypto/external/bsd/heimdal/bin/hxtool/Makefile	Sat Oct 04 13:38:28 2=
 025 +0000
 +++ b/crypto/external/bsd/heimdal/bin/hxtool/Makefile	Sat Oct 04 14:19:18 2=
 025 +0000
 @@ -20,5 +20,5 @@ COPTS.hxtool.c+=3D -Wno-error=3Ddeprecated-d
  .include <${HEIMBASE}/Makefile.rules.inc>
  .include <bsd.prog.mk>
 =20
 -LDADD+=3D -lcrypto -ledit -lterminfo -lpthread
 -DPADD+=3D ${LIBCRYPTO} ${LIBEDIT} ${LIBTERMINFO} ${LIBPTHREAD}
 +LDADD+=3D -lcrypto -ledit -lterminfo
 +DPADD+=3D ${LIBCRYPTO} ${LIBEDIT} ${LIBTERMINFO}
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/bsd/netpgp/bin/Makefil=
 e.inc
 --- a/crypto/external/bsd/netpgp/bin/Makefile.inc	Sat Oct 04 13:38:28 2025 =
 +0000
 +++ b/crypto/external/bsd/netpgp/bin/Makefile.inc	Sat Oct 04 14:19:18 2025 =
 +0000
 @@ -12,5 +12,5 @@ LIBMJDIR!=3D	cd ${.PARSEDIR}/../libmj && $
  LDADD+=3D		-L${LIBMJDIR} -lmj
  DPADD+=3D		${LIBMJDIR}/libmj.a
 =20
 -LDADD+=3D		-lcrypto -lz -lbz2 -lpthread
 -DPADD+=3D		${LIBCRYPTO} ${LIBZ} ${LIBBZ2} ${LIBPTHREAD}
 +LDADD+=3D		-lcrypto -lz -lbz2
 +DPADD+=3D		${LIBCRYPTO} ${LIBZ} ${LIBBZ2}
 diff -r 482501fe3793 -r 14dfe4989904 crypto/external/bsd/openssh/bin/Makefi=
 le.inc
 --- a/crypto/external/bsd/openssh/bin/Makefile.inc	Sat Oct 04 13:38:28 2025=
  +0000
 +++ b/crypto/external/bsd/openssh/bin/Makefile.inc	Sat Oct 04 14:19:18 2025=
  +0000
 @@ -8,7 +8,6 @@ PROGDPLIBS+=3D \
      ssh ${CRYPTOBSD}/openssh/lib \
      crypto ${CRYPTOBSD:H}/${EXTERNAL_OPENSSL_SUBDIR}/lib/libcrypto \
      crypt ${NETBSDSRCDIR}/lib/libcrypt \
 -    z ${NETBSDSRCDIR}/lib/libz \
 -    pthread ${NETBSDSRCDIR}/lib/libpthread
 +    z ${NETBSDSRCDIR}/lib/libz
 =20
  .include "${.PARSEDIR}/../Makefile.inc"
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/libfido2/bin/Makefile.inc
 --- a/external/bsd/libfido2/bin/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/libfido2/bin/Makefile.inc	Sat Oct 04 14:19:18 2025 +0000
 @@ -4,6 +4,5 @@
 =20
  .PATH: ${DIST}/tools ${DIST}/man ${DIST}/openbsd-compat
 =20
 -LDADD+=3D-lfido2 -lcbor -lusbhid -lcrypto -lz -lm -lpthread
 -DPADD+=3D${LIBFIDO2} ${LIBCBOR} ${LIBUSBHID} ${LIBCRYPTO} ${LIBZ} ${LIBM} \
 -    ${LIBPTHREAD}
 +LDADD+=3D-lfido2 -lcbor -lusbhid -lcrypto -lz -lm
 +DPADD+=3D${LIBFIDO2} ${LIBCBOR} ${LIBUSBHID} ${LIBCRYPTO} ${LIBZ} ${LIBM}
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/nsd/Makefile.inc
 --- a/external/bsd/nsd/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/nsd/Makefile.inc	Sat Oct 04 14:19:18 2025 +0000
 @@ -23,7 +23,6 @@ DPLIBS+=3D ssl ${NETBSDSRCDIR}/crypto/exte
  DPLIBS+=3D crypto ${NETBSDSRCDIR}/crypto/external/${EXTERNAL_OPENSSL_SUBDI=
 R}/lib/libcrypto
  DPLIBS+=3D crypt ${NETBSDSRCDIR}/lib/libcrypt
  DPLIBS+=3D util ${NETBSDSRCDIR}/lib/libutil
 -DPLIBS+=3D pthread ${NETBSDSRCDIR}/lib/libpthread
 =20
  __subst: .USE
  	${TOOL_SED} \
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/ntp/Makefile.inc
 --- a/external/bsd/ntp/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/ntp/Makefile.inc	Sat Oct 04 14:19:18 2025 +0000
 @@ -35,8 +35,8 @@ LIBPARSE!=3D	cd ${.CURDIR}/../../lib/libpa
  LDADD+=3D		-L${LIBNTP} -lntp -L${LIBOPTS} -lopts
  DPADD+=3D		${LIBNTP}/libntp.a ${LIBOPTS}/libopts.a
 =20
 -LDADD+=3D		-lcrypto -lcrypt -lpthread
 -DPADD+=3D		${LIBCRYPTO} ${LIBCRYPT} ${LIBPTHREAD}
 +LDADD+=3D		-lcrypto -lcrypt
 +DPADD+=3D		${LIBCRYPTO} ${LIBCRYPT}
 =20
  .if ${MKMDNS:Uno} !=3D "no"
  CPPFLAGS+=3D-DHAVE_DNSREGISTRATION=3D1
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/pam-u2f/bin/pamu2fcfg/Mak=
 efile
 --- a/external/bsd/pam-u2f/bin/pamu2fcfg/Makefile	Sat Oct 04 13:38:28 2025 =
 +0000
 +++ b/external/bsd/pam-u2f/bin/pamu2fcfg/Makefile	Sat Oct 04 14:19:18 2025 =
 +0000
 @@ -16,9 +16,8 @@ PROG=3Dpamu2fcfg
  SRCS=3Dpamu2fcfg.c cmdline.c b64.c readpassphrase.c explicit_bzero.c util.c
  COPTS.util.c +=3D -Wno-error=3Dstack-protector
 =20
 -LDADD+=3D-lpam -lfido2 -lcbor -lusbhid -lcrypto -lm -lpthread
 -DPADD+=3D${LIBPAM} ${LIBFIDO2} ${LIBCBOR} ${LIBUSBHID} ${LIBCRYPTO} ${LIBM=
 } \
 -    ${LIBPTHREAD}
 +LDADD+=3D-lpam -lfido2 -lcbor -lusbhid -lcrypto -lm
 +DPADD+=3D${LIBPAM} ${LIBFIDO2} ${LIBCBOR} ${LIBUSBHID} ${LIBCRYPTO} ${LIBM}
 =20
  pamu2fcfg.1:
  	asciidoc -b docbook45 -d manpage -o pamu2fcfg.1.xml ../../dist/man/pamu2f=
 cfg.1.txt
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/ppp/usr.sbin/pppd/Makefile
 --- a/external/bsd/ppp/usr.sbin/pppd/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/ppp/usr.sbin/pppd/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -64,8 +64,6 @@ DPADD+=3D${LIBPAM} ${PAM_STATIC_DPADD}
 =20
  LDADD+=3D -lpcap -lcrypt -lssl -lcrypto -lutil -Wl,--export-dynamic
  DPADD+=3D ${LIBPCAP} ${LIBCRYPT} ${LIBSSL} ${LIBCRYPTO} ${LIBUTIL}
 -LDADD+=3D -lpthread
 -DPADD+=3D ${LIBPTHREAD}
 =20
  .for f in chap-md5 chap_ms eap
  COPTS.${f}.c+=3D	-Wno-pointer-sign
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/tcpdump/bin/Makefile
 --- a/external/bsd/tcpdump/bin/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/tcpdump/bin/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -211,8 +211,8 @@ CPPFLAGS+=3D-DHAVE_OS_IPV6_SUPPORT=3D1
  .endif
 =20
  CPPFLAGS+=3D-DHAVE_LIBCRYPTO=3D1 -DHAVE_OPENSSL_EVP_H=20
 -LDADD+=3D	-lcrypto -lcrypt -lpthread
 -DPADD+=3D	${LIBCRYPTO} ${LIBCRYPT} ${LIBPTHREAD}
 +LDADD+=3D	-lcrypto -lcrypt
 +DPADD+=3D	${LIBCRYPTO} ${LIBCRYPT}
 =20
  CLEANFILES+=3D	version.c tcpdump.8
 =20
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/wpa/bin/hostapd/Makefile
 --- a/external/bsd/wpa/bin/hostapd/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/external/bsd/wpa/bin/hostapd/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -251,8 +251,8 @@ ikev2.c \
  tncs.c
 =20
 =20
 -DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES} ${LIBPTHREAD}
 -LDADD+=3D -lssl -lcrypto -ldes -lpthread
 +DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES}
 +LDADD+=3D -lssl -lcrypto -ldes
  .else
  CPPFLAGS+=3D -DINTERNAL_AES -DINTERNAL_MD5 -DINTERNAL_SHA1 -DCONFIG_NO_PBK=
 DF2
  CPPFLAGS+=3D -DCONFIG_CRYPTO_INTERNAL
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/wpa/bin/wpa_passphrase/Ma=
 kefile
 --- a/external/bsd/wpa/bin/wpa_passphrase/Makefile	Sat Oct 04 13:38:28 2025=
  +0000
 +++ b/external/bsd/wpa/bin/wpa_passphrase/Makefile	Sat Oct 04 14:19:18 2025=
  +0000
 @@ -14,8 +14,8 @@ wpabuf.c
 =20
  .if !defined(NO_CRYPT) && !defined(NO_OPENSSL) && !defined(RELEASE_CRUNCH)
  SRCS+=3D crypto_openssl.c
 -DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES} ${LIBPTHREAD}
 -LDADD+=3D -lssl -lcrypto -ldes -lpthread
 +DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES}
 +LDADD+=3D -lssl -lcrypto -ldes
  .else
  CPPFLAGS+=3D -DINTERNAL_AES -DINTERNAL_MD5 -DINTERNAL_SHA1
  CPPFLAGS+=3D -DCONFIG_CRYPTO_INTERNAL
 diff -r 482501fe3793 -r 14dfe4989904 external/bsd/wpa/bin/wpa_supplicant/Ma=
 kefile
 --- a/external/bsd/wpa/bin/wpa_supplicant/Makefile	Sat Oct 04 13:38:28 2025=
  +0000
 +++ b/external/bsd/wpa/bin/wpa_supplicant/Makefile	Sat Oct 04 14:19:18 2025=
  +0000
 @@ -176,8 +176,8 @@ aes-omac1.c \
  #CPPFLAGS+=3D -DEAP_FAST
  #SRCS+=3D	eap_fast.c
 =20
 -DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES} ${LIBPTHREAD}
 -LDADD+=3D -lssl -lcrypto -ldes -lpthread
 +DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBDES}
 +LDADD+=3D -lssl -lcrypto -ldes
  .else
  CPPFLAGS+=3D -DINTERNAL_AES -DINTERNAL_MD5 -DINTERNAL_SHA1 -DCONFIG_NO_PBK=
 DF2
  SRCS+=3D tls_none.c sha1-internal.c md5-internal.c aes-xinternal.c rc4.c
 diff -r 482501fe3793 -r 14dfe4989904 games/factor/Makefile
 --- a/games/factor/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/games/factor/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -10,8 +10,8 @@ SRCS=3D	factor.c pr_tbl.c
  CPPFLAGS+=3D-I${PRIMES}
 =20
  CPPFLAGS+=3D-DHAVE_OPENSSL
 -LDADD+=3D	-lcrypto -lcrypt -lpthread
 -DPADD+=3D	${LIBCRYPTO} ${LIBCRYPT} ${LIBPTHREAD}
 +LDADD+=3D	-lcrypto -lcrypt
 +DPADD+=3D	${LIBCRYPTO} ${LIBCRYPT}
 =20
  COPTS.factor.c+=3D -Wno-error=3Ddeprecated-declarations
 =20
 diff -r 482501fe3793 -r 14dfe4989904 libexec/httpd/Makefile
 --- a/libexec/httpd/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/libexec/httpd/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -52,8 +52,8 @@ CPPFLAGS+=3D	-DHAVE_NBUTIL_H
  LDADD+=3D		-lnbutil
  .endif
 =20
 -LDADD+=3D	-lssl -lcrypto -lpthread
 -DPADD+=3D	${LIBSSL} ${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD+=3D	-lssl -lcrypto
 +DPADD+=3D	${LIBSSL} ${LIBCRYPTO}
 =20
  #
  # Build release things.
 diff -r 482501fe3793 -r 14dfe4989904 share/mk/bsd.prog.mk
 --- a/share/mk/bsd.prog.mk	Sat Oct 04 13:38:28 2025 +0000
 +++ b/share/mk/bsd.prog.mk	Sat Oct 04 14:19:18 2025 +0000
 @@ -205,19 +205,19 @@ LIB${_lib:tu}=3D	${DESTDIR}/usr/lib/lib${_
  LIBKRB5_LDADD+=3D -lkrb5 -lcom_err \
  	-lhx509 -lcrypto -lasn1 \
  	-lwind -lheimbase -lcom_err -lroken \
 -	-lcrypt -lutil -lpthread
 +	-lcrypt -lutil
  LIBKRB5_DPADD+=3D ${LIBKRB5} ${LIBCOM_ERR} \
  	${LIBHX509} ${LIBCRYPTO} ${LIBASN1} \
  	${LIBWIND} ${LIBHEIMBASE} ${LIBCOM_ERR} ${LIBROKEN} \
 -	${LIBCRYPT} ${LIBUTIL} ${LIBPTHREAD}
 +	${LIBCRYPT} ${LIBUTIL}
  LIBGSSAPI_LDADD+=3D -lgssapi -lheimntlm ${LIBKRB5_LDADD}
  LIBGSSAPI_DPADD+=3D ${LIBGSSAPI} ${LIBHEIMNTLM} ${LIBKRB5_DPADD}
  .endif
 =20
  .if (${MKLDAP} !=3D "no")
 -LIBLDAP_LDADD+=3D -lldap -llber ${LIBGSSAPI_LDADD} -lssl -lcrypto -lpthread
 +LIBLDAP_LDADD+=3D -lldap -llber ${LIBGSSAPI_LDADD} -lssl -lcrypto
  LIBLDAP_DPADD+=3D ${LIBLDAP} ${LIBLBER} ${LIBGSSAPI_DPADD} ${LIBSSL} \
 -    ${LIBCRYPTO} ${LIBPTHREAD}
 +    ${LIBCRYPTO}
  .endif
 =20
  # PAM applications, if linked statically, need more libraries
 @@ -226,10 +226,10 @@ PAM_STATIC_LDADD+=3D -lssh
  PAM_STATIC_DPADD+=3D ${LIBSSH}
  .if (${MKKERBEROS} !=3D "no")
  PAM_STATIC_LDADD+=3D -lkafs -lkrb5 -lhx509 -lwind -lasn1 \
 -	-lroken -lcom_err -lheimbase -lcrypto -lsqlite3 -lpthread -lm
 +	-lroken -lcom_err -lheimbase -lcrypto -lsqlite3 -lm
  PAM_STATIC_DPADD+=3D ${LIBKAFS} ${LIBKRB5} ${LIBHX509} ${LIBWIND} ${LIBASN=
 1} \
  	${LIBROKEN} ${LIBCOM_ERR} ${LIBHEIMBASE} ${LIBCRYPTO} ${LIBSQLITE3} \
 -	${LIBPTHREAD} ${LIBM}
 +	${LIBM}
  .endif
  .if (${MKSKEY} !=3D "no")
  PAM_STATIC_LDADD+=3D -lskey
 diff -r 482501fe3793 -r 14dfe4989904 tests/crypto/libcrypto/Makefile
 --- a/tests/crypto/libcrypto/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/tests/crypto/libcrypto/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -19,8 +19,8 @@ SUBDIR +=3D lhash sha x509v3
  TESTSDIR=3D	${TESTSBASE}/crypto/libcrypto
 =20
  TESTS_C+=3D		t_sha512trunc
 -DPADD.t_sha512trunc+=3D	${LIBCRYPTO} ${LIBPTHREAD}
 -LDADD.t_sha512trunc+=3D	-lcrypto -lpthread
 +DPADD.t_sha512trunc+=3D	${LIBCRYPTO}
 +LDADD.t_sha512trunc+=3D	-lcrypto
 =20
  .if ${HAVE_OPENSSL} =3D=3D 10
  TESTS_SH=3D	t_certs
 diff -r 482501fe3793 -r 14dfe4989904 tests/crypto/libcrypto/Makefile.inc
 --- a/tests/crypto/libcrypto/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 +++ b/tests/crypto/libcrypto/Makefile.inc	Sat Oct 04 14:19:18 2025 +0000
 @@ -32,8 +32,8 @@ PROGDPLIBS+=3D	cryptotest ${OPENSSLSRC}/..
  .if ${HELPER_NAME} !=3D "threadstest"
  PROGDPLIBS+=3D	crypto ${OPENSSLSRC}/../lib/libcrypto
  .endif
 -DPADD_AFTER+=3D		${LIBCRYPT} ${LIBPTHREAD}
 -LDADD_AFTER+=3D		-lcrypt -lpthread
 +DPADD+=3D		${LIBCRYPT}
 +LDADD+=3D		-lcrypt
 =20
 =20
  .include <bsd.test.mk>
 diff -r 482501fe3793 -r 14dfe4989904 tests/crypto/libcrypto/dh/Makefile
 --- a/tests/crypto/libcrypto/dh/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/tests/crypto/libcrypto/dh/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -3,7 +3,5 @@
  PROGDPLIBSSTATIC=3Dyes
  HELPER_NAME=3D	dhtest
  HELPER_DIR=3D	dh
 -DPADD+=3D ${LIBPTHREAD}
 -LDADD+=3D -lpthread
 =20
  .include <bsd.init.mk>
 diff -r 482501fe3793 -r 14dfe4989904 tests/lib/libc/hash/Makefile
 --- a/tests/lib/libc/hash/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/tests/lib/libc/hash/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -6,8 +6,8 @@ TESTSDIR=3D	${TESTSBASE}/lib/libc/hash
 =20
  TESTS_C+=3D	t_sha2
  TESTS_C+=3D	t_hmac
 -LDADD.t_hmac+=3D	-lcrypto -lpthread
 -DDADD.t_hmac+=3D	${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD.t_hmac+=3D	-lcrypto
 +DDADD.t_hmac+=3D	${LIBCRYPTO}
 =20
  TESTS_SH+=3D	t_hash
 =20
 diff -r 482501fe3793 -r 14dfe4989904 usr.bin/dc/Makefile
 --- a/usr.bin/dc/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.bin/dc/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -6,8 +6,8 @@ PROG=3D	dc
  SRCS=3D	main.c dc.c bcode.c inout.c mem.c stack.c
 =20
  WARNS=3D6
 -LDADD=3D	-lcrypto -lpthread
 -DPADD=3D	${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD=3D	-lcrypto
 +DPADD=3D	${LIBCRYPTO}
 =20
  SUBDIR.roff+=3DUSD.doc
 =20
 diff -r 482501fe3793 -r 14dfe4989904 usr.bin/ftp/Makefile
 --- a/usr.bin/ftp/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.bin/ftp/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -20,8 +20,8 @@ CPPFLAGS+=3D-DNO_EDITCOMPLETE -DNO_ABOUT -
  LDADD+=3D	-ledit -lterminfo
  DPADD+=3D	${LIBEDIT} ${LIBTERMINFO}
  CPPFLAGS+=3D -DWITH_SSL
 -LDADD+=3D -lssl -lcrypto -lpthread
 -DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD+=3D -lssl -lcrypto
 +DPADD+=3D ${LIBSSL} ${LIBCRYPTO}
  .endif
 =20
  .if (!defined(SMALLPROG) || defined(SMALLPROG_INET6)) && (${USE_INET6} !=
 =3D "no")
 diff -r 482501fe3793 -r 14dfe4989904 usr.bin/moduli/Makefile.inc
 --- a/usr.bin/moduli/Makefile.inc	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.bin/moduli/Makefile.inc	Sat Oct 04 14:19:18 2025 +0000
 @@ -2,8 +2,8 @@
 =20
  .include <bsd.own.mk>
 =20
 -DPADD+=3D ${LIBCRYPTO} ${LIBPTHREAD}
 -LDADD+=3D -lcrypto -lpthread
 +DPADD+=3D ${LIBCRYPTO}
 +LDADD+=3D -lcrypto
 =20
  .if exists(${.CURDIR}/../../Makefile.inc)
  .include "${.CURDIR}/../../Makefile.inc"
 diff -r 482501fe3793 -r 14dfe4989904 usr.bin/nbsvtool/Makefile
 --- a/usr.bin/nbsvtool/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.bin/nbsvtool/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -1,8 +1,8 @@
  # $NetBSD: Makefile,v 1.4 2025/07/19 15:56:31 christos Exp $
 =20
  PROG=3D	nbsvtool
 -LDADD+=3D	-lcrypto -lpthread
 -DPADD+=3D	${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD+=3D	-lcrypto
 +DPADD+=3D	${LIBCRYPTO}
  CPPFLAGS+=3D-DOPENSSL_API_COMPAT=3D0x10100000L
 =20
  .include <bsd.prog.mk>
 diff -r 482501fe3793 -r 14dfe4989904 usr.sbin/plainrsa-gen/Makefile
 --- a/usr.sbin/plainrsa-gen/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.sbin/plainrsa-gen/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -9,8 +9,8 @@ SRCS+=3D	plainrsa-gen.c
  MAN=3D	plainrsa-gen.8
 =20
  CPPFLAGS+=3D-DNOUSE_PRIVSEP
 -LDADD+=3D -lcrypto -lipsec -lpthread
 -DPADD+=3D ${LIBCRYPTO} ${LIBIPSEC} ${LIBPTHREAD}
 +LDADD+=3D -lcrypto -lipsec
 +DPADD+=3D ${LIBCRYPTO} ${LIBIPSEC}
 =20
  .include "${.CURDIR}/../racoon/Makefile.racoon"
 =20
 diff -r 482501fe3793 -r 14dfe4989904 usr.sbin/syslogd/Makefile
 --- a/usr.sbin/syslogd/Makefile	Sat Oct 04 13:38:28 2025 +0000
 +++ b/usr.sbin/syslogd/Makefile	Sat Oct 04 14:19:18 2025 +0000
 @@ -28,8 +28,8 @@ CPPFLAGS+=3D-DOPENSSL_API_COMPAT=3D0x1010000
  LDADD+=3D	-lwrap -lblocklist=20
  DPADD+=3D	${LIBWRAP} ${LIBBLOCKLIST}=20
 =20
 -LDADD+=3D	-lssl -lcrypto -lpthread
 -DPADD+=3D ${LIBSSL} ${LIBCRYPTO} ${LIBPTHREAD}
 +LDADD+=3D	-lssl -lcrypto
 +DPADD+=3D ${LIBSSL} ${LIBCRYPTO}
 =20
  # Overflow that appears impossible
  COPTS.syslogd.c+=3D        ${CC_WNO_FORMAT_TRUNCATION} ${CC_WNO_STRINGOP_T=
 RUNCATION}
 
 --=_aD0stfJJ+WVg8+9bTfy4bTTT5i9m1xYu--
 


Home | Main Index | Thread Index | Old Index