Skip to content

Commit d4a57f1

Browse files
author
liujisi@google.com
committed
Fix corner case in acx_pthread.m4 to work with -nostdlib, patch from Kacper Kowalik.
1 parent 57014ff commit d4a57f1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

m4/acx_pthread.m4

+34
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,40 @@ if test "x$acx_pthread_ok" = xyes; then
340340
acx_pthread_ok=no
341341
fi
342342
343+
AC_MSG_CHECKING([whether what we have so far is sufficient with -nostdlib])
344+
CFLAGS="-nostdlib $CFLAGS"
345+
# we need c with nostdlib
346+
LIBS="$LIBS -lc"
347+
AC_TRY_LINK([#include <pthread.h>],
348+
[pthread_t th; pthread_join(th, 0);
349+
pthread_attr_init(0); pthread_cleanup_push(0, 0);
350+
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
351+
[done=yes],[done=no])
352+
353+
if test "x$done" = xyes; then
354+
AC_MSG_RESULT([yes])
355+
else
356+
AC_MSG_RESULT([no])
357+
fi
358+
359+
if test x"$done" = xno; then
360+
AC_MSG_CHECKING([whether -lpthread saves the day])
361+
LIBS="-lpthread $LIBS"
362+
AC_TRY_LINK([#include <pthread.h>],
363+
[pthread_t th; pthread_join(th, 0);
364+
pthread_attr_init(0); pthread_cleanup_push(0, 0);
365+
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
366+
[done=yes],[done=no])
367+
368+
if test "x$done" = xyes; then
369+
AC_MSG_RESULT([yes])
370+
PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
371+
else
372+
AC_MSG_RESULT([no])
373+
AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries and -nostdlib])
374+
fi
375+
fi
376+
343377
CFLAGS="$save_CFLAGS"
344378
LIBS="$save_LIBS"
345379
CC="$save_CC"

0 commit comments

Comments
 (0)