This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [PATCH] Make --enable-gather-detailed-mem-stats compatible with PCH


On Tue, May 25, 2010 at 7:22 AM, Laurynas Biveinis
<laurynas.biveinis@gmail.com> wrote:
> Sometimes in the presence of PCH, -fmem-report makes gcc crash with
> NULL dereference. The problem is that the hash table ptr_hash where
> all the GC-allocated pointers are registered is cleared on PCH read.
> Thus the following sequence makes it crash:
> 1) pointer = ggc_alloc (...); pointer is put into the ptr_hash
> 2) PCH read, ptr_hash is cleared
> 3) ggc_free (pointer); pointer is looked up in the ptr_hash, boom.
>
> A complete fix would be to account lifetime of such pointers properly,
> but for now just accept that ptr_hash might not always find the
> pointer we are looking for.
>
> Bootstrapped/regtested on x86_64-linux with the rest of gc-improv, OK for trunk?

Ok.

Thanks,
Richard.

> 2010-05-24 ?Laurynas Biveinis ?<laurynas.biveinis@gmail.com>
>
> ? ? ? ?* ggc-common.c (ggc_free_overhead): Allow empty slot.
>
> diff -r -u -x .svn gcc-trunk/gcc/gcc/ggc-common.c
> gcc-gc-improv/gcc/gcc/ggc-common.c
> --- gcc-trunk/gcc/gcc/ggc-common.c ? ? ?2010-04-20 09:03:29.000000000 +0200
> +++ gcc-gc-improv/gcc/gcc/ggc-common.c ?2010-05-24 14:03:46.000000000 +0200
> @@ -980,7 +994,13 @@
> ?{
> ? PTR *slot = htab_find_slot_with_hash (ptr_hash, ptr, htab_hash_pointer (ptr),
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NO_INSERT);
> - ?struct ptr_hash_entry *p = (struct ptr_hash_entry *) *slot;
> + ?struct ptr_hash_entry *p;
> + ?/* The pointer might be not found if a PCH read happened between allocation
> + ? ? and ggc_free () call. ?FIXME: account memory properly in the presence of
> + ? ? PCH. */
> + ?if (!slot)
> + ? ? ?return;
> + ?p = (struct ptr_hash_entry *) *slot;
> ? p->loc->freed += p->size;
> ? htab_clear_slot (ptr_hash, slot);
> ? free (p);
>
> --
> Laurynas
>


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