dynload.c patch to enable dynamic loading on HP-UX

From: Dipankar Gupta <dg_at_hplb.hpl.hp.com>
Date: Fri, 30 Sep 1994 17:51:03 +0100

The following patch to STk 2.1 enables dynamic loading on HP-UX. Run
with patch -p5 to throw away the absolute paths in the diff. Note that
in order for this to work, the binary should be linked with the -Wl,-E
option to make all symbols in the object exportable, and all
extensions should be compiled using the +Z option of the C compiler,
and a shared library created using ld -b. Patches to the makefiles in
Src/ and Extensions/ directories are also included.

Cheers,
--Dipankar

*** /users/dg/tools/STk-2.1/Src/dynload.c.~1~ Sat Mar 5 13:26:06 1994
--- /users/dg/tools/STk-2.1/Src/dynload.c Fri Sep 30 17:37:50 1994
***************
*** 26,31 ****
--- 26,34 ----
  #ifdef SUNOS4
  #include <dlfcn.h>
  #endif
+ #ifdef HPUX
+ # include <dl.h>
+ #endif /* HPUX */
  #include "stk.h"
  
  
***************
*** 103,111 ****
  
  /******************************************************************************/
  
  
! #if defined(SUNOS4) || defined(SUNOS5)
  
  /* Following code works on SunOS 4/5. But it require to use dynamic loading,
   * which in turn can not be used with dump.....
   *
--- 106,151 ----
  
  /******************************************************************************/
  
+ #ifdef HPUX
+ static void load_and_call(char *path, char *fct_name)
+ {
+ shl_t handle;
+ void (*init_fct)();
+
+ if ((handle = shl_load(path, BIND_IMMEDIATE | BIND_VERBOSE, 0L)) == NULL)
+ err("Cannot open file", makestrg(strlen(path), path));
+
+ handle = NULL;
+ if (shl_findsym(&handle, fct_name, TYPE_PROCEDURE, &init_fct) == -1) {
+ char msg[MAX_PATH_LENGTH];
+
+ sprintf(msg, "Cannot find function %s in object file", fct_name);
+ err(msg, NIL);
+ }
+ /* Call the init code */
+ (*init_fct)();
+ }
  
! void load_object_file(char *path)
! {
! char fct_name[MAX_PATH_LENGTH], *p, *slash, *dot;
  
+ /* Load the file as an object one */
+
+ for (p = path, slash = p-1; *p; p++) /* Find position of last '/' */
+ if (*p == '/') slash = p;
+
+ sprintf(fct_name, "init_%s", slash + 1);
+
+ for (p = fct_name; *p; p++) /* Delete suffix it it exists */
+ if (*p == '.') { *p = '\0'; break; }
+
+ load_and_call(path, fct_name);
+ }
+ #else
+
+ # if defined(SUNOS4) || defined(SUNOS5)
+
  /* Following code works on SunOS 4/5. But it require to use dynamic loading,
   * which in turn can not be used with dump.....
   *
***************
*** 146,158 ****
  
    load_and_call(path, fct_name);
  }
  
! #else
  void load_object_file(char *path)
  {
    err("load: Loading of object file is not defined on this architecture", NIL);
  }
! #endif
  
  
  /******************************************************************************/
--- 186,200 ----
  
    load_and_call(path, fct_name);
  }
+ #endif
  
! #if !(defined(SUNOS4) || defined(SUNOS5) || defined(HPUX))
  void load_object_file(char *path)
  {
    err("load: Loading of object file is not defined on this architecture", NIL);
  }
! # endif /* SUNOS */
! #endif /* HPUX */
  
  
  /******************************************************************************/

*** /users/dg/tools/STk-2.1/Extensions/Makefile.sun Wed Apr 6 21:39:33 1994
--- /users/dg/tools/STk-2.1/Extensions/Makefile.hp Fri Sep 30 17:04:33 1994
***************
*** 19,40 ****
  include ../config.make
  
  #define here how to obtain Position Independant Code (pic) with your compiler
! PIC = -fpic
  
  # Define here the extension you want to be defined
! EXT = hash.so time.so when.so
  
  CFLAGS= $(PIC) $(STKCFLAGS) -DUSE_TK -I../Tk -I../Tcl -I../Src $(XINCLUDES)
  
  ##############################################################################
! .SUFFIXES: .so .o .c
  
! .c.so:
          $(CC) -c $(CFLAGS) -o $*.o $<
! ld -assert pure-text -o $*.so $*.o
  
! .o.so:
! ld -assert pure-text -o $*.so $<
  ##############################################################################
  all: $(EXT)
  
--- 19,40 ----
  include ../config.make
  
  #define here how to obtain Position Independant Code (pic) with your compiler
! PIC = +Z
  
  # Define here the extension you want to be defined
! EXT = hash.sl time.sl when.sl
  
  CFLAGS= $(PIC) $(STKCFLAGS) -DUSE_TK -I../Tk -I../Tcl -I../Src $(XINCLUDES)
  
  ##############################################################################
! .SUFFIXES: .sl .o .c
  
! .c.sl:
          $(CC) -c $(CFLAGS) -o $*.o $<
! ld -b -o $*.sl $*.o
  
! .o.sl:
! ld -b -o $*.sl $<
  ##############################################################################
  all: $(EXT)
  
***************
*** 42,45 ****
          $(INSTALL) $(EXT) $(libdir)
  
  clean:
! _at_/bin/rm -f *.o *.so core *~
--- 42,45 ----
          $(INSTALL) $(EXT) $(libdir)
  
  clean:
! _at_/bin/rm -f *.o *.sl core *~
*** /users/dg/tools/STk-2.1/Src/Makefile.~1~ Fri Aug 5 17:29:38 1994
--- /users/dg/tools/STk-2.1/Src/Makefile Fri Sep 30 17:18:19 1994
***************
*** 66,72 ****
  
  stk-bin: $(OBJ) $(ALLIBS)
                  /bin/rm -f stk-bin
! $(CC) -o stk-bin $(OBJ) userinit.c $(ALLIBS) $(XLIBSW) $(LIBS)
  
  $(MPLIB):
          (cd ../Mp; make $(MP).a)
--- 66,72 ----
  
  stk-bin: $(OBJ) $(ALLIBS)
                  /bin/rm -f stk-bin
! $(CC) -g -Wl,-E -o stk-bin $(OBJ) userinit.c $(ALLIBS) $(XLIBSW) $(LIBS) -ldld
  
  $(MPLIB):
          (cd ../Mp; make $(MP).a)
Received on Fri Sep 30 1994 - 17:51:45 CET

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