Horrible GCC 4.7.0 optimizer bug
Sedat Dilek
sedat.dilek at googlemail.com
Fri Apr 13 20:53:43 UTC 2012
Issue fixed in upstream and gcc-4_7-branch GIT branch.
Patches [4] and [5] are from gcc-4_7-branch GIT.
( ChangeLog part should be dropped if applied against vanilla gcc-4.7.0 )
- Sedat -
[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52734#c16
[2] http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f7241737d3c074000cf3834b8f12c75bc3a3e8c0
[3] http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=c68bd46083d86464113b032f900387e92ddb4955
[4] http://freetz.org/attachment/ticket/1752/pr52734.patch
[5] http://freetz.org/attachment/ticket/1752/pr52734-testsuite.patch
On Wed, Apr 11, 2012 at 9:16 PM, Sedat Dilek <sedat.dilek at googlemail.com> wrote:
> Just FYI: The Freetz project had success with a backport of the
> tentative patch attached to GCC bug #52734 on MIPS.
>
> - Sedat -
>
> [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52734
>
> On Tue, Mar 27, 2012 at 7:25 AM, Michael Deutschmann
> <michael at talamasca.ocis.net> wrote:
>> Thought I should give you guys a warning. GCC 4.7.0 miscompiles uClibc
>> 0.9.33 really badly; almost every significant program segfaults quickly.
>> I've traced down the problem and it is definitely a GCC bug; the uClibc
>> source isn't doing anything wrong.
>>
>> The problem rests in sbrk(). GCC misoptimizes:
>>> oldbrk = __curbrk;
>>> if (brk (oldbrk + increment) < 0)
>>> return (void *) -1;
>>> return oldbrk;
>>
>> into:
>>> if (brk (__curbrk + increment) < 0)
>>> return (void *) -1;
>>> return __curbrk;
>>
>> Since brk() alters __curbrk, the result is a dysfunctional malloc
>> subsystem.
>>
>> Adding a volatile tag to __curbrk (remember to make it "void *
>> volatile", not "volatile void *") supresses the problem. Although it
>> does make me nervous to have an optimizer problem this bad in my
>> compiler...
>>
>> I've checked, and none of the magical things uClibc does
>> with __attribute__ are necessary for the bug to appear. I've reported a
>> simplified case to GCC's bug tracker as #52734.
>>
>> ---- Michael Deutschmann <michael at talamasca.ocis.net>
>> _______________________________________________
>> uClibc mailing list
>> uClibc at uclibc.org
>> http://lists.busybox.net/mailman/listinfo/uclibc
More information about the uClibc
mailing list