Fix tst-obprintf - and mcheck in general

Andreas Jaeger aj@suse.com
Thu May 3 19:07:00 GMT 2012


On 05/03/2012 08:41 PM, Roland McGrath wrote:
>> +#define malloc_opt_barrier(x) \
>> +({ __typeof (x) __x = x; __asm ("" : "+m" (__x)); __x; })
>
> This needs a comment.

Like this?

Andreas

diff --git a/malloc/mcheck.c b/malloc/mcheck.c
index 9213740..9d8a414 100644
--- a/malloc/mcheck.c
+++ b/malloc/mcheck.c
@@ -370,6 +370,10 @@ mabort (enum mcheck_status status)
  #endif
  }

+/* Memory barrier so that GCC does not optimize out the argument.  */
+#define malloc_opt_barrier(x) \
+({ __typeof (x) __x = x; __asm ("" : "+m" (__x)); __x; })
+
  int
  mcheck (func)
       void (*func) (enum mcheck_status);
@@ -381,6 +385,8 @@ mcheck (func)
      {
        /* We call malloc() once here to ensure it is initialized.  */
        void *p = malloc (0);
+      /* GCC might optimize out the malloc/free pair without a barrier.  */
+      p = malloc_opt_barrier (p);
        free (p);

        old_free_hook = __free_hook;

-- 
  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



More information about the Libc-alpha mailing list