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: Richard Guenther <rguenther at suse dot de>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: Andreas Jaeger <aj at suse dot com>, libc-alpha at sourceware dot org
- Date: Thu, 26 Apr 2012 15:31:35 +0200 (CEST)
- Subject: Re: Fix tst-obprintf - and mcheck in general
- References: <201204261453.08679.aj@suse.com> <20120426131538.GK27852@redhat.com>
On Thu, 26 Apr 2012, Marek Polacek wrote:
> 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.
Consider people LD_PRELOADing tcmalloc or so. Not sure if it makes sense
to use mcheck.c then, of course ..
Richard.
--
Richard Guenther <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer