[PATCH] Make --enable-gather-detailed-mem-stats compatible with PCH
Laurynas Biveinis
laurynas.biveinis@gmail.com
Tue May 25 06:56:00 GMT 2010
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?
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
More information about the Gcc-patches
mailing list