[Gc] FreeBSD patches for the libgc include with Mono 1.0

John Merryweather Cooper john_m_cooper at yahoo.com
Fri Jul 30 12:13:12 PDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Note that I'm now a committer to the Mono Project, and I have committed more 
refined versions of the configure patches to both HEAD and mono-1-0.

jmc

On Friday 16 July 2004 04:09 pm, John Merryweather Cooper wrote:
> I'm the FreeBSD maintainer for mono and I've finally gotten a
> reasonable, working mono on FreeBSD (at least on -CURRENT, FreeBSD
> 5.2).  In the hopes that some of this might get integrated into the next
> release (and make my job a little easier), I've attached the patches
> necessary to get Mono 1.0 working.  In particular, there are several
> patches necessary for libgc to function.  All of these patches can be
> had via cvsweb at:
>
> http://www.freebsd.org/cgi/cvsweb.cgi/ports/lang/mono/files/
>
> SOME COMMENTS:
>
> #####
> # patch-ligbc_Makefile.in
> #####
>
> Avoid building the documentation since all the tools haven't been
> ported, etc.
>
> #####
> # patch-ligbc_configure
> #####
>
> The build environment in the FreeBSD Ports system defines two
> environment variables:  PTHREAD_CFLAGS and PTHREAD_LIBS.  The contents
> of these two environments vary depending on the FreeBSD version,
> particularly in FreeBSD 5.x (aka -CURRENT).  Rather than take a guess
> and hard-code these values in configure, it's safer to use the values
> directly to ensure the the proper compiler flags are sent for each
> version.  That's particularly important now for -CURRENT because there's
> just enough TLS support in the compiler to fool configure into thinking
> -CURRENT can do TLS (it can't yet--probably not until the import of GCC
> 3.4.x is completed).  In running the top-level mono configure, I still
> need to disable TLS by sending --with-nptl=no or the resulting mono will
> hang.  See the Makefile at:
>
> http://www.freebsd.org/cgi/cvsweb.cgi/ports/lang/mono/Makefile
>
>
> #####
> # patch-libgc_dbg_mlc.c
> #####
>
> Patch so GC at least somewhat works.
>
> #####
> # patch-libgc_dyn_load.c
> #####
>
> FreeBSD exists on both 32 and 64 bit platforms, so make allowances for
> this.
>
> #####
> # patch-libgc_include_private_gcconfig.h
> #####
>
> Remap signals to something sensible for FreeBSD.  Also note that the
> Alpha platform has issues with MPROTECT_VDB.
>
> #####
> # patch-libgc_ltmain.sh
> #####
>
> Don't explicitly include libc in linking.  Also handle -pthread for
> -STABLE.  Also handle allergy that some have to the installation of *.la
> files.
>
> #####
> # patch-libgc_os_dep.c
> #####
>
> More signal handling stuff gets fixed.
>
> #####
> # patch-libgc_threadlibs.c
> #####
>
> Whether -pthread or -lpthread is needed depends on the OS Version.  Map
> it accordingly.
>
> Any questions?  Please ask.  :)
>
> jmc
>
> <------------------------FREEBSD PATCHES BEGIN---------------------->
>
> #####
> # patch-ligbc_Makefile.in
> #####
> --- libgc/Makefile.in.orig      Sat Jun 12 15:40:48 2004
> +++ libgc/Makefile.in   Sat Jun 12 15:41:15 2004
> @@ -120,7 +120,7 @@
>
>  AUTOMAKE_OPTIONS = foreign
>
> -SUBDIRS = include doc
> +SUBDIRS = include
>
>  noinst_LTLIBRARIES = libmonogc.la
>
> #####
> # patch-libgc_configure
> #####
> --- libgc/configure.bak Tue Jun 29 06:29:58 2004
> +++ libgc/configure     Wed Jul  7 22:43:28 2004
> @@ -3686,8 +3686,8 @@
>  #define GC_FREEBSD_THREADS 1
>  _ACEOF
>
> -       INCLUDES="$INCLUDES -pthread"
> -       THREADLIBS=-pthread
> +       INCLUDES="$INCLUDES $PTHREAD_CFLAGS"
> +       THREADLIBS="$PTHREAD_LIBS"
>         ;;
>       *-*-solaris*)
>         cat >>confdefs.h <<\_ACEOF
>
> #####
> # patch-libgc_dbg_mlc.c
> #####
> --- libgc/dbg_mlc.c.orig        Tue May 13 16:59:49 2003
> +++ libgc/dbg_mlc.c     Wed May 12 20:13:19 2004
> @@ -414,6 +414,23 @@
>      GC_register_displacement((word)sizeof(oh) + offset);
>  }
>
> +#if defined(__FreeBSD__)
> +#include <dlfcn.h>
> +static void GC_caller_func_offset(ad, symp, offp)
> +const GC_word ad;
> +const char **symp;
> +int *offp;
> +{
> +    Dl_info caller;
> +    if (dladdr((const void *)ad, &caller) && caller.dli_sname != NULL)
> {
> +      *symp = caller.dli_sname;
> +      *offp = (const char *)ad - (const char *)caller.dli_saddr;
> +    }
> +}
> +#else
> +#define GC_caller_func(ad, symp, offp)
> +#endif
> +
>  # ifdef __STDC__
>      GC_PTR GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS)
>  # else
> @@ -428,6 +445,13 @@
>  {
>      GC_PTR result = GC_malloc(lb + DEBUG_BYTES);
>
> +#ifdef GC_ADD_CALLER
> +    if (s == NULL) {
> +      GC_caller_func_offset(ra, &s, &i);
> +      if (s == NULL)
> +        s = "unknown";
> +    }
> +#endif
>      if (result == 0) {
>          GC_err_printf1("GC_debug_malloc(%ld) returning NIL (",
>                        (unsigned long) lb);
> @@ -789,6 +813,13 @@
>      register size_t old_sz;
>      register hdr * hhdr;
>
> +#ifdef GC_ADD_CALLER
> +    if (s == NULL) {
> +      GC_caller_func_offset(ra, &s, &i);
> +      if (s == NULL)
> +        s = "unknown";
> +    }
> +#endif
>      if (p == 0) return(GC_debug_malloc(lb, OPT_RA s, i));
>      if (base == 0) {
>          GC_err_printf1(
> @@ -1094,7 +1125,11 @@
>  }
>
>  #ifdef GC_ADD_CALLER
> -# define RA GC_RETURN_ADDR,
> +# ifdef GC_RETURN_ADDR_PARENT
> +#  define RA GC_RETURN_ADDR_PARENT,
> +# else
> +#  define RA GC_RETURN_ADDR,
> +# endif
>  #else
>  # define RA
>  #endif
> @@ -1102,12 +1137,12 @@
>  GC_PTR GC_debug_malloc_replacement(lb)
>  size_t lb;
>  {
> -    return GC_debug_malloc(lb, RA "unknown", 0);
> +    return GC_debug_malloc(lb, RA NULL, 0);
>  }
>
>  GC_PTR GC_debug_realloc_replacement(p, lb)
>  GC_PTR p;
>  size_t lb;
>  {
> -    return GC_debug_realloc(p, lb, RA "unknown", 0);
> +    return GC_debug_realloc(p, lb, RA NULL, 0);
>  }
>
> #####
> # patch-libgc_dyn_load.c
> #####
> --- libgc/dyn_load.c.orig       Tue May 18 14:42:19 2004
> +++ libgc/dyn_load.c    Sat Jun 12 15:23:33 2004
> @@ -91,6 +91,13 @@
>  /* Newer versions of GNU/Linux define this macro.  We
>   * define it similarly for any ELF systems that don't.  */
>  #  ifndef ElfW
> +#ifdef __FreeBSD__
> +#if __ELF_WORD_SIZE == 32
> +#define ElfW(type) Elf32_##type
> +#else
> +#define ElfW(type) Elf64_##type
> +#endif
> +#else
>  #    ifdef __NetBSD__
>  #      if ELFSIZE == 32
>  #        define ElfW(type) Elf32_##type
> @@ -104,6 +111,7 @@
>  #        define ElfW(type) Elf64_##type
>  #      endif
>  #    endif
> +#endif
>  #  endif
>
>  #if defined(SUNOS5DL) && !defined(USE_PROC_FOR_LIBRARIES)
>
> #####
> # patch-libgc_include_private_gcconfig.h
> #####
> --- libgc/include/private/gcconfig.h.orig       Mon Oct  6 22:38:35 2003
> +++ libgc/include/private/gcconfig.h    Mon Oct  6 22:38:56 2003
> @@ -1151,8 +1151,8 @@
>  #      ifndef GC_FREEBSD_THREADS
>  #          define MPROTECT_VDB
>  #      endif
> -#      define SIG_SUSPEND SIGUSR1
> -#      define SIG_THR_RESTART SIGUSR2
> +#      define SIG_SUSPEND SIGTSTP
> +#      define SIG_THR_RESTART SIGCONT
>  #      define FREEBSD_STACKBOTTOM
>  #      ifdef __ELF__
>  #          define DYNAMIC_LOADING
> @@ -1466,8 +1466,8 @@
>  #   ifdef FREEBSD
>  #      define OS_TYPE "FREEBSD"
>  /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
> -#      define SIG_SUSPEND SIGUSR1
> -#      define SIG_THR_RESTART SIGUSR2
> +#      define SIG_SUSPEND SIGTSTP
> +#      define SIG_THR_RESTART SIGCONT
>  #      define FREEBSD_STACKBOTTOM
>  #      ifdef __ELF__
>  #          define DYNAMIC_LOADING
>
> #####
> # patch-libgc_ltmain.sh
> #####
> --- libgc/ltmain.sh.orig        Mon Mar 31 09:34:30 2003
> +++ libgc/ltmain.sh     Sat Jun 12 15:23:56 2004
> @@ -1060,8 +1060,16 @@
>         continue
>         ;;
>
> +      -pthread)
> +      compile_command="$compile_command -pthread"
> +      finalize_command="$finalize_command -pthread"
> +      compiler_flags="$compiler_flags -pthread"
> +      continue
> +      ;;
> +
>        -module)
>         module=yes
> +       build_old_libs=no
>         continue
>         ;;
>
> @@ -2444,6 +2452,9 @@
>           *-*-openbsd*)
>             # Do not include libc due to us having libc/libc_r.
>             ;;
> +         *-*-freebsd*)
> +           # FreeBSD doesn't need this...
> +           ;;
>           *)
>             # Add libc to deplibs on all other systems if necessary.
>             if test $build_libtool_need_lc = "yes"; then
> @@ -4210,10 +4221,12 @@
>         fi
>
>         # Install the pseudo-library for information purposes.
> +       if /usr/bin/false; then
>         name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
>         instname="$dir/$name"i
>         $show "$install_prog $instname $destdir/$name"
>         $run eval "$install_prog $instname $destdir/$name" || exit $?
> +       fi
>
>         # Maybe install the static library, too.
>         test -n "$old_library" && staticlibs="$staticlibs
> $dir/$old_library"
>
> #####
> # patch-libgc_os_dep.c
> #####
> --- libgc/os_dep.c.orig Sat Jun 12 17:10:31 2004
> +++ libgc/os_dep.c      Sat Jun 12 17:12:42 2004
> @@ -700,10 +700,10 @@
>  #   endif
>
>  #   if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
> -    || defined(HURD) || defined(NETBSD)
> +    || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
>         static struct sigaction old_segv_act;
>  #      if defined(_sigargs) /* !Irix6.x */ || defined(HPUX) \
> -       || defined(HURD) || defined(NETBSD)
> +       || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
>             static struct sigaction old_bus_act;
>  #      endif
>  #   else
> @@ -718,7 +718,7 @@
>  #   endif
>      {
>  #      if defined(SUNOS5SIGS) || defined(IRIX5)  \
> -        || defined(OSF1) || defined(HURD) || defined(NETBSD)
> +        || defined(OSF1) || defined(HURD) || defined(NETBSD) ||
> defined(FREEBSD)
>           struct sigaction      act;
>
>           act.sa_handler        = h;
> @@ -738,7 +738,7 @@
>  #        else
>                 (void) sigaction(SIGSEGV, &act, &old_segv_act);
>  #              if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not
> 6.x */ \
> -                  || defined(HPUX) || defined(HURD) || defined(NETBSD)
> +                  || defined(HPUX) || defined(HURD) || defined(NETBSD)
>
> defined(FREEBSD)
>                     /* Under Irix 5.x or HP/UX, we may get
> SIGBUS.      */
>                     /* Pthreads doesn't exist under Irix 5.x, so
> we     */
>                     /* don't have to worry in the threads
> case.         */
> @@ -774,10 +774,10 @@
>      void GC_reset_fault_handler()
>      {
>  #       if defined(SUNOS5SIGS) || defined(IRIX5) \
> -          || defined(OSF1) || defined(HURD) || defined(NETBSD)
> +          || defined(OSF1) || defined(HURD) || defined(NETBSD) ||
> defined(FREEBSD)
>           (void) sigaction(SIGSEGV, &old_segv_act, 0);
>  #        if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */
> \
> -            || defined(HPUX) || defined(HURD) || defined(NETBSD)
> +            || defined(HPUX) || defined(HURD) || defined(NETBSD) ||
> defined(FREEBSD)
>               (void) sigaction(SIGBUS, &old_bus_act, 0);
>  #        endif
>  #       else
>
> #####
> # patch-libgc_threadlibs.c
> #####
> --- libgc/threadlibs.c.orig     Wed Jul  7 22:57:48 2004
> +++ libgc/threadlibs.c  Wed Jul  7 23:05:12 2004
> @@ -1,5 +1,6 @@
>  # include "private/gcconfig.h"
>  # include <stdio.h>
> +# include <sys/param.h>
>
>  int main()
>  {
> @@ -12,7 +13,11 @@
>  #   if defined(GC_LINUX_THREADS) || defined(GC_IRIX_THREADS) \
>
>         || defined(GC_FREEBSD_THREADS) || defined(GC_SOLARIS_PTHREADS) \
>         || defined(GC_DARWIN_THREADS) || defined(GC_AIX_THREADS)
>
> +#       if (__FREEBSD_version >= 500000)
>          printf("-lpthread\n");
> +#       else
> +       printf("-pthread\n");
> +#       endif
>  #   endif
>  #   if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS)
>         printf("-lpthread -lrt\n");
>
> <-------------------------FREEBSD PATCHES END----------------------->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFBCp3QvBSBfjNhsrIRAtSJAJ0Q/qOvlW0cx9f+InznPBM/XI0uswCgg5JZ
0TTa38FbEjd7LzlegGhplZY=
=vGtS
-----END PGP SIGNATURE-----


More information about the Gc mailing list