On FreeBSD 5.2.1/i386, I see these link errors:

../gllib/libgnu.a(mtx.o): In function `mtx_timedlock':
/usr/home/bruno/testdir-all/build/gllib/../../gllib/mtx.c:257: undefined 
reference to `pthread_mutex_timedlock'
gmake[4]: *** [test-mtx] Error 1

test-pthread-spin.o: In function `lock_mutator_thread':
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:122: 
undefined reference to `pthread_spin_lock'
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:132: 
undefined reference to `pthread_spin_unlock'
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:136: 
undefined reference to `pthread_spin_lock'
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:138: 
undefined reference to `pthread_spin_unlock'
test-pthread-spin.o: In function `lock_checker_thread':
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:156: 
undefined reference to `pthread_spin_lock'
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:158: 
undefined reference to `pthread_spin_unlock'
test-pthread-spin.o: In function `main':
/home/bruno/testdir-all/build/gltests/../../gltests/test-pthread-spin.c:209: 
undefined reference to `pthread_spin_init'
gmake[4]: *** [test-pthread-spin] Error 1

The cause is similar: FreeBSD declares these functions in <pthread.h>, but
does not actually define them in libthr.so.

These two patches corrects the configuration results accordingly.


2023-10-15  Bruno Haible  <br...@clisp.org>

        pthread-spin: Fix link errors on FreeBSD 5.2.1/i386.
        * m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Test not only whether
        <pthread.h> defines the pthread_spinlock_t type, but also whether the
        function pthread_spin_init is actually defined.

2023-10-15  Bruno Haible  <br...@clisp.org>

        pthread_mutex_timedlock: Fix link errors on FreeBSD 5.2.1/i386.
        * m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK): Test
        not only whether pthread_mutex_timedlock is declared, but also whether
        it is actually defined.

>From 7a10f54cc7d4a9de6812ee4cdc8f3a315bc75f73 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 15 Oct 2023 21:57:26 +0200
Subject: [PATCH 1/2] pthread_mutex_timedlock: Fix link errors on FreeBSD
 5.2.1/i386.

* m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK): Test
not only whether pthread_mutex_timedlock is declared, but also whether
it is actually defined.
---
 ChangeLog                     |  7 +++++++
 m4/pthread_mutex_timedlock.m4 | 37 +++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6dc612cb49..096a70e498 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-10-15  Bruno Haible  <br...@clisp.org>
+
+	pthread_mutex_timedlock: Fix link errors on FreeBSD 5.2.1/i386.
+	* m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK): Test
+	not only whether pthread_mutex_timedlock is declared, but also whether
+	it is actually defined.
+
 2023-10-15  Bruno Haible  <br...@clisp.org>
 
 	threadlib: Fix link errors on FreeBSD 5.2.1/i386.
