This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR47566
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: rguenther at suse dot de (Richard Guenther)
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 22 Jul 2011 16:42:01 +0200 (CEST)
- Subject: Re: [PATCH] Fix PR47566
Richard Guenther wrote:
> On Fri, 22 Jul 2011, Ulrich Weigand wrote:
> > Now that we have the linker plugin, this fails on spu-elf with:
> >
> > /tmp/cce6KuRb.ltrans0.ltrans.o: In function `foo':
> > cce6KuRb.ltrans0.o:(.text+0x28): undefined reference to `sqrt'
> >
> > because nothing links against libm. I'm a bit confused by the comment
> > above: even with the linker plugin, where should libm be pulled in?
> > Don't we need to use -lm on the linker line anyway?
>
> Well, the testcase was for an ICE which required that cabs is folded
> to sqrt(real**2 + imag**2), it requires "late" folding, thus
> -O0 during the compile step (it's a trick to use LTO here, to delay
> folding until after IPA opts). Not linking with -lm and relying
> on a HW sqrt instruction makes sure we do that late folding
> which we want to happen.
>
> So, if you can in any way retain all of the above features with
> fixing non-HW sqrt targets fine - otherwise I suggest you skip spu-elf.
Well, it works for me with just adding -lm to the dg-extra-ld-options.
This still folds cabs to sqrt in the LTO step, and then satisfies that
call via the libm routine ... If I understood your intent correctly,
this should still test the same thing, shouldn't it?
Bye,
Ulrich
ChangeLog:
* testsuite/gcc.dg/lto/20110201-1_0.c: Add -lm to dg-extra-ld-options.
Update comment.
Index: gcc/testsuite/gcc.dg/lto/20110201-1_0.c
===================================================================
*** gcc/testsuite/gcc.dg/lto/20110201-1_0.c (revision 176572)
--- gcc/testsuite/gcc.dg/lto/20110201-1_0.c (working copy)
***************
*** 1,12 ****
/* { dg-lto-do run } */
/* { dg-lto-options { { -O0 -flto } } } */
! /* { dg-extra-ld-options "-O2 -ffast-math -fuse-linker-plugin" } */
/* { dg-require-linker-plugin "" } */
! /* We require a linker plugin because otherwise we'd need to link
! against libm which we are not sure here has cabs on all targets.
! This is because collect2 invokes ld on the -O0 object code
! which does not have folded cabs. */
double cabs(_Complex double);
double __attribute__((used))
--- 1,14 ----
/* { dg-lto-do run } */
/* { dg-lto-options { { -O0 -flto } } } */
! /* { dg-extra-ld-options "-O2 -ffast-math -fuse-linker-plugin -lm" } */
/* { dg-require-linker-plugin "" } */
! /* Since we compile with -O0, the object code will have a reference
! to cabs. The LTO link step will then fold this to either a call
! to sqrt or a hardware square-root instruction. We require the
! linker plugin because otherwise a reference to cabs might remain
! in the final output, which is not present on all targets. We
! still link against libm in case it is needed for sqrt. */
double cabs(_Complex double);
double __attribute__((used))
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com