This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa libmudflap] alloca support, cleanups
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 3 Sep 2002 11:46:53 -0400
- Subject: [tree-ssa libmudflap] alloca support, cleanups
Hi -
I'm about to commit the following patch:
Index: gcc/ChangeLog.tree-ssa
2002-09-03 Frank Ch. Eigler <fche@redhat.com>
* gcc.c (MFWRAP_SPEC): Add --wrap=alloca.
Index: libmudflap/ChangeLog
2002-09-03 Frank Ch. Eigler <fche@redhat.com>
alloca support:
* Makefile.am (AM_CFLAGS): New definition of needed settings.
(HOOKOBJS): Add alloca-hook.o.
* mf-hooks.c (alloca): New function to implement alloca in libiberty
style.
* mf-runtime.c (__mf_report): Call alloca(0) to flush remaining blocks.
(__mf_backtrace): Reimplement without using alloca.
* Makefile.in: Regenerated.
cleanup:
* mf-hooks.c: Use VERBOSE_TRACE throughout instead of fprintf(stderr).
Correct signedness bugs in length-tracking variables.
* mf-impl.h: Make options unsigned.
(CALL_WRAP): New macro to parallel CALL_REAL().
(DECLARE): Remove erroneous ";" at end.
* mf-runtime.c, mf-hooks.c, mf-heuristics.c: Replace remaining %p
formatting specs with %08lx. Correct several compiler warnings.
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.324.2.10
diff -u -w -s -r1.324.2.10 gcc.c
--- gcc/gcc.c 27 Aug 2002 22:11:38 -0000 1.324.2.10
+++ gcc/gcc.c 3 Sep 2002 15:43:34 -0000
@@ -558,7 +558,7 @@
--wrap=strdup --wrap=strndup --wrap=strchr --wrap=strrchr\
--wrap=strstr --wrap=memmem --wrap=strlen --wrap=strnlen\
--wrap=bzero --wrap=bcopy --wrap=bcmp --wrap=index --wrap=rindex\
- --wrap=dlopen --wrap=mmap --wrap=munmap\
+ --wrap=dlopen --wrap=mmap --wrap=munmap --wrap=alloca\
}}"
#endif
#ifndef MFLIB_SPEC
Index: libmudflap/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/Makefile.am,v
retrieving revision 1.1.2.7
diff -u -w -s -r1.1.2.7 Makefile.am
--- libmudflap/Makefile.am 27 Aug 2002 22:33:29 -0000 1.1.2.7
+++ libmudflap/Makefile.am 3 Sep 2002 15:43:35 -0000
@@ -42,10 +42,8 @@
# Cross compiler and multilib support.
lib_LTLIBRARIES = libmudflap.la
-# Compile flags that should be constant throughout the build, both for
-# SUBDIRS and for libmudflap in general.
CFLAGS = -O2 -g -freorder-blocks
-WARN_CFLAGS = $(WERROR) -fdiagnostics-show-location=once
+AM_CFLAGS = -fno-builtin -fno-builtin-alloca -ansi -Wall -D__NO_STRING_INLINES
# Use common includes from acinclude.m4/LIBMUDFLAP_EXPORT_INCLUDES
LIBMUDFLAP_INCLUDES =
@@ -93,9 +91,11 @@
rindex-hook.lo \
dlopen-hook.lo \
mmap-hook.lo \
- munmap-hook.lo
+ munmap-hook.lo \
+ alloca-hook.lo
+.NOTPARALLEL:
$(HOOKOBJS): mf-hooks.c mf-runtime.h mf-impl.h
set -e; \
for i in $(HOOKOBJS); do \
Index: libmudflap/mf-heuristics.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-heuristics.c,v
retrieving revision 1.1.2.6
diff -u -w -s -r1.1.2.6 mf-heuristics.c
--- libmudflap/mf-heuristics.c 27 Aug 2002 22:33:29 -0000 1.1.2.6
+++ libmudflap/mf-heuristics.c 3 Sep 2002 15:43:35 -0000
@@ -50,7 +50,7 @@
{
uintptr_t stack_top_guess = (uintptr_t)__builtin_frame_address(0);
- VERBOSE_TRACE ("mf: stack estimated as %p-%p\n",
+ VERBOSE_TRACE ("mf: stack estimated as %08lx-%08lx\n",
stack_top_guess, stack_segment_base);
if (ptr_high <= stack_segment_base &&
@@ -84,8 +84,8 @@
if ((uintptr_t) low <= ptr &&
(uintptr_t) high >= ptr_high)
{
- VERBOSE_TRACE ("mf: registering region %p-%p given %s\n",
- low, high, buf);
+ VERBOSE_TRACE ("mf: registering region %08lx-%08lx given %s\n",
+ (uintptr_t) low, (uintptr_t) high, buf);
/* XXX: bad hack; permit __mf_register to do its job. */
__mf_state = active;
Index: libmudflap/mf-hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-hooks.c,v
retrieving revision 1.1.2.12
diff -u -w -s -r1.1.2.12 mf-hooks.c
--- libmudflap/mf-hooks.c 27 Aug 2002 22:33:29 -0000 1.1.2.12
+++ libmudflap/mf-hooks.c 3 Sep 2002 15:43:35 -0000
@@ -1,4 +1,5 @@
/* {{{ Copyright */
+
/* Mudflap: narrow-pointer bounds-checking by tree rewriting.
Copyright (C) 2002 Free Software Foundation, Inc.
Contributed by Frank Ch. Eigler <fche@redhat.com>
@@ -14,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
#include <execinfo.h>
#include <assert.h>
@@ -199,9 +201,11 @@
base -= __mf_opts.crumple_zone;
if (__mf_opts.trace_mf_calls)
{
- fprintf (stderr, "mf: freeing deferred pointer #%d %p = %p - %d\n",
- __mf_opts.free_queue_length, base,
- free_queue [free_ptr], __mf_opts.crumple_zone);
+ VERBOSE_TRACE ("mf: freeing deferred pointer #%d %08lx = %08lx - %u\n",
+ __mf_opts.free_queue_length,
+ (uintptr_t) base,
+ (uintptr_t) free_queue [free_ptr],
+ __mf_opts.crumple_zone);
}
CALL_REAL(free, base);
}
@@ -215,8 +219,10 @@
base -= __mf_opts.crumple_zone;
if (__mf_opts.trace_mf_calls)
{
- fprintf (stderr, "mf: freeing pointer %p = %p - %d\n", base,
- buf, __mf_opts.crumple_zone);
+ VERBOSE_TRACE ("mf: freeing pointer %08lx = %08lx - %u\n",
+ (uintptr_t) base,
+ (uintptr_t) buf,
+ __mf_opts.crumple_zone);
}
CALL_REAL(free, base);
}
@@ -283,9 +289,78 @@
__mf_state = old_state;
__mf_unregister ((uintptr_t)start, length);
+ return result;
}
#endif
+
+/* This wrapper is a little different, as it's implemented in terms
+ of the wrapped malloc/free functions. */
+#ifdef WRAP_alloca
+WRAPPER(void *, alloca, size_t c)
+{
+ DECLARE (void *, malloc, size_t);
+ DECLARE (void, free, void *);
+
+ /* This struct, a linked list, tracks alloca'd objects. The newest
+ object is at the head of the list. If we detect that we've
+ popped a few levels of stack, then the listed objects are freed
+ as needed. NB: The tracking struct is allocated with
+ real_malloc; the user data with wrap_malloc.
+ */
+ struct alloca_tracking { void *ptr; void *stack; struct alloca_tracking* next; };
+ static struct alloca_tracking *alloca_history = NULL;
+
+ void *stack = __builtin_frame_address (0);
+ char *result;
+ struct alloca_tracking *track;
+
+ TRACE_IN;
+ VERBOSE_TRACE ("mf: alloca stack level %08lx\n", (uintptr_t) stack);
+
+ /* Free any previously alloca'd blocks that belong to deeper-nested functions,
+ which must therefore have exited by now. */
+#define INNER_THAN < /* for x86 */
+ while (alloca_history &&
+ ((uintptr_t) stack INNER_THAN (uintptr_t) alloca_history->stack))
+ {
+ struct alloca_tracking *next = alloca_history->next;
+ CALL_WRAP (free, alloca_history->ptr);
+ CALL_REAL (free, alloca_history);
+ alloca_history = next;
+ }
+
+ /* Allocate new block. */
+ result = NULL;
+ if (LIKELY (c > 0)) /* alloca(0) causes no allocation. */
+ {
+ track = (struct alloca_tracking *) CALL_REAL (malloc,
+ sizeof (struct alloca_tracking));
+ if (LIKELY (track != NULL))
+ {
+ result = (char *) CALL_WRAP (malloc, c);
+ if (UNLIKELY (result == NULL))
+ {
+ CALL_REAL (free, track);
+ /* Too bad. XXX: What about errno? */
+ }
+ else
+ {
+ track->ptr = result;
+ track->stack = stack;
+ track->next = alloca_history;
+ alloca_history = track;
+ }
+ }
+ }
+
+ TRACE_OUT;
+ return result;
+}
+#endif
+
+
+
/* }}} */
/* {{{ str*,mem*,b* */
@@ -356,16 +431,16 @@
#ifdef WRAP_strcpy
WRAPPER(char *, strcpy, char *dest, const char *src)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strcpy, char *dest, const char *src);
- int n;
+ size_t n;
/* nb: just because strlen(src) == n doesn't mean (src + n) or (src + n +
1) are valid pointers. the allocated object might have size < n.
check anyways. */
BEGIN_PROTECT(char *, strcpy, dest, src);
- TRACE("mf: strcpy %p -> %p\n", src, dest);
+ TRACE("mf: strcpy %08lx -> %08lx\n", (uintptr_t) src, (uintptr_t) dest);
n = CALL_REAL(strlen, src);
MF_VALIDATE_EXTENT(src, CLAMPADD(n, 1), "strcpy src");
MF_VALIDATE_EXTENT(dest, CLAMPADD(n, 1), "strcpy dest");
@@ -376,12 +451,12 @@
#ifdef WRAP_strncpy
WRAPPER(char *, strncpy, char *dest, const char *src, size_t n)
{
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
DECLARE(char *, strncpy, char *dest, const char *src, size_t n);
- int len;
+ size_t len;
BEGIN_PROTECT(char *, strncpy, dest, src, n);
- TRACE("mf: strncpy %d chars %p -> %p\n", n, src, dest);
+ TRACE("mf: strncpy %08lx -> %08lx\n", (uintptr_t) src, (uintptr_t) dest);
len = CALL_REAL(strnlen, src, n);
MF_VALIDATE_EXTENT(src, len, "strncpy src");
MF_VALIDATE_EXTENT(dest, len, "strncpy dest"); /* nb: strNcpy */
@@ -392,10 +467,10 @@
#ifdef WRAP_strcat
WRAPPER(char *, strcat, char *dest, const char *src)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strcat, char *dest, const char *src);
- int dest_sz;
- int src_sz;
+ size_t dest_sz;
+ size_t src_sz;
BEGIN_PROTECT(char *, strcat, dest, src);
dest_sz = CALL_REAL(strlen, dest);
@@ -430,10 +505,10 @@
this same logic applies to further uses of strnlen later down in this
file. */
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
DECLARE(char *, strncat, char *dest, const char *src, size_t n);
- int src_sz;
- int dest_sz;
+ size_t src_sz;
+ size_t dest_sz;
BEGIN_PROTECT(char *, strncat, dest, src, n);
src_sz = CALL_REAL(strnlen, src, n);
@@ -448,10 +523,10 @@
#ifdef WRAP_strcmp
WRAPPER(int, strcmp, const char *s1, const char *s2)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(int, strcmp, const char *s1, const char *s2);
- int s1_sz;
- int s2_sz;
+ size_t s1_sz;
+ size_t s2_sz;
BEGIN_PROTECT(int, strcmp, s1, s2);
s1_sz = CALL_REAL(strlen, s1);
@@ -465,10 +540,10 @@
#ifdef WRAP_strcasecmp
WRAPPER(int, strcasecmp, const char *s1, const char *s2)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(int, strcasecmp, const char *s1, const char *s2);
- int s1_sz;
- int s2_sz;
+ size_t s1_sz;
+ size_t s2_sz;
BEGIN_PROTECT(int, strcasecmp, s1, s2);
s1_sz = CALL_REAL(strlen, s1);
@@ -482,10 +557,10 @@
#ifdef WRAP_strncmp
WRAPPER(int, strncmp, const char *s1, const char *s2, size_t n)
{
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
DECLARE(int, strncmp, const char *s1, const char *s2, size_t n);
- int s1_sz;
- int s2_sz;
+ size_t s1_sz;
+ size_t s2_sz;
BEGIN_PROTECT(int, strncmp, s1, s2, n);
s1_sz = CALL_REAL(strnlen, s1, n);
@@ -499,10 +574,10 @@
#ifdef WRAP_strncasecmp
WRAPPER(int, strncasecmp, const char *s1, const char *s2, size_t n)
{
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
DECLARE(int, strncasecmp, const char *s1, const char *s2, size_t n);
- int s1_sz;
- int s2_sz;
+ size_t s1_sz;
+ size_t s2_sz;
BEGIN_PROTECT(int, strncasecmp, s1, s2, n);
s1_sz = CALL_REAL(strnlen, s1, n);
@@ -516,11 +591,11 @@
#ifdef WRAP_strdup
WRAPPER(char *, strdup, const char *s)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strdup, const char *s);
DECLARE(void *, malloc, size_t sz);
DECLARE(void *, memcpy, void *dest, const void *src, size_t n);
- int n;
+ size_t n;
BEGIN_PROTECT(char *, strdup, s);
n = CALL_REAL(strlen, s);
@@ -553,11 +628,11 @@
#ifdef WRAP_strndup
WRAPPER(char *, strndup, const char *s, size_t n)
{
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
DECLARE(char *, strndup, const char *s, size_t n);
DECLARE(void *, malloc, size_t sz);
DECLARE(void *, memcpy, void *dest, const void *src, size_t n);
- int sz;
+ size_t sz;
BEGIN_PROTECT(char *, strndup, s, n);
sz = CALL_REAL(strnlen, s, n);
@@ -591,9 +666,9 @@
#ifdef WRAP_strchr
WRAPPER(char *, strchr, const char *s, int c)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strchr, const char *s, int c);
- int n;
+ size_t n;
BEGIN_PROTECT(char *, strchr, s, c);
n = CALL_REAL(strlen, s);
@@ -605,9 +680,9 @@
#ifdef WRAP_strrchr
WRAPPER(char *, strrchr, const char *s, int c)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strrchr, const char *s, int c);
- int n;
+ size_t n;
BEGIN_PROTECT(char *, strrchr, s, c);
n = CALL_REAL(strlen, s);
@@ -619,10 +694,10 @@
#ifdef WRAP_strstr
WRAPPER(char *, strstr, const char *haystack, const char *needle)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, strstr, const char *haystack, const char *needle);
- int haystack_sz;
- int needle_sz;
+ size_t haystack_sz;
+ size_t needle_sz;
BEGIN_PROTECT(char *, strstr, haystack, needle);
haystack_sz = CALL_REAL(strlen, haystack);
@@ -649,11 +724,11 @@
#endif
#ifdef WRAP_strlen
-WRAPPER(int, strlen, const char *s)
+WRAPPER(size_t, strlen, const char *s)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
- BEGIN_PROTECT(int, strlen, s);
+ BEGIN_PROTECT(size_t, strlen, s);
result = CALL_REAL(strlen, s);
MF_VALIDATE_EXTENT(s, CLAMPADD(result, 1), "strlen region");
__mf_state = old_state;
@@ -663,11 +738,11 @@
#endif
#ifdef WRAP_strnlen
-WRAPPER(int, strnlen, const char *s, size_t n)
+WRAPPER(size_t, strnlen, const char *s, size_t n)
{
- DECLARE(int, strnlen, const char *s, size_t n);
+ DECLARE(size_t, strnlen, const char *s, size_t n);
- BEGIN_PROTECT(int, strnlen, s, n);
+ BEGIN_PROTECT(size_t, strnlen, s, n);
result = CALL_REAL(strnlen, s, n);
MF_VALIDATE_EXTENT(s, result, "strnlen region");
__mf_state = old_state;
@@ -734,9 +809,9 @@
#ifdef WRAP_index
WRAPPER(char *, index, const char *s, int c)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, index, const char *s, int c);
- int n;
+ size_t n;
BEGIN_PROTECT(char *, index, s, c);
n = CALL_REAL(strlen, s);
@@ -748,9 +823,9 @@
#ifdef WRAP_rindex
WRAPPER(char *, rindex, const char *s, int c)
{
- DECLARE(int, strlen, const char *s);
+ DECLARE(size_t, strlen, const char *s);
DECLARE(char *, rindex, const char *s, int c);
- int n;
+ size_t n;
BEGIN_PROTECT(char *, rindex, s, c);
n = CALL_REAL(strlen, s);
Index: libmudflap/mf-impl.h
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-impl.h,v
retrieving revision 1.1.2.3
diff -u -w -s -r1.1.2.3 mf-impl.h
--- libmudflap/mf-impl.h 27 Aug 2002 22:33:29 -0000 1.1.2.3
+++ libmudflap/mf-impl.h 3 Sep 2002 15:43:35 -0000
@@ -50,41 +50,41 @@
struct __mf_options
{
/* Emit a trace message for each call. */
- int trace_mf_calls;
+ unsigned trace_mf_calls;
/* Collect and emit statistics. */
- int collect_stats;
+ unsigned collect_stats;
/* Execute internal checking code */
- int internal_checking;
+ unsigned internal_checking;
/* Print list of leaked heap objects on shutdown. */
- int print_leaks;
+ unsigned print_leaks;
/* Print verbose description of violations. */
- int verbose_violations;
+ unsigned verbose_violations;
/* Emit internal tracing message. */
- int verbose_trace;
+ unsigned verbose_trace;
/* Perform occasional tree-rotations to optimize lookups. */
- int optimize_object_tree;
+ unsigned optimize_object_tree;
/* Support multiple threads. */
- int multi_threaded;
+ unsigned multi_threaded;
/* Maintain a queue of this many deferred free()s,
to trap use of freed memory. */
- int free_queue_length;
+ unsigned free_queue_length;
/* Maintain a history of this many past unregistered objects. */
- int persistent_count;
+ unsigned persistent_count;
/* Pad allocated extents by this many bytes on either side. */
- int crumple_zone;
+ unsigned crumple_zone;
/* Maintain this many stack frames for contexts. */
- int backtrace;
+ unsigned backtrace;
/* Major operation mode */
@@ -110,9 +110,9 @@
violation_mode;
/* Violation heuristics selection. */
- int heur_stack_bound; /* allow current stack region */
- int heur_proc_map; /* allow & cache /proc/self/map regions. */
- int heur_start_end; /* allow & cache _start .. _end */
+ unsigned heur_stack_bound; /* allow current stack region */
+ unsigned heur_proc_map; /* allow & cache /proc/self/map regions. */
+ unsigned heur_start_end; /* allow & cache _start .. _end */
};
@@ -231,21 +231,25 @@
__attribute__ (( alias (#fname) )); \
ret fname (__VA_ARGS__)
#define DECLARE(ty, fname, ...) \
- typedef ty (*__mf_fn_ ## fname) (__VA_ARGS__);
+ typedef ty (*__mf_fn_ ## fname) (__VA_ARGS__)
#define CALL_REAL(fname, ...) \
({ if (UNLIKELY(!__mf_dynamic.dyn_ ## fname)) \
__mf_resolve_dynamics (); \
((__mf_fn_ ## fname)(__mf_dynamic.dyn_ ## fname)) \
(__VA_ARGS__);})
+#define CALL_WRAP(fname, ...) \
+ (__wrap_ ## fname (__VA_ARGS__))
#else /* not PIC --> static library */
#define WRAPPER(ret, fname, ...) \
ret __wrap_ ## fname (__VA_ARGS__)
#define DECLARE(ty, fname, ...) \
- extern ty __real_ ## fname (__VA_ARGS__);
+ extern ty __real_ ## fname (__VA_ARGS__)
#define CALL_REAL(fname, ...) \
__real_ ## fname (__VA_ARGS__)
+#define CALL_WRAP(fname, ...) \
+ __wrap_ ## fname (__VA_ARGS__)
#endif /* PIC */
Index: libmudflap/mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-runtime.c,v
retrieving revision 1.1.2.11
diff -u -w -s -r1.1.2.11 mf-runtime.c
--- libmudflap/mf-runtime.c 28 Aug 2002 19:47:24 -0000 1.1.2.11
+++ libmudflap/mf-runtime.c 3 Sep 2002 15:43:35 -0000
@@ -231,7 +231,7 @@
case set_option:
fprintf (stderr, "-%-23.23s %s", opt->name, opt->description);
if (default_p)
- fprintf (stderr, " [default]\n", opt->value);
+ fprintf (stderr, " [default]\n");
else
fprintf (stderr, "\n");
break;
@@ -518,8 +518,8 @@
struct __mf_cache old_entry = *entry;
BEGIN_RECURSION_PROTECT;
- TRACE ("mf: check p=%p s=%lu "
- "location=`%s'\n", (void *)ptr, sz, location);
+ TRACE ("mf: check p=%08lx s=%lu "
+ "location=`%s'\n", ptr, sz, location);
switch (__mf_opts.mudflap_mode)
{
@@ -657,7 +657,7 @@
{
/* if (UNLIKELY (!(__mf_state == active || __mf_state == starting))) return; */
- TRACE ("mf: register p=%p s=%lu t=%d n='%s'\n", (void *)ptr, sz,
+ TRACE ("mf: register p=%08lx s=%lu t=%d n='%s'\n", ptr, sz,
type, name ? name : "");
switch (__mf_opts.mudflap_mode)
@@ -680,7 +680,6 @@
case mode_check:
{
__mf_object_tree_t *ovr_obj[1];
- __mf_object_tree_t *new_obj;
unsigned num_overlapping_objs;
uintptr_t low = ptr;
uintptr_t high = CLAMPSZ (ptr, sz);
@@ -704,13 +703,13 @@
ovr_obj[0]->data.high == high)
{
/* do nothing */
- VERBOSE_TRACE ("mf: duplicate static reg %p\n", (void *)low);
+ VERBOSE_TRACE ("mf: duplicate static reg %08lx\n", low);
END_RECURSION_PROTECT;
return;
}
else if (type == __MF_TYPE_GUESS)
{
- int i;
+ unsigned i;
int all_guesses = 1;
for (i = 0; i < num_overlapping_objs; ++i)
@@ -729,12 +728,12 @@
little HEAPie was added second. */
if (all_guesses)
{
- VERBOSE_TRACE ("mf: replacing %d existing guess%s at %p "
- "with %p - %p\n",
+ VERBOSE_TRACE ("mf: replacing %d existing guess%s at %08lx "
+ "with %08lx - %08lx\n",
num_overlapping_objs,
(num_overlapping_objs > 1 ? "es" : ""),
- (void *)low,
- (void *)low, (void *)high);
+ low,
+ low, high);
for (i = 0; i < num_overlapping_objs; ++i)
{
@@ -749,15 +748,15 @@
}
else
{
- VERBOSE_TRACE ("mf: preserving %d regions at %p\n",
- num_overlapping_objs, (void *)low);
+ VERBOSE_TRACE ("mf: preserving %d regions at %08lx\n",
+ num_overlapping_objs, low);
}
END_RECURSION_PROTECT;
return;
}
else
{
- int i;
+ unsigned i;
for (i = 0; i < num_overlapping_objs; ++i)
{
if (ovr_obj[i]->data.type == __MF_TYPE_GUESS)
@@ -781,7 +780,7 @@
guess2_low = CLAMPADD (high, (1 + __mf_opts.crumple_zone));
guess2_high = ovr_obj[i]->data.high;
- VERBOSE_TRACE ("mf: splitting guess region %p-%p\n",
+ VERBOSE_TRACE ("mf: splitting guess region %08lx-%08lx\n",
guess1_low, guess2_high);
/* NB: split regions may disappear if low > high. */
@@ -848,7 +847,7 @@
DECLARE (void, free, void *ptr);
BEGIN_RECURSION_PROTECT;
- TRACE ("mf: unregister p=%p s=%lu\n", (void *)ptr, sz);
+ TRACE ("mf: unregister p=%08lx s=%lu\n", ptr, sz);
switch (__mf_opts.mudflap_mode)
{
@@ -868,7 +867,6 @@
case mode_check:
{
- static unsigned recursion = 0;
__mf_object_tree_t *old_obj = NULL;
__mf_object_tree_t *del_obj = NULL; /* Object to actually delete. */
__mf_object_tree_t *objs[1] = {NULL};
@@ -881,12 +879,12 @@
{
/* do not unregister guessed regions */
- int i;
+ unsigned i;
for (i = 0; i < num_overlapping_objs; ++i)
{
if (objs[i]->data.type == __MF_TYPE_GUESS)
{
- VERBOSE_TRACE ("mf: ignored guess unreg %p\n", objs[i]->data.low);
+ VERBOSE_TRACE ("mf: ignored guess unreg %08lx\n", objs[i]->data.low);
END_RECURSION_PROTECT;
return;
}
@@ -905,7 +903,8 @@
old_obj = objs[0];
- VERBOSE_TRACE ("mf: removing %p-%p\n", old_obj->data.low, old_obj->data.high);
+ VERBOSE_TRACE ("mf: removing %08lx-%08lx\n",
+ old_obj->data.low, old_obj->data.high);
__mf_remove_old_object (old_obj);
@@ -1323,7 +1322,7 @@
if (__mf_opts.backtrace > 0)
{
- int i;
+ unsigned i;
for (i=0; i<obj->alloc_backtrace_size; i++)
fprintf (stderr, " %s\n", obj->alloc_backtrace[i]);
}
@@ -1337,7 +1336,7 @@
if (__mf_opts.backtrace > 0)
{
- int i;
+ unsigned i;
for (i=0; i<obj->dealloc_backtrace_size; i++)
fprintf (stderr, " %s\n", obj->dealloc_backtrace[i]);
}
@@ -1432,7 +1431,10 @@
}
if (__mf_opts.print_leaks && (__mf_opts.mudflap_mode == mode_check))
{
- unsigned l = __mf_report_leaks (__mf_object_root);
+ unsigned l;
+ /* Free up any remaining alloca()'d blocks. */
+ (void) CALL_WRAP (alloca, 0); /* XXX: doesn't work in shared mode. */
+ l = __mf_report_leaks (__mf_object_root);
fprintf (stderr, "number of leaked objects: %u\n", l);
}
}
@@ -1448,8 +1450,10 @@
unsigned remaining_size;
unsigned omitted_size = 0;
unsigned i;
+ DECLARE (void, free, void *ptr);
+ DECLARE (void *, calloc, size_t c, size_t n);
- pc_array = alloca (pc_array_size * sizeof (void *));
+ pc_array = CALL_REAL (calloc, pc_array_size, sizeof (void *));
pc_array_size = backtrace (pc_array, pc_array_size);
/* We want to trim the first few levels of the stack traceback,
@@ -1470,6 +1474,8 @@
remaining_size = pc_array_size - omitted_size;
*symbols = backtrace_symbols (pc_array + omitted_size, remaining_size);
+ CALL_REAL (free, pc_array);
+
return remaining_size;
}
@@ -1486,7 +1492,7 @@
DECLARE(void, free, void *ptr);
BEGIN_RECURSION_PROTECT;
- TRACE ("mf: violation pc=%p location=%s type=%d ptr=%p size=%lu\n", pc,
+ TRACE ("mf: violation pc=%08lx location=%s type=%d ptr=%08lx size=%lu\n", pc,
(location != NULL ? location : ""), type, ptr, sz);
if (__mf_opts.collect_stats)