[Top][All Lists]

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

Re: -xc99=all and libraries on Solaris 10

From: Paul Eggert
Subject: Re: -xc99=all and libraries on Solaris 10
Date: Tue, 28 Dec 2010 00:40:50 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20101208 Thunderbird/3.1.7

On 12/27/2010 09:35 AM, Peter O'Gorman wrote:
> We patch our autoconf to not add -xc99=all to avoid the issue.

Looking at the Autoconf history, Autoconf uses -xc99=all rather than
plain -xc99 because plain -xc99 broke Forte Developer 7 C on Solaris 9:
the compiler assumed C99 semantics for library functions, but the library
didn't do that.  I can't remember what went exactly went wrong in that case
and no longer have access to a Solaris 9 box to try it out.  I don't think
that particular combination matters much, as nobody uses Forte Developer 7
any more.

On Oracle Solaris Studio 12.2's C compiler, plain -xc99 implies
-xc99=all, and omitting -xc99 entirely implies -xc99='all,no_lib'.
The "no_lib" behavior avoids the problem with __xpg4, but unfortunately
"no_lib" also breaks <stdbool.h>: when one uses no_lib (either
explicitly or implicitly) then the following program:

  #include <stdbool.h>
  int main (void) { return false; }

causes cc to complain:

  "/usr/include/stdbool.h", line 42: #error: "Use of <stdbool.h> is valid only 
in a c99 compilation environment."

which is silly pedanticism.  Programs that use gnulib's
stdbool module work around this problem by supplying their own
stdbool.h, but Autoconf shouldn't be assuming gnulib.

I looked into this a bit, and decided that the easiest way out is to
add -D_STDC_C99= to the command line (instead of -xc99=whatever).
This avoids -xc99's problem of changing the library semantics,
and supports C99 well enough so that Autoconf's test program passes,
which is probably good enough.

I pushed this into Autoconf.  Comments welcome.

>From 4e33814cce87f13873c7b9dd5a327fce4c98f2ca Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Mon, 27 Dec 2010 23:31:43 -0800
Subject: [PATCH] autoconf: Use -D_STDC_C99=, not -xc99=all, with Solaris cc

* lib/autoconf/c.m4 (_AC_PROG_CC_C99): Use -D_STDC_C99= rather than
-xc99=all to convince Solaris Studio cc to compile c99 programs.
 ChangeLog         |    6 ++++++
 lib/autoconf/c.m4 |   15 ++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c1ec95d..8c9b89f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-12-27  Paul Eggert  <address@hidden>
+       autoconf: Use -D_STDC_C99=, not -xc99=all, with Solaris cc
+       * lib/autoconf/c.m4 (_AC_PROG_CC_C99): Use -D_STDC_C99= rather than
+       -xc99=all to convince Solaris Studio cc to compile c99 programs.
 2010-11-26  Paul Eggert  <address@hidden>
        autotest: fix file descriptor leak
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index a873ccd..5479056 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1340,11 +1340,20 @@ dnl AIX         -qlanglvl=extc99 (unused restrictive 
mode: -qlanglvl=stdc99)
 dnl HP cc      -AC99
 dnl Intel ICC  -std=c99, -c99 (deprecated)
 dnl IRIX       -c99
-dnl Solaris    -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
-dnl            as it incorrectly assumes C99 semantics for library functions)
+dnl Solaris    -D_STDC_C99=
+dnl            cc's -xc99 option uses linker magic to define the external
+dnl            symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
+dnl            behavior for C library functions.  This is not wanted here,
+dnl            because it means that a single module compiled with -xc99
+dnl            alters C runtime behavior for the entire program, not for
+dnl            just the module.  Instead, define the (private) symbol
+dnl            _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
+dnl            The resulting compiler passes the test case here, and that's
+dnl            good enough.  For more, please see the thread starting at:
 dnl Tru64      -c99
 dnl with extended modes being tried first.
-[[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
+[[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99]], [$1], 
 ])# _AC_PROG_CC_C99

reply via email to

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