diff options
author | hp <hp@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-20 20:06:34 +0000 |
---|---|---|
committer | hp <hp@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-20 20:06:34 +0000 |
commit | dd359afe344feca5e4116da242bb70aff05f41b1 (patch) | |
tree | 875408dbc971a059d46c40bc2e97d990800c184a /gcc/ggc-common.c | |
parent | 0fa54ff10f530f6de61a405566b2b61c423ef0d8 (diff) | |
download | gcc-dd359afe344feca5e4116da242bb70aff05f41b1.tar.gz |
* ggc-common.c [!ENABLE_VALGRIND_CHECKING] (VALGRIND_DISCARD):
Define as empty.
(ggc_realloc): Update valgrind annotations.
* ggc-page.c [!ENABLE_VALGRIND_CHECKING] (VALGRIND_DISCARD):
Define as empty.
(alloc_anon, free_page, ggc_alloc, poison_pages): Add machinery to
valgrind-annotate memory.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59310 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ggc-common.c')
-rw-r--r-- | gcc/ggc-common.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c index 2674cec52a1..b0ebabc40ce 100644 --- a/gcc/ggc-common.c +++ b/gcc/ggc-common.c @@ -30,6 +30,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "varray.h" #include "ggc.h" #include "langhooks.h" +#ifdef ENABLE_VALGRIND_CHECKING +#include <valgrind.h> +#else +/* Avoid #ifdef:s when we can help it. */ +#define VALGRIND_DISCARD(x) +#endif /* Statistics about the allocation. */ static ggc_statistics *ggc_stats; @@ -155,10 +161,36 @@ ggc_realloc (x, size) old_size = ggc_get_size (x); if (size <= old_size) - return x; + { + /* Mark the unwanted memory as unaccessible. We also need to make + the "new" size accessible, since ggc_get_size returns the size of + the pool, not the size of the individually allocated object, the + size which was previously made accessible. Unfortunately, we + don't know that previously allocated size. Without that + knowledge we have to lose some initialization-tracking for the + old parts of the object. An alternative is to mark the whole + old_size as reachable, but that would lose tracking of writes + after the end of the object (by small offsets). Discard the + handle to avoid handle leak. */ + VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS ((char *) x + size, + old_size - size)); + VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, size)); + return x; + } r = ggc_alloc (size); + + /* Since ggc_get_size returns the size of the pool, not the size of the + individually allocated object, we'd access parts of the old object + that were marked invalid with the memcpy below. We lose a bit of the + initialization-tracking since some of it may be uninitialized. */ + VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, old_size)); + memcpy (r, x, old_size); + + /* The old object is not supposed to be used anymore. */ + VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (x, old_size)); + return r; } |