Re: [fedora-java] rssowl: libgcj bugs that need fixing for it to run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2005-07-03 at 12:08 -0600, Tom Tromey wrote:
> Robin>  2. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13212
> Robin> "AttachCurrentThread() not working"
> 
> This one looks hard.  The GC likes to intercept some pthread calls in
> order to do things like add the new stacks to the root set.  Maybe
> there is some way we can make this work for Linux though.

The attached trick appears to work.  Rather than wrap the pthread_create
symbol, we override it with our own implementation and then use a glibc
runtime linker trick to get a pointer to the real pthread_create.

I can work up a submittable patch if you're in agreement with the
general approach.

AG


Index: boehm-gc/pthread_support.c
===================================================================
RCS file: /cvs/gcc/gcc/boehm-gc/pthread_support.c,v
retrieving revision 1.2
diff -u -p -r1.2 pthread_support.c
--- boehm-gc/pthread_support.c	13 Aug 2004 23:05:30 -0000	1.2
+++ boehm-gc/pthread_support.c	4 Jul 2005 01:37:10 -0000
@@ -44,7 +44,10 @@
  * + #  define GC_LOCK_TAKEN GC_allocate_lock
  */
 
-/*#define DEBUG_THREADS 1*/
+#define _GNU_SOURCE
+#include <dlfcn.h>
+
+#define DEBUG_THREADS 1
 /*#define GC_ASSERTIONS*/
 
 # include "gc.h"
@@ -1194,8 +1197,24 @@ void * GC_start_routine(void * arg)
     return(result);
 }
 
+/* Force constr to execute prior to main().  */
+static void constr (void) __attribute__ ((constructor));
+
+static int
+(*pthread_create_)(pthread_t *new_thread,
+		   const pthread_attr_t *attr_in,
+		   void * (*thread_execp)(void *), void *arg);
+
+static void
+constr (void)
+{
+  /* Get a pointer to the real pthread_create.  */
+  pthread_create_ = dlsym (RTLD_NEXT, "pthread_create");
+}
+
 int
-WRAP_FUNC(pthread_create)(pthread_t *new_thread,
+pthread_create (pthread_t *new_thread,
 		  const pthread_attr_t *attr,
                   void *(*start_routine)(void *), void *arg)
 {
@@ -1250,7 +1269,7 @@ WRAP_FUNC(pthread_create)(pthread_t *new
 		   pthread_self());
 #   endif
 
-    result = REAL_FUNC(pthread_create)(new_thread, attr, GC_start_routine, si);
+	result = (*pthread_create_)(new_thread, attr, GC_start_routine, si);
 
 #   ifdef DEBUG_THREADS
         GC_printf1("Started thread 0x%X\n", *new_thread);
Index: boehm-gc/include/gc_pthread_redirects.h
===================================================================
RCS file: /cvs/gcc/gcc/boehm-gc/include/gc_pthread_redirects.h,v
retrieving revision 1.4
diff -u -p -r1.4 gc_pthread_redirects.h
--- boehm-gc/include/gc_pthread_redirects.h	28 Jul 2003 04:18:23 -0000	1.4
+++ boehm-gc/include/gc_pthread_redirects.h	4 Jul 2005 01:37:10 -0000
@@ -67,8 +67,8 @@
 # undef pthread_join
 # undef pthread_detach
 #endif
-
-# define pthread_create GC_pthread_create
+// Test new pthread_create wrapping mechanism.
+// # define pthread_create GC_pthread_create
 # define pthread_join GC_pthread_join
 # define pthread_detach GC_pthread_detach
 

[Index of Archives]     [Red Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux