On dropping -D_REENTRANT -D_THREAD_SAFE

Simon Josefsson simon at josefsson.org
Fri Jan 4 17:54:08 CET 2008


For a long time configure.in has contained:

dnl In order to use the reentrant libc functions.
dnl I hope it is portable enough.
CFLAGS="${CFLAGS} -D_REENTRANT -D_THREAD_SAFE"
AM_CFLAGS="${CFLAGS}"

The problem with this is that disabling the default -O2 from builds,
which is typically done with 'make CFLAGS=-g', doesn't work.  I think we
could fix that problem by using:

CFLAGS="${CFLAGS} -D_REENTRANT -D_THREAD_SAFE"
AM_CFLAGS="${AM_CFLAGS} -D_REENTRANT -D_THREAD_SAFE"

But then I started to investigate why we need -D_REENTRANT
-D_THREAD_SAFE at all.  Glibc manual says:

 -- Macro: _REENTRANT
 -- Macro: _THREAD_SAFE
     If you define one of these macros, reentrant versions of several
     functions get declared.  Some of the functions are specified in
     POSIX.1c but many others are only available on a few other systems
     or are unique to GNU libc.  The problem is the delay in the
     standardization of the thread safe C library interface.

     Unlike on some other systems, no special version of the C library
     must be used for linking.  There is only one version but while
     compiling this it must have been specified to compile as thread
     safe.

Glibc features.h says:

...
   _GNU_SOURCE		All of the above, plus GNU extensions.
   _REENTRANT		Select additionally reentrant object.
   _THREAD_SAFE		Same as _REENTRANT, often used by other systems.
...

However, grepping for _REENTRANT in /usr/include/* on my systems reveals
that it is only used for 'getlogin_r', which we aren't using anyway.

My conclusion is that -D_REENTRANT -D_THREAD_SAFE is not needed on glibc
systems.  Does anyone know of other systems that needs these defines to
work properly?

I'm inclined to remove the lines from configure.in.  If some other
system needs this to have working standard C/POSIX functions, we could
solve it via a gnulib module, I suppose.

Thoughts?

/Simon





More information about the Gnutls-devel mailing list