[Top][All Lists]

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

[patch #8186] ax_pthread adds -pthread when it should not on OSX when co

From: Daniel Richard G.
Subject: [patch #8186] ax_pthread adds -pthread when it should not on OSX when compiling with clang
Date: Tue, 09 Feb 2016 08:33:28 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36

Follow-up Comment #21, patch #8186 (project autoconf-archive):

Hi everyone,

I've been working on this macro again lately, and finally have a few things
figured out---not least the ongoing Clang/Darwin issue.

First, I would like to clarify that even though Clang explicitly does not
require -pthread at link time, and gives no trouble on Darwin if this is not
specified at compile time, this flag is *not* being silently ignored during

Specifically, -pthread causes _REENTRANT to be defined, which by convention is
used to enable re-entrant declarations of variables/functions. It does happen
that on Darwin, the system headers do not conditionalize anything on
_REENTRANT, so this symbol has no effect there. But that is a property of
Apple's headers, not of Clang, and third-party headers could very well make
use of _REENTRANT. It's worth noting that "gcc -pthread" on Darwin defines
this too.

So PTHREAD_CFLAGS="-pthread" is the correct solution on Darwin (and for Clang
in general) after all. As for the warning that [older versions of] Clang gives
when linking with this flag, it can be quashed with one of the following


AX_PTHREAD will check if the compiler is Clang, and if it's a Clang that gives
the link-time warning, the macro will add either of the above to
PTHREAD_CFLAGS to kill the warning. So projects that choose to build with
-Werror won't need to carve out an exception for this.

All this is handled in new special-case code for Clang. What we have with
Clang is a compiler that's sufficiently different from most others, and whose
popularity as a free project will only increase with time, that handling it
separately and specifically makes sense.

That's not the only change I have here, however. There's a grab bag of other
improvements, gathered up over the last three years that this macro has been
used in my product development work. Here's a (hopefully exhaustive) summary:

* Minor doc/comment text tweaks

* Formally require AC_PROG_CC and AC_PROG_SED

* Use properly namespaced shell variable names

* Made 'test "x$foo" = "xbar"' syntax consistent

* Replaced obsolete AC_TRY_LINK_FUNC() call with AC_LINK_IFELSE()

* Try -kthread and -llthread only on FreeBSD, as the notes indicate these are
only used there (but I can't find a version of FreeBSD that uses either of
these; anyone know?)

* Added some observations from Solaris, Tru64 and HP-UX to the threads options

* Added special-case handling for HP-UX

* Added rudimentary support for z/OS Unix System Services ("openedition")

* On Solaris, try the "-mt" + "-lpthread" combination first, and moved
-pthreads to a general GCC handler

* Removed the Darwin special case, as it is now handled as general GCC

* Added a mechanism to verify correct pthreads support on certain platforms by
checking that _REENTRANT or _THREAD_SAFE is defined by the option we're
testing. I'd like to see what other platforms can be supported here, because
IMO it's a good way of sussing out if we're really in "pthreads mode" or not

* Totally rewrote the Clang support!

* Added a check: Is the compiler Clang?

* If compiling with Clang, use -pthread; don't bother with the general check,
because (AFAIK) Clang has never supported any other option

* If Clang give a warning when -pthread is specified in a link-only
invocation, then find an option that will shut it up---implemented by
temporarily redefining the ac_link() shell function

and special-flags check, plus extra variables to ensure idempotency

Everyone who's interested, please review these changes, try them out, kick the
tires, let me know if anything breaks. Comments and feedback will be
appreciated. (I'll need more third-party testing than previous iterations as a
few of my older exotic test systems have bit the dust in recent years.)

(file #36281)

Additional Item Attachment:

File name: ax_pthread-draft3.m4           Size:17 KB


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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