This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix tst-obprintf - and mcheck in general


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.

Here's a patch for the first option. Tested on x86-64 with GCC 4.7.

Ok to commit?

Andreas

2012-04-26  Andreas Jaeger  <aj@suse.de>,
	Richard Guenther <rguenther@suse.de>

	* malloc/Makefile (CFLAGS-mcheck.c): Set it so that malloc(0);free
	is not optimized out.

diff --git a/malloc/Makefile b/malloc/Makefile
index 5d6d716..92f8bc1 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -50,6 +50,7 @@ aux := set-freeres thread-freeres
 include ../Makeconfig
 
 CPPFLAGS-memusagestat = -DNOT_IN_libc
+CFLAGS-mcheck.c = -fno-builtin-malloc
 
 # The Perl script to analyze the output of the mtrace functions.
 ifneq ($(PERL),no)

Andreas
-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]