Commit 35dee980 by Hans-Peter Nilsson Committed by Hans-Peter Nilsson

Support valgrind 3.3 for --enable-checking=valgrind.

	* system.h: Consolidate ENABLE_VALGRIND_CHECKING-dependent defines
	here.
	[!VALGRIND_MAKE_MEM_NOACCESS]: Define as VALGRIND_MAKE_NOACCESS.
	[!VALGRIND_MAKE_MEM_DEFINED]: Define as VALGRIND_MAKE_READABLE.
	[!VALGRIND_MAKE_MEM_UNDEFINED]: Define as VALGRIND_MAKE_WRITABLE.
	* ggc-common.c: Remove ENABLE_VALGRIND_CHECKING-dependent defines.
	Replace use of VALGRIND_MAKE_READABLE, VALGRIND_MAKE_WRITABLE, and
	VALGRIND_MAKE_NOACCESS with VALGRIND_MAKE_MEM_DEFINED,
	VALGRIND_MAKE_MEM_UNDEFINED, and VALGRIND_MAKE_MEM_NOACCESS
	respectively.
	* ggc-zone.c: Similar.
	* ggc-page.c: Similar.

From-SVN: r132407
parent 5ff3a208
2008-02-19 Hans-Peter Nilsson <hp@axis.com>
Support valgrind 3.3 for --enable-checking=valgrind.
* system.h: Consolidate ENABLE_VALGRIND_CHECKING-dependent defines
here.
[!VALGRIND_MAKE_MEM_NOACCESS]: Define as VALGRIND_MAKE_NOACCESS.
[!VALGRIND_MAKE_MEM_DEFINED]: Define as VALGRIND_MAKE_READABLE.
[!VALGRIND_MAKE_MEM_UNDEFINED]: Define as VALGRIND_MAKE_WRITABLE.
* ggc-common.c: Remove ENABLE_VALGRIND_CHECKING-dependent defines.
Replace use of VALGRIND_MAKE_READABLE, VALGRIND_MAKE_WRITABLE, and
VALGRIND_MAKE_NOACCESS with VALGRIND_MAKE_MEM_DEFINED,
VALGRIND_MAKE_MEM_UNDEFINED, and VALGRIND_MAKE_MEM_NOACCESS
respectively.
* ggc-zone.c: Similar.
* ggc-page.c: Similar.
2008-02-19 Paul Brook <paul@codesourcery.com> 2008-02-19 Paul Brook <paul@codesourcery.com>
PR target/35071 PR target/35071
......
...@@ -47,19 +47,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -47,19 +47,6 @@ along with GCC; see the file COPYING3. If not see
# define MAP_FAILED ((void *)-1) # define MAP_FAILED ((void *)-1)
#endif #endif
#ifdef ENABLE_VALGRIND_CHECKING
# ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
# elif defined HAVE_MEMCHECK_H
# include <memcheck.h>
# else
# include <valgrind.h>
# endif
#else
/* Avoid #ifdef:s when we can help it. */
#define VALGRIND_DISCARD(x)
#endif
/* When set, ggc_collect will do collection. */ /* When set, ggc_collect will do collection. */
bool ggc_force_collect; bool ggc_force_collect;
...@@ -163,9 +150,9 @@ ggc_realloc_stat (void *x, size_t size MEM_STAT_DECL) ...@@ -163,9 +150,9 @@ ggc_realloc_stat (void *x, size_t size MEM_STAT_DECL)
old_size as reachable, but that would lose tracking of writes old_size as reachable, but that would lose tracking of writes
after the end of the object (by small offsets). Discard the after the end of the object (by small offsets). Discard the
handle to avoid handle leak. */ handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS ((char *) x + size, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS ((char *) x + size,
old_size - size)); old_size - size));
VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (x, size));
return x; return x;
} }
...@@ -175,7 +162,7 @@ ggc_realloc_stat (void *x, size_t size MEM_STAT_DECL) ...@@ -175,7 +162,7 @@ ggc_realloc_stat (void *x, size_t size MEM_STAT_DECL)
individually allocated object, we'd access parts of the old object 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 that were marked invalid with the memcpy below. We lose a bit of the
initialization-tracking since some of it may be uninitialized. */ initialization-tracking since some of it may be uninitialized. */
VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (x, old_size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (x, old_size));
memcpy (r, x, old_size); memcpy (r, x, old_size);
......
...@@ -31,18 +31,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -31,18 +31,6 @@ along with GCC; see the file COPYING3. If not see
#include "timevar.h" #include "timevar.h"
#include "params.h" #include "params.h"
#include "tree-flow.h" #include "tree-flow.h"
#ifdef ENABLE_VALGRIND_CHECKING
# ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
# elif defined HAVE_MEMCHECK_H
# include <memcheck.h>
# else
# include <valgrind.h>
# endif
#else
/* Avoid #ifdef:s when we can help it. */
#define VALGRIND_DISCARD(x)
#endif
/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
file open. Prefer either to valloc. */ file open. Prefer either to valloc. */
...@@ -689,7 +677,7 @@ alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size) ...@@ -689,7 +677,7 @@ alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size)
/* Pretend we don't have access to the allocated pages. We'll enable /* Pretend we don't have access to the allocated pages. We'll enable
access to smaller pieces of the area in ggc_alloc. Discard the access to smaller pieces of the area in ggc_alloc. Discard the
handle to avoid handle leak. */ handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (page, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (page, size));
return page; return page;
} }
...@@ -933,7 +921,7 @@ free_page (page_entry *entry) ...@@ -933,7 +921,7 @@ free_page (page_entry *entry)
/* Mark the page as inaccessible. Discard the handle to avoid handle /* Mark the page as inaccessible. Discard the handle to avoid handle
leak. */ leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (entry->page, entry->bytes)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (entry->page, entry->bytes));
set_page_table_entry (entry->page, NULL); set_page_table_entry (entry->page, NULL);
...@@ -1208,7 +1196,7 @@ ggc_alloc_stat (size_t size MEM_STAT_DECL) ...@@ -1208,7 +1196,7 @@ ggc_alloc_stat (size_t size MEM_STAT_DECL)
exact same semantics in presence of memory bugs, regardless of exact same semantics in presence of memory bugs, regardless of
ENABLE_VALGRIND_CHECKING. We override this request below. Drop the ENABLE_VALGRIND_CHECKING. We override this request below. Drop the
handle to avoid handle leak. */ handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (result, object_size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (result, object_size));
/* `Poison' the entire allocated object, including any padding at /* `Poison' the entire allocated object, including any padding at
the end. */ the end. */
...@@ -1216,14 +1204,14 @@ ggc_alloc_stat (size_t size MEM_STAT_DECL) ...@@ -1216,14 +1204,14 @@ ggc_alloc_stat (size_t size MEM_STAT_DECL)
/* Make the bytes after the end of the object unaccessible. Discard the /* Make the bytes after the end of the object unaccessible. Discard the
handle to avoid handle leak. */ handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS ((char *) result + size, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS ((char *) result + size,
object_size - size)); object_size - size));
#endif #endif
/* Tell Valgrind that the memory is there, but its content isn't /* Tell Valgrind that the memory is there, but its content isn't
defined. The bytes at the end of the object are still marked defined. The bytes at the end of the object are still marked
unaccessible. */ unaccessible. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (result, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (result, size));
/* Keep track of how many bytes are being allocated. This /* Keep track of how many bytes are being allocated. This
information is used in deciding when to collect. */ information is used in deciding when to collect. */
...@@ -1358,11 +1346,11 @@ ggc_free (void *p) ...@@ -1358,11 +1346,11 @@ ggc_free (void *p)
#ifdef ENABLE_GC_CHECKING #ifdef ENABLE_GC_CHECKING
/* Poison the data, to indicate the data is garbage. */ /* Poison the data, to indicate the data is garbage. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (p, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (p, size));
memset (p, 0xa5, size); memset (p, 0xa5, size);
#endif #endif
/* Let valgrind know the object is free. */ /* Let valgrind know the object is free. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (p, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (p, size));
#ifdef ENABLE_GC_ALWAYS_COLLECT #ifdef ENABLE_GC_ALWAYS_COLLECT
/* In the completely-anal-checking mode, we do *not* immediately free /* In the completely-anal-checking mode, we do *not* immediately free
...@@ -1815,11 +1803,12 @@ poison_pages (void) ...@@ -1815,11 +1803,12 @@ poison_pages (void)
so the exact same memory semantics is kept, in case so the exact same memory semantics is kept, in case
there are memory errors. We override this request there are memory errors. We override this request
below. */ below. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (object, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (object,
size));
memset (object, 0xa5, size); memset (object, 0xa5, size);
/* Drop the handle to avoid handle leak. */ /* Drop the handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (object, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (object, size));
} }
} }
} }
......
...@@ -37,21 +37,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -37,21 +37,6 @@ along with GCC; see the file COPYING3. If not see
#include "params.h" #include "params.h"
#include "bitmap.h" #include "bitmap.h"
#ifdef ENABLE_VALGRIND_CHECKING
# ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
# elif defined HAVE_MEMCHECK_H
# include <memcheck.h>
# else
# include <valgrind.h>
# endif
#else
/* Avoid #ifdef:s when we can help it. */
#define VALGRIND_DISCARD(x)
#define VALGRIND_MALLOCLIKE_BLOCK(w,x,y,z)
#define VALGRIND_FREELIKE_BLOCK(x,y)
#endif
/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
file open. Prefer either to valloc. */ file open. Prefer either to valloc. */
#ifdef HAVE_MMAP_ANON #ifdef HAVE_MMAP_ANON
...@@ -787,7 +772,7 @@ alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size, struct alloc_zone *zone) ...@@ -787,7 +772,7 @@ alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size, struct alloc_zone *zone)
/* Pretend we don't have access to the allocated pages. We'll enable /* Pretend we don't have access to the allocated pages. We'll enable
access to smaller pieces of the area in ggc_alloc. Discard the access to smaller pieces of the area in ggc_alloc. Discard the
handle to avoid handle leak. */ handle to avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (page, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (page, size));
return page; return page;
} }
...@@ -903,8 +888,8 @@ free_small_page (struct small_page_entry *entry) ...@@ -903,8 +888,8 @@ free_small_page (struct small_page_entry *entry)
/* Mark the page as inaccessible. Discard the handle to /* Mark the page as inaccessible. Discard the handle to
avoid handle leak. */ avoid handle leak. */
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (entry->common.page, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (entry->common.page,
SMALL_PAGE_SIZE)); SMALL_PAGE_SIZE));
entry->next = entry->common.zone->free_pages; entry->next = entry->common.zone->free_pages;
entry->common.zone->free_pages = entry; entry->common.zone->free_pages = entry;
...@@ -978,18 +963,30 @@ free_chunk (char *ptr, size_t size, struct alloc_zone *zone) ...@@ -978,18 +963,30 @@ free_chunk (char *ptr, size_t size, struct alloc_zone *zone)
if (bin > NUM_FREE_BINS) if (bin > NUM_FREE_BINS)
{ {
bin = 0; bin = 0;
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (chunk, sizeof (struct alloc_chunk))); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (chunk,
sizeof (struct
alloc_chunk)));
chunk->size = size; chunk->size = size;
chunk->next_free = zone->free_chunks[bin]; chunk->next_free = zone->free_chunks[bin];
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (ptr + sizeof (struct alloc_chunk), VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (ptr
size - sizeof (struct alloc_chunk))); + sizeof (struct
alloc_chunk),
size
- sizeof (struct
alloc_chunk)));
} }
else else
{ {
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (chunk, sizeof (struct alloc_chunk *))); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (chunk,
sizeof (struct
alloc_chunk *)));
chunk->next_free = zone->free_chunks[bin]; chunk->next_free = zone->free_chunks[bin];
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (ptr + sizeof (struct alloc_chunk *), VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (ptr
size - sizeof (struct alloc_chunk *))); + sizeof (struct
alloc_chunk *),
size
- sizeof (struct
alloc_chunk *)));
} }
zone->free_chunks[bin] = chunk; zone->free_chunks[bin] = chunk;
...@@ -1213,16 +1210,16 @@ ggc_alloc_zone_stat (size_t orig_size, struct alloc_zone *zone ...@@ -1213,16 +1210,16 @@ ggc_alloc_zone_stat (size_t orig_size, struct alloc_zone *zone
#ifdef ENABLE_GC_CHECKING #ifdef ENABLE_GC_CHECKING
/* `Poison' the entire allocated object. */ /* `Poison' the entire allocated object. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (result, size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (result, size));
memset (result, 0xaf, size); memset (result, 0xaf, size);
VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (result + orig_size, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (result + orig_size,
size - orig_size)); size - orig_size));
#endif #endif
/* Tell Valgrind that the memory is there, but its content isn't /* Tell Valgrind that the memory is there, but its content isn't
defined. The bytes at the end of the object are still marked defined. The bytes at the end of the object are still marked
unaccessible. */ unaccessible. */
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (result, orig_size)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (result, orig_size));
/* Keep track of how many bytes are being allocated. This /* Keep track of how many bytes are being allocated. This
information is used in deciding when to collect. */ information is used in deciding when to collect. */
...@@ -1701,9 +1698,9 @@ sweep_pages (struct alloc_zone *zone) ...@@ -1701,9 +1698,9 @@ sweep_pages (struct alloc_zone *zone)
{ {
if (last_free) if (last_free)
{ {
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (last_free, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (last_free,
object object
- last_free)); - last_free));
poison_region (last_free, object - last_free); poison_region (last_free, object - last_free);
free_chunk (last_free, object - last_free, zone); free_chunk (last_free, object - last_free, zone);
last_free = NULL; last_free = NULL;
...@@ -1739,7 +1736,8 @@ sweep_pages (struct alloc_zone *zone) ...@@ -1739,7 +1736,8 @@ sweep_pages (struct alloc_zone *zone)
{ {
*spp = snext; *spp = snext;
#ifdef ENABLE_GC_CHECKING #ifdef ENABLE_GC_CHECKING
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (sp->common.page, SMALL_PAGE_SIZE)); VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (sp->common.page,
SMALL_PAGE_SIZE));
/* Poison the page. */ /* Poison the page. */
memset (sp->common.page, 0xb5, SMALL_PAGE_SIZE); memset (sp->common.page, 0xb5, SMALL_PAGE_SIZE);
#endif #endif
...@@ -1748,8 +1746,8 @@ sweep_pages (struct alloc_zone *zone) ...@@ -1748,8 +1746,8 @@ sweep_pages (struct alloc_zone *zone)
} }
else if (last_free) else if (last_free)
{ {
VALGRIND_DISCARD (VALGRIND_MAKE_WRITABLE (last_free, VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (last_free,
object - last_free)); object - last_free));
poison_region (last_free, object - last_free); poison_region (last_free, object - last_free);
free_chunk (last_free, object - last_free, zone); free_chunk (last_free, object - last_free, zone);
} }
......
...@@ -804,4 +804,29 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; ...@@ -804,4 +804,29 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
#endif #endif
#endif #endif
#ifdef ENABLE_VALGRIND_CHECKING
# ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
# elif defined HAVE_MEMCHECK_H
# include <memcheck.h>
# else
# include <valgrind.h>
# endif
/* Compatibility macros to let valgrind 3.1 work. */
# ifndef VALGRIND_MAKE_MEM_NOACCESS
# define VALGRIND_MAKE_MEM_NOACCESS VALGRIND_MAKE_NOACCESS
# endif
# ifndef VALGRIND_MAKE_MEM_DEFINED
# define VALGRIND_MAKE_MEM_DEFINED VALGRIND_MAKE_READABLE
# endif
# ifndef VALGRIND_MAKE_MEM_UNDEFINED
# define VALGRIND_MAKE_MEM_UNDEFINED VALGRIND_MAKE_WRITABLE
# endif
#else
/* Avoid #ifdef:s when we can help it. */
#define VALGRIND_DISCARD(x)
#define VALGRIND_MALLOCLIKE_BLOCK(w,x,y,z)
#define VALGRIND_FREELIKE_BLOCK(x,y)
#endif
#endif /* ! GCC_SYSTEM_H */ #endif /* ! GCC_SYSTEM_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment