This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Avoiding compiler-induced infinite recursion in memset w/ GCC 4.8?
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Brooks Moses <bmoses at google dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 16 Jul 2013 17:33:25 -0400
- Subject: Re: Avoiding compiler-induced infinite recursion in memset w/ GCC 4.8?
- References: <CAOxa4KpCdYu=z1rpSo-NcUw8jNjcC8L=Yf-UDn8m2WyGfTgQ5g at mail dot gmail dot com>
On 07/16/2013 05:23 PM, Brooks Moses wrote:
> Hey, all -
>
> I ran into an issue with building EGLIBC 2.17 with GCC 4.8 -- it looks
> like GCC is recognizing the cleanup loop at the end of string/memset.c
> as something it can replace with a call to memset, and so we get an
> infinite recursive loop.
>
> Is there an already-existing solution to this problem? I'd be
> surprised if I'm the first person to run into this, but I can't
> immediately find any references to it by searching. From what I can
> see in string/Makefile, we only add -fno-builtin to test files.
>
> Presumably we need to compile memset with -fno-builtin somehow -- and
> if this is solved in a current GLIBC, I need to backport it to our
> EGLIBC branch.
>
> (In my case, one exacerbating factor is that I'm building for
> powerpc64, and the memset there is defined in
> sysdeps/powerpc/powerpc64/rtld-memset.c, which #includes
> string/memset.c, but may not have the same flags applied or
> something.)
This is already resolved in master.
There was a long discussion about *how* this should be fixed, but
we eventually settled on the two following fixes.
commit 85c2e6110c9a01ec817c30f1b7e20549d7229987
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date: Thu Jun 20 19:40:55 2013 -0500
Fix loop construction to functions calls
Check wheter the compiler has the option -fno-tree-loop-distribute-patterns
to inhibit loop transformation to library calls and uses it on memset
and memmove default implementation to avoid recursive calls.
commit 6a97b62a5b4f18aea849d6f4d8de58d1469d2521
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date: Wed Jun 12 10:21:22 2013 -0500
Fix unsafe compiler optimization
GCC 4.8 enables -ftree-loop-distribute-patterns at -O3 by default and
this optimization may transform loops into memset/memmove calls. Without
proper handling this may generate unexpected PLT calls on GLIBC.
This patch fixes by create memset/memmove alias to internal GLIBC
__GI_memset/__GI_memmove symbols.
Cheers,
Carlos.