This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fix tst-obprintf - and mcheck in general
- From: Marek Polacek <polacek at redhat dot com>
- To: Andreas Jaeger <aj at suse dot com>
- Cc: libc-alpha at sourceware dot org, Richard Guenther <rguenther at suse dot de>
- Date: Thu, 26 Apr 2012 15:15:38 +0200
- Subject: Re: Fix tst-obprintf - and mcheck in general
- References: <201204261453.08679.aj@suse.com>
On Thu, Apr 26, 2012 at 02:53:07PM +0200, Andreas Jaeger wrote:
> Richard and myself analyzed the tst-obprintf failure with GCC 4.7.
>
> It turned out that this is the fault of GCC optimizing away the following
> from malloc/mcheck.c:
> /* We call malloc() once here to ensure it is initialized. */
> void *p = malloc (0);
> free (p);
>
> gcc sees the malloc(0);free pair and removes it completely.
>
> And now malloc is not properly initialized and we screw up if both mcheck
> is used (via tst-obprintf) and MALLOC_CHECK_ is set (as it is in my
> environment).
>
> One option is to compile with -fno-builtin-malloc, the alternative would be
> to use some otherways to initialize the malloc implementation.
Perhaps we could call e.g. malloc_get_state ();. That shouldn't be optimized
away and calls ptmalloc_init. Not sure what's better though.
Marek