Horrible GCC 4.7.0 optimizer bug

Michael Deutschmann michael at talamasca.ocis.net
Tue Mar 27 05:25:55 UTC 2012


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>


More information about the uClibc mailing list