glibc-2.5 build with -Os broken on PowerPC

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

glibc-2.5 build with -Os broken on PowerPC

Przemyslaw Iskra
Hello.

glibc 2.5 does not compile on PowerPC with -Os. It fails on:
 sysdeps/powerpc/fpu/e_sqrt.c
and
 sysdeps/powerpc/fpu/e_sqrtf.c
because of undefined reference to __CPU_HAS_FSQRT.

This is because __CPU_HAS_FSQRT is defined in mathinline.h, which is not
included if glibc is built with -Os optimization (and shouldn't be).

My fix/hack was to force mathinline.h inclusion in e_sqrt(f).c files:
http://cvs.pld-linux.org/cgi-bin/cvsweb/SOURCES/glibc-ppc-include-mathinline.patch?rev=1.1
but I've been told it isn't a good idea.

Probably __CPU_HAS_FSQRT definitions should be moved somewere else, but
I see no good place for it.

--
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ........... LANG...Pl..Ca..Es..En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : JID......sparky<at>jabberes.org
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| : Mail....sparky<at>pld-linux.org
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Steve Munroe


[hidden email] wrote on 11/02/2006 11:24:43 AM:

> Hello.
>
> glibc 2.5 does not compile on PowerPC with -Os. It fails on:
>  sysdeps/powerpc/fpu/e_sqrt.c
> and
>  sysdeps/powerpc/fpu/e_sqrtf.c
> because of undefined reference to __CPU_HAS_FSQRT.
>
> This is because __CPU_HAS_FSQRT is defined in mathinline.h, which is not
> included if glibc is built with -Os optimization (and shouldn't be).
>
> My fix/hack was to force mathinline.h inclusion in e_sqrt(f).c files:
> http://cvs.pld-linux.org/cgi-bin/cvsweb/SOURCES/glibc-ppc-include-
> mathinline.patch?rev=1.1
> but I've been told it isn't a good idea.
>
> Probably __CPU_HAS_FSQRT definitions should be moved somewere else, but
> I see no good place for it.
>

Builds for me with -O2 (libc default) so which gcc version are you using
and which day did you pull glibc? And what configure options?

Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center

Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Przemyslaw Iskra
In reply to this post by Przemyslaw Iskra
On Thu, Nov 02, 2006 at 11:42:37AM -0600, Steve Munroe wrote:

>
>
> [hidden email] wrote on 11/02/2006 11:24:43 AM:
>
> > Hello.
> >
> > glibc 2.5 does not compile on PowerPC with -Os. It fails on:
> >  sysdeps/powerpc/fpu/e_sqrt.c
> > and
> >  sysdeps/powerpc/fpu/e_sqrtf.c
> > because of undefined reference to __CPU_HAS_FSQRT.
> >
> > This is because __CPU_HAS_FSQRT is defined in mathinline.h, which is not
> > included if glibc is built with -Os optimization (and shouldn't be).
> >
> > My fix/hack was to force mathinline.h inclusion in e_sqrt(f).c files:
> > http://cvs.pld-linux.org/cgi-bin/cvsweb/SOURCES/glibc-ppc-include-
> > mathinline.patch?rev=1.1
> > but I've been told it isn't a good idea.
> >
> > Probably __CPU_HAS_FSQRT definitions should be moved somewere else, but
> > I see no good place for it.
> >
>
> Builds for me with -O2 (libc default) so which gcc version are you using
> and which day did you pull glibc? And what configure options?

With -O2 builds for me too, but, as I said the __CPU_HAS_FSQRT
definition is in bits/mathinline.h. It is included from math.h:

/* Get machine-dependent inline versions (if there are any).  */
#ifdef __USE_EXTERN_INLINES
# include <bits/mathinline.h>
#endif


And __USE_EXTERN_INLINES is defined in features.h as:

/* Decide whether we can define 'extern inline' functions in headers.
 * */
#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
    && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__
# define __USE_EXTERN_INLINES   1
#endif


So, if __OPTIMIZE_SIZE__ is enabled (defined by compiler when building
with -Os) mathinline.h file is not included.


I'm trying to compile glibc 2.5 from
ftp://sources.redhat.com/pub/glibc/releases/
and my gcc is some 4.1.2 snapshot

--
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ........... LANG...Pl..Ca..Es..En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : JID......sparky<at>jabberes.org
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| : Mail....sparky<at>pld-linux.org
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Przemyslaw Iskra
On Thu, Nov 02, 2006 at 07:08:49PM +0100, [hidden email] wrote:

> > > glibc 2.5 does not compile on PowerPC with -Os. It fails on:
> > >  sysdeps/powerpc/fpu/e_sqrt.c
> > > and
> > >  sysdeps/powerpc/fpu/e_sqrtf.c
> > > because of undefined reference to __CPU_HAS_FSQRT.

Maybe attached patch would be a suitable solution. It simply does not
include that code if __CPU_HAS_FSQRT is not defined.

--
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ........... LANG...Pl..Ca..Es..En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : JID......sparky<at>jabberes.org
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| : Mail....sparky<at>pld-linux.org

glibc-ppc-optimize-for-size.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Jakub Jelinek
On Fri, Nov 03, 2006 at 12:28:39PM +0100, [hidden email] wrote:

> On Thu, Nov 02, 2006 at 07:08:49PM +0100, [hidden email] wrote:
>
> > > > glibc 2.5 does not compile on PowerPC with -Os. It fails on:
> > > >  sysdeps/powerpc/fpu/e_sqrt.c
> > > > and
> > > >  sysdeps/powerpc/fpu/e_sqrtf.c
> > > > because of undefined reference to __CPU_HAS_FSQRT.
>
> Maybe attached patch would be a suitable solution. It simply does not
> include that code if __CPU_HAS_FSQRT is not defined.

That should be better written as
#ifndef __CPU_HAS_FSQRT
# define __CPU_HAS_FSQRT 0
#endif
above the functions rather than cluttering the functions with #ifdefs.

> --- libc/sysdeps/powerpc/fpu/e_sqrt.c~ 2006-04-14 08:44:30.000000000 +0300
> +++ libc/sysdeps/powerpc/fpu/e_sqrt.c 2006-11-03 13:24:10.000000000 +0200
> @@ -169,6 +169,8 @@
>  {
>    double z;
>  
> +  /* If __CPU_HAS_FSQRT is not defined means we don't want optimization */
> +#ifdef __CPU_HAS_FSQRT
>    /* If the CPU is 64-bit we can use the optional FP instructions.  */
>    if (__CPU_HAS_FSQRT)
>      {
> @@ -178,6 +180,7 @@
>   :"=f" (z):"f" (x));
>      }
>    else
> +#endif
>      z = __slow_ieee754_sqrt (x);
>  
>    return z;
> --- libc/sysdeps/powerpc/fpu/e_sqrtf.c~ 2006-04-14 08:44:30.000000000 +0300
> +++ libc/sysdeps/powerpc/fpu/e_sqrtf.c 2006-11-03 13:24:57.000000000 +0200
> @@ -146,6 +146,8 @@
>  {
>    double z;
>  
> +  /* If __CPU_HAS_FSQRT is not defined means we don't want optimization */
> +#ifdef __CPU_HAS_FSQRT
>    /* If the CPU is 64-bit we can use the optional FP instructions.  */
>    if (__CPU_HAS_FSQRT)
>      {
> @@ -155,6 +157,7 @@
>   :"=f" (z):"f" (x));
>      }
>    else
> +#endif
>      z = __slow_ieee754_sqrtf (x);
>  
>    return z;


        Jakub
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Ulrich Drepper
The correct solution is to not have the libc-internal block of code in
the header in the first place.  Create a separate header and put it all
there.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Przemyslaw Iskra
On Fri, Nov 03, 2006 at 09:03:31AM -0800, Ulrich Drepper wrote:
> The correct solution is to not have the libc-internal block of code in
> the header in the first place.  Create a separate header and put it all
> there.

you mean # define __CPU_HAS_FSQRT something ?

It isn't internal-only definition. It is used in inline __ieee754_sqrt
function in bits/mathinline.h. That's why I don't know where to move
those definitions.


--
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ........... LANG...Pl..Ca..Es..En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : JID......sparky<at>jabberes.org
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| : Mail....sparky<at>pld-linux.org
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Ulrich Drepper
[hidden email] wrote:
> you mean # define __CPU_HAS_FSQRT something ?
>
> It isn't internal-only definition. It is used in inline __ieee754_sqrt

The code is protected by __LIBC_INTERNAL_MATH_INLINES which is only
defined inside glibc.  At least this is the intend.  Therefore all the
code inside the #ifdef can be moved in a separate header which is always
included when compiling glibc and not installed.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Steve Munroe
In reply to this post by Przemyslaw Iskra
[hidden email] wrote on 11/03/2006 11:35:29 AM:

> On Fri, Nov 03, 2006 at 09:03:31AM -0800, Ulrich Drepper wrote:
> > The correct solution is to not have the libc-internal block of code in
> > the header in the first place.  Create a separate header and put it all

> > there.
>
> you mean # define __CPU_HAS_FSQRT something ?
>
> It isn't internal-only definition. It is used in inline __ieee754_sqrt
> function in bits/mathinline.h. That's why I don't know where to move
> those definitions.
>

You really must explain what you are doing and what does not work. Because
is works for me as of libc from 10/18.

For example what configure options are you using?

This is complicated by the fact the not all PowerPC32 hardware implements
fsqrt. So the current implement for powerpc32 uses a guard based on
checking for PPC_FEATURE_64 in the AT_HWCAP (#define __CPU_HAS_FSQRT
((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0), fsqrt is implemented on all
64-bit processors).

So it is inappropriate to arbitrarily build fsqrt into libm for 32-bit
unless you have complete control over where the code will run (For example
powerpc_cpu add-on and --with-cpu=).

Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center

Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Mike Frysinger
On Friday 03 November 2006 16:20, Steve Munroe wrote:
> You really must explain what you are doing and what does not work. Because
> is works for me as of libc from 10/18.

i might be missing something but sparky says "building glibc with -Os fails"
while your replies have been "builds fine for me with -O2"
-mike

attachment0 (844 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Steve Munroe


Mike Frysinger <[hidden email]> wrote on 11/03/2006 03:25:14 PM:

> On Friday 03 November 2006 16:20, Steve Munroe wrote:
> > You really must explain what you are doing and what does not work.
Because
> > is works for me as of libc from 10/18.
>
> i might be missing something but sparky says "building glibc with -Os
fails"
> while your replies have been "builds fine for me with -O2"

Dang, I though he was making a generic statement and did realise there was
a -Os (optimized for size).

Not something I normally worry about ...

Building with CFLAGS="-Os" now.

Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center

Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Steve Munroe
In reply to this post by Ulrich Drepper
Ulrich Drepper <[hidden email]> wrote on 11/03/2006 11:41:53 AM:

> [hidden email] wrote:
> > you mean # define __CPU_HAS_FSQRT something ?
> >
> > It isn't internal-only definition. It is used in inline __ieee754_sqrt
>
> The code is protected by __LIBC_INTERNAL_MATH_INLINES which is only
> defined inside glibc.  At least this is the intend.  Therefore all the
> code inside the #ifdef can be moved in a separate header which is always
> included when compiling glibc and not installed.
>

Would it be appropriate to move this code into
libc/sysdeps/powerpc/fpu/math_private.h

then this math_private would tail include

#include_next <math_private.h>

Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center

Reply | Threaded
Open this post in threaded view
|

Re: glibc-2.5 build with -Os broken on PowerPC

Ulrich Drepper
Steve Munroe wrote:
> Would it be appropriate to move this code into
> libc/sysdeps/powerpc/fpu/math_private.h

It's one possibility, yes.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