[patch] add GNU/kFreeBSD support into boehm-gc

Petr Salinger Petr.Salinger@seznam.cz
Wed Jun 7 09:21:00 GMT 2006


Hi,

would be possible to merge GNU/kFreeBSD support in boehm-gc into gcc.
It gives reasonable results, see http://gcc.gnu.org/ml/java/2006-05/msg00093.html.

Those changes to boehm-gc have been just accepted by upstream,
http://www.hpl.hp.com/hosted/linux/mail-archives/gc/2006-June/001332.html

2006-06-07  Petr Salinger  <Petr.Salinger@seznam.cz>

         * configure.ac: add support for GNU/kFreeBSD, accepted by upstream for gc 6.8
         * dyn_load.c: Likewise.
         * include/gc.h: Likewise.
         * private/gcconfig.h: Likewise.
         * configure: Regenerate.
         * include/gc_config.h.in: Regenerate.


The only needed change outside boehm-gc to get gcj working is
to add support of GNU/kFreeBSD into shlibpath.m4.

The easiest way is (together with regenerate of configure):

--- libjava/shlibpath.m4~       2006-06-07 10:35:36.000000000 +0200
+++ libjava/shlibpath.m4        2006-06-07 10:35:36.000000000 +0200
@@ -361,7 +361,7 @@
    ;;

  # This must be Linux ELF.
-linux*)
+linux*|k*bsd*-gnu)
    version_type=linux
    need_lib_prefix=no
    need_version=no

Should I do anything else to get it included ?

Petr

-------------- next part --------------
diff -ur gcc-4.2-20060603.orig/boehm-gc/include/gc_config.h.in gcc-4.2-20060603/boehm-gc/include/gc_config.h.in
--- gcc-4.2-20060603.orig/boehm-gc/include/gc_config.h.in	2006-06-03 04:07:36.000000000 +0200
+++ gcc-4.2-20060603/boehm-gc/include/gc_config.h.in	2006-06-07 10:28:24.000000000 +0200
@@ -166,6 +166,9 @@
 /* define GC_local_malloc() & GC_local_malloc_atomic() */
 #undef THREAD_LOCAL_ALLOC
 
+/* use tls for boehm */
+#undef USE_COMPILER_TLS
+
 /* use MMAP instead of sbrk to get new memory */
 #undef USE_MMAP
 
diff -ur gcc-4.2-20060603.orig/boehm-gc/configure gcc-4.2-20060603/boehm-gc/configure
--- gcc-4.2-20060603.orig/boehm-gc/configure	2006-06-03 19:44:20.000000000 +0200
+++ gcc-4.2-20060603/boehm-gc/configure	2006-06-07 10:28:24.000000000 +0200
@@ -5444,6 +5444,32 @@
 	{ echo "$as_me:$LINENO: WARNING: \"Only HP-UX 11 POSIX threads are supported.\"" >&5
 echo "$as_me: WARNING: \"Only HP-UX 11 POSIX threads are supported.\"" >&2;}
 	;;
+      *-*-kfreebsd*-gnu)
+       cat >>confdefs.h <<\_ACEOF
+#define GC_FREEBSD_THREADS 1
+_ACEOF
+
+       INCLUDES="$INCLUDES -pthread"
+       THREADDLLIBS=-pthread
+       cat >>confdefs.h <<\_ACEOF
+#define _REENTRANT 1
+_ACEOF
+
+         if test "${enable_parallel_mark}" = yes; then
+         cat >>confdefs.h <<\_ACEOF
+#define PARALLEL_MARK 1
+_ACEOF
+
+       fi
+       cat >>confdefs.h <<\_ACEOF
+#define THREAD_LOCAL_ALLOC 1
+_ACEOF
+
+       cat >>confdefs.h <<\_ACEOF
+#define USE_COMPILER_TLS 1
+_ACEOF
+
+               ;;
      *-*-freebsd*)
 	{ echo "$as_me:$LINENO: WARNING: \"FreeBSD does not yet fully support threads with Boehm GC.\"" >&5
 echo "$as_me: WARNING: \"FreeBSD does not yet fully support threads with Boehm GC.\"" >&2;}
diff -ur gcc-4.2-20060603.orig/boehm-gc/configure.ac gcc-4.2-20060603/boehm-gc/configure.ac
--- gcc-4.2-20060603.orig/boehm-gc/configure.ac	2006-06-03 04:07:36.000000000 +0200
+++ gcc-4.2-20060603/boehm-gc/configure.ac	2006-06-07 10:28:24.000000000 +0200
@@ -155,6 +155,17 @@
      *-*-hpux10*)
 	AC_MSG_WARN("Only HP-UX 11 POSIX threads are supported.")
 	;;
+      *-*-kfreebsd*-gnu)
+       AC_DEFINE(GC_FREEBSD_THREADS)
+       INCLUDES="$INCLUDES -pthread"
+       THREADDLLIBS=-pthread
+       AC_DEFINE(_REENTRANT)
+         if test "${enable_parallel_mark}" = yes; then
+         AC_DEFINE(PARALLEL_MARK)
+       fi
+       AC_DEFINE(THREAD_LOCAL_ALLOC)
+       AC_DEFINE(USE_COMPILER_TLS, 1,[use tls for boehm])
+               ;;
      *-*-freebsd*)
 	AC_MSG_WARN("FreeBSD does not yet fully support threads with Boehm GC.")
 	AC_DEFINE(GC_FREEBSD_THREADS,1,[support FreeBSD threads])
diff -ur gcc-4.2-20060603.orig/boehm-gc/dyn_load.c gcc-4.2-20060603/boehm-gc/dyn_load.c
--- gcc-4.2-20060603.orig/boehm-gc/dyn_load.c	2006-04-24 15:40:21.000000000 +0200
+++ gcc-4.2-20060603/boehm-gc/dyn_load.c	2006-06-07 10:28:24.000000000 +0200
@@ -26,7 +26,7 @@
  * None of this is safe with dlclose and incremental collection.
  * But then not much of anything is safe in the presence of dlclose.
  */
-#if defined(__linux__) && !defined(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__GLIBC__)) && !defined(_GNU_SOURCE)
     /* Can't test LINUX, since this must be define before other includes */
 #   define _GNU_SOURCE
 #endif
@@ -392,7 +392,7 @@
 /* For glibc 2.2.4+.  Unfortunately, it doesn't work for older	*/
 /* versions.  Thanks to Jakub Jelinek for most of the code.	*/
 
-# if defined(LINUX) /* Are others OK here, too? */ \
+# if (defined(LINUX) || defined (__GLIBC__)) /* Are others OK here, too? */ \
      && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
          || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG))) 
 
diff -ur gcc-4.2-20060603.orig/boehm-gc/include/gc.h gcc-4.2-20060603/boehm-gc/include/gc.h
--- gcc-4.2-20060603.orig/boehm-gc/include/gc.h	2006-04-24 15:40:21.000000000 +0200
+++ gcc-4.2-20060603/boehm-gc/include/gc.h	2006-06-07 10:28:24.000000000 +0200
@@ -500,7 +500,7 @@
 #   define GC_RETURN_ADDR (GC_word)__return_address
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
 # include <features.h>
 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
      && !defined(__ia64__)
diff -ur gcc-4.2-20060603.orig/boehm-gc/include/private/gcconfig.h gcc-4.2-20060603/boehm-gc/include/private/gcconfig.h
--- gcc-4.2-20060603.orig/boehm-gc/include/private/gcconfig.h	2006-01-25 20:33:37.000000000 +0100
+++ gcc-4.2-20060603/boehm-gc/include/private/gcconfig.h	2006-06-07 10:29:34.000000000 +0200
@@ -55,7 +55,7 @@
 # endif
 
 /* And one for FreeBSD: */
-# if defined(__FreeBSD__) && !defined(FREEBSD)
+# if ( defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ) && !defined(FREEBSD)
 #    define FREEBSD
 # endif
 
@@ -1241,8 +1241,15 @@
 #	ifndef GC_FREEBSD_THREADS
 #	    define MPROTECT_VDB
 #	endif
-#	define SIG_SUSPEND SIGUSR1
-#	define SIG_THR_RESTART SIGUSR2
+#	ifdef __GLIBC__
+#	    define SIG_SUSPEND		(32+6)
+#	    define SIG_THR_RESTART	(32+5)
+	    extern int _end[];
+#	    define DATAEND (_end)
+#	else
+#	    define SIG_SUSPEND SIGUSR1
+#	    define SIG_THR_RESTART SIGUSR2
+#	endif
 #	define FREEBSD_STACKBOTTOM
 #	ifdef __ELF__
 #	    define DYNAMIC_LOADING
@@ -1952,6 +1959,28 @@
 #	    define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
 #	endif
 #   endif
+#   ifdef FREEBSD
+#	define OS_TYPE "FREEBSD"
+#	ifndef GC_FREEBSD_THREADS
+#	    define MPROTECT_VDB
+#	endif
+#	ifdef __GLIBC__
+#	    define SIG_SUSPEND		(32+6)
+#	    define SIG_THR_RESTART	(32+5)
+	    extern int _end[];
+#	    define DATAEND (_end)
+#	else
+#	    define SIG_SUSPEND SIGUSR1
+#	    define SIG_THR_RESTART SIGUSR2
+#	endif
+#	define FREEBSD_STACKBOTTOM
+#	ifdef __ELF__
+#	    define DYNAMIC_LOADING
+#	endif
+	extern char etext[];
+	extern char * GC_FreeBSDGetDataStart();
+#	define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
+#   endif
 #   ifdef NETBSD
 #	define OS_TYPE "NETBSD"
 #	ifdef __ELF__
@@ -2023,7 +2052,7 @@
 #   define SUNOS5SIGS
 # endif
 
-# if defined(FREEBSD) && (__FreeBSD__ >= 4)
+# if defined(FREEBSD) && ((__FreeBSD__ >= 4) || (__FreeBSD_kernel__ >= 4))
 #   define SUNOS5SIGS
 # endif
 
@@ -2086,7 +2115,7 @@
 #   define CACHE_LINE_SIZE 32	/* Wild guess	*/
 # endif
 
-# ifdef LINUX
+# if defined(LINUX) || defined(__GLIBC__)
 #   define REGISTER_LIBRARIES_EARLY
     /* We sometimes use dl_iterate_phdr, which may acquire an internal	*/
     /* lock.  This isn't safe after the world has stopped.  So we must	*/
@@ -2167,7 +2196,7 @@
 #if defined(SPARC)
 # define CAN_SAVE_CALL_ARGS
 #endif
-#if (defined(I386) || defined(X86_64)) && defined(LINUX)
+#if (defined(I386) || defined(X86_64)) && (defined(LINUX) || defined(__GLIBC__))
 	    /* SAVE_CALL_CHAIN is supported if the code is compiled to save	*/
 	    /* frame pointers by default, i.e. no -fomit-frame-pointer flag.	*/
 # define CAN_SAVE_CALL_ARGS


More information about the Gcc-patches mailing list