unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Valgrind fix
@ 2010-03-08  0:04 No Itisnt
  2010-03-08 18:49 ` No Itisnt
  2010-03-08 21:16 ` Ludovic Courtès
  0 siblings, 2 replies; 7+ messages in thread
From: No Itisnt @ 2010-03-08  0:04 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 560 bytes --]

Here is patch that allows valgrind to run Guile under Linux non-IA64
systems. It also fixes a potential leak in threads.c where a
pthread attribute was not destroyed.

Note that libgc still generates lots of warnings. For now, I've just
been suppressing all warnings from libgc, and I'm happy to report that
Guile doesn't seem to cause any issues on my system (Linux/AMD64). But
it's certainly possible that the suppressions could mask a legitimate
issue.

Attached are the patch and suppressions file (which also suppresses a
false positive in libunistring).

[-- Attachment #2: guile.supp --]
[-- Type: application/octet-stream, Size: 212 bytes --]

{
  <gc1>
  Memcheck:Cond
  fun:GC_*
}
{
  <gc2>  
  Memcheck:Value8
  fun:GC_*
}
# False positive: freea knowingly accesses uninitialized memory
{
  libunistring_freea
  Memcheck:Cond
  fun:libunistring_freea
}

[-- Attachment #3: valgrind.patch --]
[-- Type: application/octet-stream, Size: 2023 bytes --]

diff --git a/libguile/gc.c b/libguile/gc.c
index fc405f3..b531b85 100644
--- a/libguile/gc.c
+++ b/libguile/gc.c
@@ -617,6 +617,28 @@ scm_getenv_int (const char *var, int def)
 void
 scm_storage_prehistory ()
 {
+  /* libgc seems to obtain the stack address from the kernel on
+  linux/freebsd. this gives it valgrind's stack address, which it
+  then scans, causing a segmentation fault. this sets GC_stackbottom
+  to the address that valgrind wants the program to use */
+#if HAVE_PTHREAD_ATTR_GETSTACK && HAVE_PTHREAD_GETATTR_NP
+  size_t size;
+  void* sstart;
+  pthread_attr_t attr;
+  pthread_getattr_np(pthread_self(), &attr);
+  pthread_attr_getstack(&attr, &sstart, &size);
+  pthread_attr_destroy(&attr);
+  if(sstart) {
+    GC_stackbottom = (char*) sstart + size;
+  } else {
+    int dummy;
+    size_t stack_bottom = (size_t) & dummy;
+    stack_bottom += 4095;
+    stack_bottom &= ~4095;
+    GC_stackbottom = (char*) stack_bottom;
+  }
+#endif
+
   GC_all_interior_pointers = 0;
   GC_set_free_space_divisor (scm_getenv_int ("GC_FREE_SPACE_DIVISOR", 3));
 
@@ -813,7 +835,6 @@ scm_i_tag_name (scm_t_bits tag)
 
 
 
-\f
 void
 scm_init_gc ()
 {
diff --git a/libguile/threads.c b/libguile/threads.c
index 7c377d7..e052f47 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -632,6 +632,7 @@ scm_i_init_thread_for_guile (SCM_STACKITEM *base, SCM parent)
 static SCM_STACKITEM *
 get_thread_stack_base ()
 {
+  SCM_STACKITEM* ret;
   pthread_attr_t attr;
   void *start, *end;
   size_t size;
@@ -647,16 +648,18 @@ get_thread_stack_base ()
 
 #ifndef PTHREAD_ATTR_GETSTACK_WORKS
   if ((void *)&attr < start || (void *)&attr >= end)
-    return (SCM_STACKITEM *) GC_stackbottom;
+    ret = (SCM_STACKITEM*) GC_stackbottom;
   else
 #endif
     {
 #if SCM_STACK_GROWS_UP
-      return start;
+      ret = (SCM_STACKITEM*) start;
 #else
-      return end;
+      ret = (SCM_STACKITEM*) end;
 #endif
     }
+  pthread_attr_destroy(&attr);
+  return ret;
 }
 
 #elif defined HAVE_PTHREAD_GET_STACKADDR_NP

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Valgrind fix
@ 2010-03-07 22:53 No Itisnt
  0 siblings, 0 replies; 7+ messages in thread
From: No Itisnt @ 2010-03-07 22:53 UTC (permalink / raw)
  To: guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 566 bytes --]

Here is patch that allows valgrind to run Guile under Linux non-IA64
architectures. It also fixes a potential leak in threads.c where a pthread
attribute was not destroyed.

Note that libgc still generates lots of warnings. For now, I've just been
suppressing all warnings from libgc, and I'm happy to report that Guile
doesn't seem to cause any issues on my system (Linux/AMD64). But it's
certainly possible that the suppressions could mask a legitimate issue.

Attached are the patch and suppressions file (which also suppresses a false
positive in libunistring).

[-- Attachment #1.2: Type: text/html, Size: 605 bytes --]

[-- Attachment #2: guile.supp --]
[-- Type: application/octet-stream, Size: 212 bytes --]

{
  <gc1>
  Memcheck:Cond
  fun:GC_*
}
{
  <gc2>  
  Memcheck:Value8
  fun:GC_*
}
# False positive: freea knowingly accesses uninitialized memory
{
  libunistring_freea
  Memcheck:Cond
  fun:libunistring_freea
}

[-- Attachment #3: valgrind.patch --]
[-- Type: application/octet-stream, Size: 2023 bytes --]

diff --git a/libguile/gc.c b/libguile/gc.c
index fc405f3..b531b85 100644
--- a/libguile/gc.c
+++ b/libguile/gc.c
@@ -617,6 +617,28 @@ scm_getenv_int (const char *var, int def)
 void
 scm_storage_prehistory ()
 {
+  /* libgc seems to obtain the stack address from the kernel on
+  linux/freebsd. this gives it valgrind's stack address, which it
+  then scans, causing a segmentation fault. this sets GC_stackbottom
+  to the address that valgrind wants the program to use */
+#if HAVE_PTHREAD_ATTR_GETSTACK && HAVE_PTHREAD_GETATTR_NP
+  size_t size;
+  void* sstart;
+  pthread_attr_t attr;
+  pthread_getattr_np(pthread_self(), &attr);
+  pthread_attr_getstack(&attr, &sstart, &size);
+  pthread_attr_destroy(&attr);
+  if(sstart) {
+    GC_stackbottom = (char*) sstart + size;
+  } else {
+    int dummy;
+    size_t stack_bottom = (size_t) & dummy;
+    stack_bottom += 4095;
+    stack_bottom &= ~4095;
+    GC_stackbottom = (char*) stack_bottom;
+  }
+#endif
+
   GC_all_interior_pointers = 0;
   GC_set_free_space_divisor (scm_getenv_int ("GC_FREE_SPACE_DIVISOR", 3));
 
@@ -813,7 +835,6 @@ scm_i_tag_name (scm_t_bits tag)
 
 
 
-\f
 void
 scm_init_gc ()
 {
diff --git a/libguile/threads.c b/libguile/threads.c
index 7c377d7..e052f47 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -632,6 +632,7 @@ scm_i_init_thread_for_guile (SCM_STACKITEM *base, SCM parent)
 static SCM_STACKITEM *
 get_thread_stack_base ()
 {
+  SCM_STACKITEM* ret;
   pthread_attr_t attr;
   void *start, *end;
   size_t size;
@@ -647,16 +648,18 @@ get_thread_stack_base ()
 
 #ifndef PTHREAD_ATTR_GETSTACK_WORKS
   if ((void *)&attr < start || (void *)&attr >= end)
-    return (SCM_STACKITEM *) GC_stackbottom;
+    ret = (SCM_STACKITEM*) GC_stackbottom;
   else
 #endif
     {
 #if SCM_STACK_GROWS_UP
-      return start;
+      ret = (SCM_STACKITEM*) start;
 #else
-      return end;
+      ret = (SCM_STACKITEM*) end;
 #endif
     }
+  pthread_attr_destroy(&attr);
+  return ret;
 }
 
 #elif defined HAVE_PTHREAD_GET_STACKADDR_NP

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-04-13 12:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-08  0:04 Valgrind fix No Itisnt
2010-03-08 18:49 ` No Itisnt
2010-03-08 21:21   ` Ludovic Courtès
2010-03-12 18:41     ` No Itisnt
2010-04-13 12:15       ` Ludovic Courtès
2010-03-08 21:16 ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2010-03-07 22:53 No Itisnt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).