[commit: ghc] master: configure: detect whether -lpthreads is necessary for pthreads (e94bfb6)

git at git.haskell.org git at git.haskell.org
Tue Feb 28 15:59:17 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/e94bfb677298de3c4b4e0d1223fbc589849b79be/ghc

>---------------------------------------------------------------

commit e94bfb677298de3c4b4e0d1223fbc589849b79be
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sun Feb 26 19:28:08 2017 -0500

    configure: detect whether -lpthreads is necessary for pthreads
    
    Some platforms have pthreads support available without linking against
    libpthread (and indeed don't even offer a libpthread to link against).
    One example of this is Android's bionic library. Teach the RTS about
    this case.
    
    Test Plan: Validate while cross-compiling targetting Android on aarch64
    
    Reviewers: simonmar, austin, hvr, erikd, rwbarton
    
    Subscribers: danharaj, thomie, erikd, snowleopard
    
    Differential Revision: https://phabricator.haskell.org/D3149


>---------------------------------------------------------------

e94bfb677298de3c4b4e0d1223fbc589849b79be
 configure.ac        | 25 +++++++++++++++++++++++++
 rts/package.conf.in |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/configure.ac b/configure.ac
index ec526d8..3c153c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -946,6 +946,31 @@ AC_TRY_LINK_FUNC(printf\$LDBLStub,
             [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
     ])
 
+dnl Some platforms (e.g. Android's Bionic) have pthreads support available
+dnl without linking against libpthread. Check whether -lpthread is necessary
+dnl to use pthreads.
+dnl
+dnl Note that it is important that this happens before we AC_CHECK_LIB(thread)
+AC_MSG_CHECKING(whether -lpthread is needed for pthreads)
+AC_CHECK_FUNC(pthread_create,
+    [
+        AC_MSG_RESULT(no)
+        need_lpthread=0
+    ],
+    [
+        AC_CHECK_LIB(pthread, pthread_create,
+            [
+                AC_MSG_RESULT(yes)
+                need_lpthread=1
+            ],
+            [
+                AC_MSG_RESULT([no pthreads support found.])
+                need_lpthread=0
+            ])
+    ])
+AC_DEFINE_UNQUOTED([NEED_PTHREAD_LIB], [$need_lpthread],
+    [Define 1 if we need to link code using pthreads with -lpthread])
+
 dnl ** pthread_setname_np is a recent addition to glibc, and OS X has
 dnl    a different single-argument version.
 AC_CHECK_LIB(pthread, pthread_setname_np)
diff --git a/rts/package.conf.in b/rts/package.conf.in
index 338fcb1..02437ae 100644
--- a/rts/package.conf.in
+++ b/rts/package.conf.in
@@ -46,7 +46,9 @@ extra-libraries:
                               ,"gdi32"      /* for the linker */
                               ,"winmm"      /* for the linker */
 #endif
+#if NEED_PTHREAD_LIB
                               , "pthread"   /* for pthread_getthreadid_np, pthread_create, etc. */
+#endif
 #if defined(DEBUG) && defined(HAVE_LIBBFD)
                               ,"bfd", "iberty"  /* for debugging */
 #endif



More information about the ghc-commits mailing list