[patch] PR22097: libgfortran build failure on mips-sgi-irix6.5

Roger Sayle roger@eyesopen.com
Tue Feb 7 15:29:00 GMT 2006


On Tue, 7 Feb 2006, Rainer Emrich wrote:
> There is one open question. Is the "#ifdef __sgi__" the right way to
> distinguish between IRIX and other mips systems?
> ...
> +#ifdef __sgi__
> +#ifndef HAVE_COMPLEX_H
> +#undef HAVE_CABS
> +#undef HAVE_CABSF
> +#undef HAVE_CABSL
> +#define cabs __gfc_cabs
> +#define cabsf __gfc_cabsf
> +#define cabsl __gfc_cabsl
> +#endif /* HAVE_COMPLEX_H */
> +#endif /* __sgi__ */


If it's any help to the libgfortran maintainers, I believe that this
is the correct way to fix PR22097.  The issue is that old versions of
IRIX defined "cabs" the same way that Tru64 did, as a function taking
two arguments.  After IRIX 6.5.18 (or with more recent MIPSPro
compilers?), the header files were fixed such that defining __c99
used the new posix definitions.  libgfortran compiles with -std=gnu99,
so on relatively up to date IRIX boxes (such as mine), things build
fine.

The transition can be detected, as above, by the presence of complex.h.
>From the current IRIX "cabs(3m)" man page:

     The c89 library also had functions cabs, cabsf, and cabsl with the
     following prototypes:

          double cabs (struct {double a,b; } z);
          float cabsf (struct {float a,b; } z);
          long double cabs (struct {long double a,b; } z);

     In order to preserve forward compatability of these functions, it is
     possible to use either the c89 or the c99 definitions of the cabs
     functions simply by including <complex.h> for the c99 versions (and
     compiling with the -c99 option) or by including <math.h> for the c89
     versions (and compiling without -c99). If possible, change to the c99
     versons of these functions by changing the source code and
     recompiling. The functionality is the same as in the c89 version.


This explains why Rainer has a bootstrap failure, whilst I can
bootstrap fine but all the libgfortran regression tests fail due to
(soon to be resolved) TImode issues.

I believe that __sgi__ is the correct macro to test, to identify
IRIX systems, and even if its defined by the deprecated SGI Linux
systems, they should have /usr/include/complex.h (or use SGI's
C library headers with would have identical issues).


The remaining question is whether the libgfortran maintainers are
happy with the style of this patch.  For example, it could be
simplified to

#if defined(__sgi__) && !defined(HAVE_COMPLEX_H)

and maybe even combined with the Tru64 test to reduce code:

#if defined(__osf__) || (defined(__sgi__) && !defined(HAVE_COMPLEX_H))


FYI, just for the record Tru64 doesn't define HAVE_COMPLEX_H, not that
it should matter.

Rainer, you also need to provide a ChangeLog entry for your patch
submissions, perhaps something like:


2006-02-07  Rainer Emrich <r.emrich@de.tecosim.com>

	* intrinsics/c99_functions.c: Work around incompatible
	declarations of cabs{,f,l} on pre-C99 IRIX systems.


One final possibility, perhaps a follow-up patch, is to instead test
this using autoconf, to define the macro HAVE_BROKEN_CABS, if there
are compilation failures trying to call "cabs" with a single complex
argument.  Unfortunately, I don't speak autoconf (or I'd fix the
libgomp bootstrap failure on Tru64 myself).  Perhaps I should offer
to return a middle-end failure to anyone who can help with configure?

In the meantime, Rainer's patch (with ot without the refinements
suggested above) should get him back to bootstrap land, but the
decision rests with the libgfortran folks.

Roger
--



More information about the Gcc-patches mailing list