This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix libiberty issues using IBM's xlc compiler


A colleague recently pointed out that GCC fails to bootstrap hosted
from IBM's native xlc compiler, though builds fine hosted from gcc.
This is the first in a series of patches to resolve this problem.

It turns out that IBM's VisualAge compiler is picky about redefining
macros to different values without undefining them first.  This trips
up libiberty where config.h wants to define "inline" to be __inline
but ansidecl.h wants to define inline as nothing.  This is only a
problem if "ansidecl.h" is included before "config.h", as the former
includes the necessary "#undef", but the latter doesn't.  Currently,
there's a mixture of include orders in libiberty, with most of the
files compiling fine, but a handful causing problems.

Given that #undef'ing macros prior to defining them in config.h involves
more autoconf/configure hackery than I posses, I propose to resolve the
issue by always including "config.h" first in libiberty's source files.

The final remaining problem building libiberty on AIX is caused by the
way regex.c recursively #includes itself.  In this case, including
config.h again in the recursive invocation results in a similar error
(as inline will have been incompatibly redefined by ansidecl.h).  The
easiest way to fix this is to ensure that config.h is only included
once.


The following patch has been tested on powerpc-ibm-aix5.2.0.0 using
"CC=/usr/bin/xlc configure", where a bootstrap now proceeds past the
build of libiberty.  It's also been tested on i686-pc-linux-gnu with
a full "make bootstrap", all default languages, and a top-level "make
-k check" with no new failures.


Ok for mainline?  I don't have write access to src, so someone may
need to apply/synchronize this there.  If approved, I'll prepare a
similar patch for review to fix the gcc-3_4-branch.


2004-11-19  Roger Sayle  <roger@eyesopen.com>

	* objalloc.c, strsignal.c, xstrerror.c: Include "config.h" before
	"ansidecl.h" to avoid redeclaration errors with native compilers.
	* regex.c: Protect config.h from multiple inclusion.

Index: objalloc.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/objalloc.c,v
retrieving revision 1.5
diff -c -3 -p -r1.5 objalloc.c
*** objalloc.c	29 May 2000 19:33:52 -0000	1.5
--- objalloc.c	19 Nov 2004 00:53:07 -0000
*************** along with this program; if not, write t
*** 17,24 ****
  Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */

- #include "ansidecl.h"
  #include "config.h"

  #include "objalloc.h"

--- 17,24 ----
  Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */

  #include "config.h"
+ #include "ansidecl.h"

  #include "objalloc.h"

Index: regex.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/regex.c,v
retrieving revision 1.15
diff -c -3 -p -r1.15 regex.c
*** regex.c	17 Feb 2004 01:59:42 -0000	1.15
--- regex.c	19 Nov 2004 00:53:11 -0000
***************
*** 32,39 ****
  #undef	_GNU_SOURCE
  #define _GNU_SOURCE

! #ifdef HAVE_CONFIG_H
! # include <config.h>
  #endif

  #include <ansidecl.h>
--- 32,41 ----
  #undef	_GNU_SOURCE
  #define _GNU_SOURCE

! #ifndef INSIDE_RECURSION
! # ifdef HAVE_CONFIG_H
! #  include <config.h>
! # endif
  #endif

  #include <ansidecl.h>
Index: strsignal.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/strsignal.c,v
retrieving revision 1.11
diff -c -3 -p -r1.11 strsignal.c
*** strsignal.c	15 Apr 2003 20:36:33 -0000	1.11
--- strsignal.c	19 Nov 2004 00:53:12 -0000
***************
*** 2,12 ****
     Written by Fred Fish.  fnf@cygnus.com
     This file is in the public domain.  */

  #include "ansidecl.h"
  #include "libiberty.h"

- #include "config.h"
-
  /* We need to declare sys_siglist, because even if the system provides
     it we can't assume that it is declared in <signal.h> (for example,
     SunOS provides sys_siglist, but it does not declare it in any
--- 2,11 ----
     Written by Fred Fish.  fnf@cygnus.com
     This file is in the public domain.  */

+ #include "config.h"
  #include "ansidecl.h"
  #include "libiberty.h"

  /* We need to declare sys_siglist, because even if the system provides
     it we can't assume that it is declared in <signal.h> (for example,
     SunOS provides sys_siglist, but it does not declare it in any
Index: xstrerror.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xstrerror.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 xstrerror.c
*** xstrerror.c	7 Oct 2001 21:53:31 -0000	1.4
--- xstrerror.c	19 Nov 2004 00:53:13 -0000
*************** will never return a @code{NULL} pointer.
*** 15,22 ****

  #include <stdio.h>

- #include "libiberty.h"
  #include "config.h"

  #ifdef VMS
  #include <errno.h>
--- 15,22 ----

  #include <stdio.h>

  #include "config.h"
+ #include "libiberty.h"

  #ifdef VMS
  #include <errno.h>

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]