[Top][All Lists]

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

threadlib: support static linking

From: Bruno Haible
Subject: threadlib: support static linking
Date: Sun, 16 Jul 2017 15:43:46 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-83-generic; KDE/5.18.0; x86_64; ; )

When configuring a gnulib testdir with LDFLAGS="-static", the multithreading
tests fail in strange ways. The reason is that weak symbols don't work:
In a program linked through "gcc -static ... -pthread", symbols declared
weak (such as pthread_cancel) are marked "w" in the resulting executable,
i.e. their value evaluates to NULL. Linking with -pthread or -lpthread was
meant to avoid this, but did not have the desired effect.

2017-07-16  Bruno Haible  <address@hidden>

        threadlib: Support static linking.
        * m4/threadlib.m4 (gl_THREADLIB_BODY): When static linking is in use,
        set gl_cv_have_weak to 'no'.

diff --git a/m4/threadlib.m4 b/m4/threadlib.m4
index f79fde2..6fd1b9e 100644
--- a/m4/threadlib.m4
+++ b/m4/threadlib.m4
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 12
+# threadlib.m4 serial 13
 dnl Copyright (C) 2005-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -148,6 +148,10 @@ int main ()
               [gl_cv_have_weak="guessing no"])
+       dnl But when linking statically, weak symbols don't work.
+       case " $LDFLAGS " in
+         *" -static "*) gl_cv_have_weak=no ;;
+       esac
     if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
       # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that

reply via email to

[Prev in Thread] Current Thread [Next in Thread]