diff -aur ruby-1.8.4.orig/Makefile.in ruby-1.8.4/Makefile.in
--- ruby-1.8.4.orig/Makefile.in	2005-11-11 00:22:03.000000000 +0100
+++ ruby-1.8.4/Makefile.in	2006-02-11 00:45:49.000000000 +0100
@@ -32,7 +32,7 @@
 
 empty =
 OUTFLAG = @OUTFLAG@$(empty)
-CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@
+CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@ @VALGRIND_CFLAGS@
 CPPFLAGS = -I. -I$(srcdir) @CPPFLAGS@
 LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
 EXTLDFLAGS = 
diff -aur ruby-1.8.4.orig/configure.in ruby-1.8.4/configure.in
--- ruby-1.8.4.orig/configure.in	2005-11-24 13:07:18.000000000 +0100
+++ ruby-1.8.4/configure.in	2006-02-11 00:51:46.000000000 +0100
@@ -769,6 +769,20 @@
     fi
 fi
 
+AC_ARG_ENABLE(valgrind,
+       [  --enable-valgrind       use valgrind support.],
+       [want_valgrind=$enableval], [want_valgrind=auto])
+
+if test x"$want_valgrind" != xno; then
+	PKG_CHECK_MODULES(VALGRIND, valgrind, have_valgrind=yes, have_valgrind=no)
+
+	if test x"$have_valgrind" = xyes; then
+		AC_DEFINE(HAVE_VALGRIND)
+	elif test x"$want_valgrind" = xyes -a x"$have_valgrind" = xno; then
+		AC_MSG_ERROR(valgrind support requested but valgrind not found)
+	fi
+fi
+
 dnl default value for $KANJI
 DEFAULT_KCODE="KCODE_NONE"
 
diff -aur ruby-1.8.4.orig/gc.c ruby-1.8.4/gc.c
--- ruby-1.8.4.orig/gc.c	2005-12-16 05:58:51.000000000 +0100
+++ ruby-1.8.4/gc.c	2006-02-11 00:45:15.000000000 +0100
@@ -30,6 +30,12 @@
 #include <sys/resource.h>
 #endif
 
+#ifdef HAVE_VALGRIND
+#include <memcheck.h>
+#else
+#define VALGRIND_MAKE_READABLE(p, n) /* empty */
+#endif
+
 #ifdef __ia64__
 #include <ucontext.h>
 #if defined(__FreeBSD__)
@@ -620,6 +626,9 @@
     register long n;
 {
     VALUE v;
+
+    VALGRIND_MAKE_READABLE(x, sizeof(*x) * n);
+
     while (n--) {
         v = *x;
 	if (is_pointer_to_heap((void *)v)) {
@@ -710,7 +719,10 @@
 {
     register RVALUE *obj;
 
+    VALGRIND_MAKE_READABLE(&ptr, sizeof(ptr));
     obj = RANY(ptr);
+    VALGRIND_MAKE_READABLE(obj, sizeof(*obj));
+
     if (rb_special_const_p(ptr)) return; /* special const not marked */
     if (obj->as.basic.flags == 0) return;       /* free cell */
     if (obj->as.basic.flags & FL_MARK) return;  /* already marked */
