A couple of platform compatibility issues...

Richard Lightman richard at nezumi.plus.com
Sun Jan 5 09:23:50 PST 2003

* Greg Schafer <gschafer at zip.com.au> [2003-01-05 11:44]:
> On a side note, I note that some people (Debian for instance) go out of
> their way to compile all their shared libs with -D_REENTRANT. I always
> thought -D_REENTRANT was related to threading. What are your thoughts on
> that? 
>From the documentation, it looks like _REENTRANT used to do more, but
the extra functions it used to enable are now standard, so they no
longer depend on a feature test. The only thing left in glibc is
getlogin_r (from unistd.h) is only declared if _REENTRANT (or its
synonim _THREAD_SAFE) is defined.

The only other header files I have that use _REENTRANT are:
lwp:     Changes the LSB of the verion number, so this could affect
         run time behaviour.
libxml2: Tests for _REENTRANT in some code that is forgotten inside a
         #if 0
python:  defines _REENTRANT. This will not do any good if you included
         unistd.h first.

Defining _REENTRANT is unlikely to do any harm, and also unlikely
to do any good - unless you are getting warnings like getlogin_r
is used without a protoype or getlogin_r defined twice.

> I'm sure I read somewhere that pretty much all GNU software should be
> compiled with -D_GNU_SOURCE. I think I even did some investigations and
> noted that only a few of the source files in findutils define _GNU_SOURCE.
> So again, no objections from me.
The feature test macros like _GNU_SOURCE change the default behaviour
when a signall arrives during a system call. See:
info '(libc)Interrupted Primitives'

For this reason we should only be setting _GNU_SOURCE if the source
code expects that the default behaviour for an interrupted system
call is to retry.

_GNU_SOURCE adds extra (non-standard) features to the library. If you
use these features, you must ensure that _GNU_SOURCE is defined before
any system header is loaded. The documentation for glibc-2.2.5
recommends defining the macro at the head of each source file. This is
totally impractical because flex generates includes for system headers
before any of your code. Older versions of the glibc documents gave
dire warnings of subtle erratic bugs if you defined _GNU_SOURCE

If you are going to use _GNU_SOURCE in your own software , it should
be on the preprocessor command line either as -D_GNU_SOURCE, or
-include some_config_file_that_defines_GNU_SOURCE.h

For other people's software, I recommend you leave it alone unless
it is broken.


Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-dev' in the subject header of the message

More information about the lfs-dev mailing list