diff --git a/m4/pthread_mutex_timedlock.m4 b/m4/pthread_mutex_timedlock.m4
index 6686720805..b8eb81bda9 100644
--- a/m4/pthread_mutex_timedlock.m4
+++ b/m4/pthread_mutex_timedlock.m4
@@ -1,4 +1,4 @@
-# pthread_mutex_timedlock.m4 serial 2
+# pthread_mutex_timedlock.m4 serial 3
 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,39 @@ AC_DEFUN([gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK]
 [
   AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
 
-  AC_CHECK_DECL([pthread_mutex_timedlock], , [HAVE_PTHREAD_MUTEX_TIMEDLOCK=0],
+  AC_CHECK_DECL([pthread_mutex_timedlock],
+    [dnl Test whether the gnulib module 'threadlib' is in use.
+     dnl Some packages like Emacs use --avoid=threadlib.
+     dnl Write the symbol in such a way that it does not cause 'aclocal' to pick
+     dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/.
+     m4_ifdef([gl_][THREADLIB], [
+       AC_REQUIRE([gl_][THREADLIB])
+       dnl Test whether the function actually exists.
+       dnl FreeBSD 5.2.1 declares it but does not define it.
+       AC_CACHE_CHECK([for pthread_mutex_timedlock],
+         [gl_cv_func_pthread_mutex_timedlock_in_LIBMULTITHREAD],
+         [gl_save_LIBS="$LIBS"
+          LIBS="$LIBS $LIBMULTITHREAD"
+          AC_LINK_IFELSE(
+            [AC_LANG_PROGRAM(
+               [[#include <pthread.h>
+                 #include <time.h>
+               ]],
+               [[pthread_mutex_t *lock;
+                 return pthread_mutex_timedlock (&lock, (struct timespec *) 0);
+               ]])
+            ],
+            [gl_cv_func_pthread_mutex_timedlock_in_LIBMULTITHREAD=yes],
+            [gl_cv_func_pthread_mutex_timedlock_in_LIBMULTITHREAD=no])
+          LIBS="$gl_save_LIBS"
+         ])
+       if test $gl_cv_func_pthread_mutex_timedlock_in_LIBMULTITHREAD != yes; then
+         HAVE_PTHREAD_MUTEX_TIMEDLOCK=0
+       fi
+     ], [
+       :
+     ])
+    ],
+    [HAVE_PTHREAD_MUTEX_TIMEDLOCK=0],
     [[#include <pthread.h>]])
 ])
-- 
2.34.1

>From f7610114b6f94bb08f58e85bdfde6a9cfaa5b745 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 15 Oct 2023 22:00:04 +0200
Subject: [PATCH 2/2] pthread-spin: Fix link errors on FreeBSD 5.2.1/i386.

* m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Test not only whether
<pthread.h> defines the pthread_spinlock_t type, but also whether the
function pthread_spin_init is actually defined.
---
 ChangeLog          |  7 +++++++
 m4/pthread-spin.m4 | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 096a70e498..1c5a0502e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-10-15  Bruno Haible  <br...@clisp.org>
+
+	pthread-spin: Fix link errors on FreeBSD 5.2.1/i386.
+	* m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Test not only whether
+	<pthread.h> defines the pthread_spinlock_t type, but also whether the
+	function pthread_spin_init is actually defined.
+
 2023-10-15  Bruno Haible  <br...@clisp.org>
 
 	pthread_mutex_timedlock: Fix link errors on FreeBSD 5.2.1/i386.
diff --git a/m4/pthread-spin.m4 b/m4/pthread-spin.m4
index 3e8971fcc8..5c7b8b2bb5 100644
--- a/m4/pthread-spin.m4
+++ b/m4/pthread-spin.m4
@@ -1,4 +1,4 @@
-# pthread-spin.m4 serial 3
+# pthread-spin.m4 serial 4
 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,6 +25,41 @@ AC_DEFUN([gl_PTHREAD_SPIN]
       HAVE_PTHREAD_SPIN_TRYLOCK=0
       HAVE_PTHREAD_SPIN_UNLOCK=0
       HAVE_PTHREAD_SPIN_DESTROY=0
+    else
+      dnl Test whether the gnulib module 'threadlib' is in use.
+      dnl Some packages like Emacs use --avoid=threadlib.
+      dnl Write the symbol in such a way that it does not cause 'aclocal' to pick
+      dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/.
+      m4_ifdef([gl_][THREADLIB], [
+        AC_REQUIRE([gl_][THREADLIB])
+        dnl Test whether the functions actually exist.
+        dnl FreeBSD 5.2.1 declares them but does not define them.
+        AC_CACHE_CHECK([for pthread_spin_init],
+          [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD],
+          [gl_save_LIBS="$LIBS"
+           LIBS="$LIBS $LIBMULTITHREAD"
+           AC_LINK_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <pthread.h>
+                ]],
+                [[pthread_spinlock_t *lock;
+                  return pthread_spin_init (&lock, 0);
+                ]])
+             ],
+             [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD=yes],
+             [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD=no])
+           LIBS="$gl_save_LIBS"
+          ])
+        if test $gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD != yes; then
+          HAVE_PTHREAD_SPIN_INIT=0
+          HAVE_PTHREAD_SPIN_LOCK=0
+          HAVE_PTHREAD_SPIN_TRYLOCK=0
+          HAVE_PTHREAD_SPIN_UNLOCK=0
+          HAVE_PTHREAD_SPIN_DESTROY=0
+        fi
+      ], [
+        :
+      ])
     fi
   fi
 ])
-- 
2.34.1

Reply via email to