Closed Bug 17040 Opened 25 years ago Closed 25 years ago

Environment (i.e., _XXX_SOURCE) macro defines for Linux

Categories

(NSPR :: NSPR, defect, P3)

All
Linux
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: wtc)

Details

Attachments

(3 files)

On Linux, we are compiling with -D_POSIX_SOURCE
-D_BSD_SOURCE on all architectures, and on alpha,
ppc, and x86 architectures we also compile with
-D_XOPEN_SOURCE.

It isn't clear whether we need all these _XXX_SOURCE
macro defines or whether there is a better way to
specify the desired environment.  My experiment on
x86 shows that we need -D_XOPEN_SOURCE -D_BSD_SOURCE.
_XOPEN_SOURCE is needed for a lot of things, e.g.,
System V IPC.  _BSD_SOURCE is needed for strcasecmp,
strdup, caddr_t, etc.

Also, I think we should compile with -D_XOPEN_SOURCE
on all architectures, because these macros are
independent of the processor architecture.
Is there a specific reason you need _XOPEN_SOURCE?

Looking at <features.h> under glibc shows:
#if (!defined __STRICT_ANSI__ && !defined _ISOC9X_SOURCE && \
     !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE && \
     !defined _XOPEN_SOURCE && !defined _XOPEN_SOURCE_EXTENDED && \
     !defined _BSD_SOURCE && !defined _SVID_SOURCE)
# define _BSD_SOURCE    1
# define _SVID_SOURCE   1
#endif

Looking at libc5's <feature.h> shows:
#if (!defined(__STRICT_ANSI__) && !defined(_POSIX_SOURCE) && \
     !defined(_POSIX_C_SOURCE) && !defined(_BSD_SOURCE) && \
     !defined(_SVID_SOURCE))
#define _BSD_SOURCE     1
#define _SVID_SOURCE    1
#endif
A grep of the libc5 headers indicates that libc5 seems to know nothing about
_XOPEN_SOURCE.

Given the above, if you do not specify any _XXX_SOURCE flags, _BSD_SOURCE &
_SVID_SOURCE will be defined by default.  Glibc's <sys/ipc.h> looks like it'll
take either _XOPEN_SOURCE or _SVID_SOURCE.
We use the -ansi flag, which defines __STRICT_ANSI__.
This prevents glibc's <features.h> or libc5's <feature.h>
from being defined.

Your patch (id 2351, removing all -D_XXX_SOURCE) doesn't
work on a Red Hat 6.0 system, under the classic (non-autoconf)
build system.  If I also remove -ansi, then it works.
I guess you are not compiling with -ansi?  This reminds me of
your patch for mozilla/nsprpub/pr/include/prinet.h (revision 3.7)
to define __STRICT_ANSI__ in that header file, which is
another evidence that Mozilla is not compiled with -ansi.

Does this mean we don't need -ansi?
I wrote:
> We use the -ansi flag, which defines __STRICT_ANSI__.
> This prevents glibc's <features.h> or libc5's <feature.h>
> from being defined.

This should read:
  We use the -ansi flag, which defines __STRICT_ANSI__.
  This prevents glibc's <features.h> or libc5's <feature.h>
  from defining _BSD_SOURCE and _SVID_SOURCE.
Ah, yes, I missed that.  Mozilla will not compile (under RH6.0 Linux at least)
with -D__STRICT_ANSI__ so Mozilla does not need -ansi.  However, I do not know
about the server side of things that also use NSPR.  If -ansi is not required,
then I guess the choice of patches boils down to whether you want to force the
use of a certain header/API subset by using -ansi -D_XXX_SOURCE or just use
whatever's available by not setting any of those flags.
Status: NEW → ASSIGNED
Is there anything on the server side to prevent us from just removing the -ansi
flag and the extra _XXX_SOURCE defines?  The Ports Linux/arm tinderboxes are
still breaking on this.
This has nothing to do with the server side of things.
(Client and server use the same NSPR on Linux.)  It's
just that I feel extremely uncomfortable about not
using the -ansi flag.

So, given that I *want* to use -ansi, the _XXX_SOURCE
macros required for the compilation of NSPR are:
- _POSIX_SOURCE
- _BSD_SOURCE
- _SVID_SOURCE or _XOPEN_SOURCE

Since libc5 knows nothing about _XOPEN_SOURCE, I
will use _SVID_SOURCE instead.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
The patch (attachment id=3167) is checked in.
/cvsroot/mozilla/nsprpub/config/Linux.mk, revision 3.15

It's also checked into the internal repository.
/m/src/ns/nspr20/config/Linux.mk, revision 2.21
I agree that -ansi should not be removed.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: