Skip to content

Commit c0fc8dd

Browse files
committed
PHPC-759: Fix pthread linking for static builds
1 parent 4500d8d commit c0fc8dd

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

config.m4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ if test "$PHP_MONGODB" != "no"; then
349349
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/MongoDB/Monitoring/])
350350
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/contrib/])
351351

352+
dnl Necessary to ensure that static builds include "-pthread" when linking
353+
if test "$ext_shared" != "yes"; then
354+
EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM $EXTRA_LDFLAGS"
355+
fi
356+
352357
dnl This must come after PHP_NEW_EXTENSION, otherwise the srcdir won't be set
353358
PHP_ADD_MAKEFILE_FRAGMENT
354359

scripts/build/autotools/libbson/FindDependencies.m4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ AC_CHECK_FUNC(rand_r, [AC_SUBST(BSON_HAVE_RAND_R, 1)], [], [#include <stdlib.h>]
7979
# but I actually think it is okay to just check for it even though we will
8080
# use win32 primatives.
8181
AX_PTHREAD([
82-
PHP_EVAL_INCLINE([$PTHREAD_CFLAGS])
82+
PHP_MONGODB_BSON_CFLAGS="$PHP_MONGODB_BSON_CFLAGS $PTHREAD_CFLAGS"
8383
PHP_EVAL_LIBLINE([$PTHREAD_LIBS],[MONGODB_SHARED_LIBADD])
84+
85+
# PTHREAD_CFLAGS may come back as "-pthread", which should also be used when
86+
# linking. We can trust PHP_EVAL_LIBLINE to ignore other values.
87+
PHP_EVAL_LIBLINE([$PTHREAD_CFLAGS],[MONGODB_SHARED_LIBADD])
8488
],[
8589
AC_MSG_ERROR([libbson requires pthreads on non-Windows platforms.])
8690
])

scripts/build/autotools/libmongoc/FindDependencies.m4

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,16 @@ AC_CHECK_TYPE([socklen_t],
2323
[AC_SUBST(MONGOC_HAVE_SOCKLEN, 0)],
2424
[#include <sys/socket.h>])
2525

26-
dnl libbson already requires pthreads, so skip a redundant, optional check here
27-
dnl AX_PTHREAD
26+
# Check for pthreads. libmongoc's original FindDependencies.m4 script did not
27+
# require pthreads, but it does appear to be necessary on non-Windows platforms
28+
# based on mongoc-openssl.c and mongoc-thread-private.h.
29+
AX_PTHREAD([
30+
PHP_MONGODB_MONGOC_CFLAGS="$PHP_MONGODB_MONGOC_CFLAGS $PTHREAD_CFLAGS"
31+
PHP_EVAL_LIBLINE([$PTHREAD_LIBS],[MONGODB_SHARED_LIBADD])
32+
33+
# PTHREAD_CFLAGS may come back as "-pthread", which should also be used when
34+
# linking. We can trust PHP_EVAL_LIBLINE to ignore other values.
35+
PHP_EVAL_LIBLINE([$PTHREAD_CFLAGS],[MONGODB_SHARED_LIBADD])
36+
],[
37+
AC_MSG_ERROR([libmongoc requires pthreads on non-Windows platforms.])
38+
])

0 commit comments

Comments
 (0)