[PATCH] FreeBSD patches for dump/restore/load

From: Amancio Hasty Jr <hasty_at_netcom.com>
Date: Tue, 13 Dec 1994 22:31:07 -0800

The following are the patches necessary to allow dynamic loading of modules,
dump/restore the current state of the scheme interpreter.
All patches where done against STk-2.1.4.

My FreeBSD OS version 1.1.5.

I use gnu's make so the patch to change the include directive in
the make files is not neeeded.

To apply the patches :
(1) cd to your root STk directory
(2) patch -p <patch
(3) ./configure
(4) edit Extensions/Makefile and take out the reference to ALLOC:
CFLAGS= $(SHLIB_CCFLAGS) $(STKCFLAGS) $(ALLOC) $(DFLGS) -DUSE_TK \
                                      ^^^^^^^^ just delete it.
(5) make

Caveat:

The FreeBSD dlopen library call does not search the standard library
directories so you have to specify the full pathname of the dynamic
module. This problem can be fixed for FreeBSD but I am running out
of time.

Example:
 /usr/local/scheme/STk-hacked/Src > stk
Welcome to the STk interpreter version 2.1.4
Copyright (C) 1993, 1994 Erick Gallesio - I3S - CNRS / UNSA <eg_at_unice.fr>
STk> (load "/usr/local/lib/stk/process")
#[undefined]
STk> (run-process)

*** Error:
run_process: no command given
STk> (run-process "ls")
#<process 9e684>
STk> #dump.c# gf.c sport.o
#dynload.c# gf.h sregexp.c
Makefile globals.c stk
...


Currently, we can not dump and image which has a dynamically loaded
module. One of these days I will try to figure why stk is core dumping
when it tries to reference symbol of a dynamic module from a saved sate.


Here is a sample session of a dump/restore:

Welcome to the STk interpreter version 2.1.4
Copyright (C) 1993, 1994 Erick Gallesio - I3S - CNRS / UNSA <eg_at_unice.fr>
STk> (load "sort.scm")
#[undefined]
STk> (load "associators.ss")
#[undefined]
STk> (load "lalr.ss")
#[undefined]
STk> (load "lalr-test.ss")
(#[undefined]
STk> ^U
(eval-string "1 + 3 * 5")
16
STk> (dump "save")
#[undefined]
STk> (exit)
 /usr/local/scheme/code/lalr > stk -image save
Welcome to the STk interpreter version 2.1.4
Copyright (C) 1993, 1994 Erick Gallesio - I3S - CNRS / UNSA <eg_at_unice.fr>
STk> (eval-string "1 + 3 * 5")
16
STk>


        Thats All Folks :)
        Amancio


-------------------------------cut-here-----------------------------------
*** configure Wed Nov 9 08:04:21 1994
--- ../STk-hacked/configure Tue Dec 13 15:03:30 1994
***************
*** 448,453 ****
--- 448,455 ----
  case $OS in
    SUNOS4) HAVE_DYNLOAD=yes;
              echo " (System supports dynamic loading)";;
+ FREEBSD) HAVE_DYNLOAD=yes;
+ echo " (System supports dynamic loading)";;
    *) echo "" ;;
  esac
  
***************
*** 474,480 ****
  SHLIB_LDFLAGS="";
  SHLIB_LOADER=":";
  SHLIB_SUFFIX="";
!
  case $OS in
    SUNOS4)
       SHLIB_CCFLAGS="-pic"
--- 476,482 ----
  SHLIB_LDFLAGS="";
  SHLIB_LOADER=":";
  SHLIB_SUFFIX="";
! LIB_MALLOC="";
  case $OS in
    SUNOS4)
       SHLIB_CCFLAGS="-pic"
***************
*** 491,499 ****
       SHLIB_LDFLAGS="-shared"
       SHLIB_LOADER="$CC"
       SHLIB_SUFFIX='.so' ;;
     *) echo "Don't know how to make shared libraries for $OS" ;;
  esac
!
  if test ! -z "SHLIB_CCFLAGS" ; then
     if test "$CC" = "gcc" ; then
        SHLIB_CCFLAGS="-fpic"
--- 493,507 ----
       SHLIB_LDFLAGS="-shared"
       SHLIB_LOADER="$CC"
       SHLIB_SUFFIX='.so' ;;
+ FREEBSD)
+ SHLIB_CCFLAGS="-pic"
+ SHLIB_LDFLAGS="-Bshareable"
+ SHLIB_LOADER="ld"
+ LIB_MALLOC="/usr/lib/libgnumalloc.a"
+ SHLIB_SUFFIX='.so';;
     *) echo "Don't know how to make shared libraries for $OS" ;;
  esac
! echo $LIB_MALLOC
  if test ! -z "SHLIB_CCFLAGS" ; then
     if test "$CC" = "gcc" ; then
        SHLIB_CCFLAGS="-fpic"
***************
*** 1073,1078 ****
--- 1081,1087 ----
  SHLIB_LDFLAGS='$SHLIB_LDFLAGS'
  SHLIB_LOADER='$SHLIB_LOADER'
  SHLIB_SUFFIX='$SHLIB_SUFFIX'
+ LIB_MALLOC='$LIB_MALLOC'
  MP='$MP'
  DYNLOAD='$DYNLOAD'
  EXTRA_OBJ='$EXTRA_OBJ'
***************
*** 1141,1146 ****
--- 1150,1156 ----
  s%_at_SHLIB_LDFLAGS@%$SHLIB_LDFLAGS%g
  s%_at_SHLIB_LOADER@%$SHLIB_LOADER%g
  s%_at_SHLIB_SUFFIX@%$SHLIB_SUFFIX%g
+ s%_at_LIB_MALLOC@%$LIB_MALLOC%g
  s%_at_MP@%$MP%g
  s%_at_DYNLOAD@%$DYNLOAD%g
  s%_at_EXTRA_OBJ@%$EXTRA_OBJ%g
***************
*** 1187,1197 ****
  # FreeBsd seems to use an old syntax for inclusion in Makefile. Patch
  # Makefiles acordingly
  
! case $OS in
! FREEBSD) for i in */Makefile
! do
! sed <$i > X$$X 's%include ../config.make%.include "../config.make"%'
! mv X$$X $i
! done;;
! *) ;;
! esac
--- 1197,1207 ----
  # FreeBsd seems to use an old syntax for inclusion in Makefile. Patch
  # Makefiles acordingly
  
! #case $OS in
! # FREEBSD) for i in */Makefile
! # do
! # sed <$i > X$$X 's%include ../config.make%.include "../config.make"%'
! # mv X$$X $i
! # done;;
! # *) ;;
! #esac
*** Makefile.in Fri Oct 28 03:24:04 1994
--- ../STk-hacked/Makefile.in Tue Dec 13 14:57:55 1994
***************
*** 15,20 ****
--- 15,21 ----
  INSTALL_DATA = _at_INSTALL_DATA@
  RANLIB = _at_RANLIB@
  
+
  MP = _at_MP@.a
  
  all: start config.make tcl tk mp src stklos ext stop
***************
*** 56,61 ****
--- 57,63 ----
          _at_echo "SHLIB_LOADER = @SHLIB_LOADER@" >> config.make
          _at_echo "SHLIB_SUFFIX = @SHLIB_SUFFIX@" >> config.make
          _at_echo "STK_LIBRARY = $(libdir)" >> config.make
+ _at_echo "LIB_MALLOC = @LIB_MALLOC@" >> config.make
  
  
  tcl:
*** Src/dump.c Fri Sep 2 03:43:24 1994
--- ../STk-hacked/Src/dump.c Tue Dec 13 13:57:40 1994
***************
*** 24,30 ****
  
  int dumped_core = 0;
  
! #ifdef SUNOS4
  static caddr_t current_break = (caddr_t) -1;
  static long data_size = 0;
  static long data_start = 0;
--- 24,30 ----
  
  int dumped_core = 0;
  
! #if defined (SUNOS4) || defined(FREEBSD)
  static caddr_t current_break = (caddr_t) -1;
  static long data_size = 0;
  static long data_start = 0;
*** Src/dynload.c Tue Dec 13 17:34:29 1994
--- ../STk-hacked/Src/dynload.c Tue Dec 13 14:21:13 1994
***************
*** 103,112 ****
  /******************************************************************************/
  
  
! #if defined(SUNOS4) || defined(SUNOS5)
!
  /* Following code works on SunOS 4/5. This code should also work on OSF-1.
! * But I can't test it myself.
   */
  
  static SCM list_of_files = NULL;
--- 103,112 ----
  /******************************************************************************/
  
  
! #if defined(SUNOS4) || defined(SUNOS5) || defined(FREEBSD)
! /* modified to work for FreeBSD */
  /* Following code works on SunOS 4/5. This code should also work on OSF-1.
! * But I can't test it myself.
   */
  
  static SCM list_of_files = NULL;
***************
*** 116,121 ****
--- 116,127 ----
    void *handle;
    void (*init_fct)();
    SCM str;
+ #ifdef FREEBSD
+ char s[1024];
+ s[0] = '_';
+ strcpy(s + 1, fct_name);
+ fct_name = s;
+ #endif
  
    /* Test if fct_name is already defined in the core interpreter */
    if ((handle = dlopen(NULL, 1)) == NULL) err("Cannot open myself !!!", NIL);
***************
*** 139,145 ****
--- 145,155 ----
    if ((handle = dlopen(path, 1)) == NULL) {
      char msg[MAX_PATH_LENGTH];
      
+ #ifndef FREEBSD
      sprintf(msg, "Cannot open object file (%s)", dlerror());
+ #else
+ sprintf(msg, "Cannot open object file ");
+ #endif
      err(msg, str);
    }
    
*** Src/Makefile.in Wed Nov 9 05:48:22 1994
--- ../STk-hacked/Src/Makefile.in Tue Dec 13 14:36:42 1994
***************
*** 60,66 ****
  
  stk-bin: userinit.o libstk.a $(ALLIBS)
          /bin/rm -f stk-bin
! $(CC) $(CFLAGS) -o stk-bin userinit.o libstk.a $(ALLIBS) $(XLIBSW) $(LIBS)
  
  libstk.a: $(OBJ)
          /bin/rm -f libstk.a
--- 60,66 ----
  
  stk-bin: userinit.o libstk.a $(ALLIBS)
          /bin/rm -f stk-bin
! $(CC) $(CFLAGS) -o stk-bin userinit.o libstk.a $(ALLIBS) $(XLIBSW) $(LIBS) $(LIB_MALLOC)
  
  libstk.a: $(OBJ)
          /bin/rm -f libstk.a
*** Src/unix.c Tue Dec 13 21:11:07 1994
--- ../STk-hacked/Src/unix.c Tue Dec 13 21:10:17 1994
***************
*** 114,120 ****
--- 114,127 ----
   
    if (*exec == '/') strncpy(path, exec, MAX_PATH_LENGTH);
  
+ #ifdef FREEBSD
+ if (access(path, X_OK) == 0) {
+ stat(path, &buf);
+ if (!S_ISDIR(buf.st_mode)) return;
+ }
+ #endif
    p = getenv("PATH");
+
    while (*p) {
      /* Copy the stuck of path in dir */
      for (q = dir; *p && *p != ':'; p++, q++) *q = *p;
Received on Wed Dec 14 1994 - 07:32:14 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST