zsh-workers
 help / color / mirror / code / Atom feed
* Dealing with module envy under HPUX 10.20
@ 1998-12-16  2:20 Gene Cohler
  1998-12-16 16:12 ` PATCH: 3.1.5-pws-3: Dynamic loading under HPUX 10 Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Gene Cohler @ 1998-12-16  2:20 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1687 bytes --]


 Zsh Gurus:

   Suffering module envy can be a sad thing! I have tested the following
   which seems to get the modules stuff working fine under HPUX 10.20.
   (HPUX 11 comes pre-armed with dlopen() et al so it is not needed there).
    
   I am totally unfamiliar with the configure magic so I'm hoping someone
   who knows better can make that part more elegant so that module support
   for hpux 10 is supported out of the box.

   Heres what I did (against stock zsh-3.1.5):

   a) The important bits ...

     o Put the included dlfcn.h header file where it can be seen
       Obviously the macros could just as easily have been functions. 
       Be aware there is a global variable in here (zsh_gl_sym_addr)
       used as a temporary.
       These macros redefine the dlopen() suite in terms of the shl_load()
       type funcs.
     
   b) faking out configure coz I dont know any better ...

     o adjusted configure by changing

       void *symlist1 = {
       
       to

       void *symlist1[] = {

       Otherwise the test fails as the compile gives errors compiling
       the test proggie.

    o The test for presence of dlopen() needs to be faked out beacuse it 
      is in the header as a macro rather than a library. I simply created
      a little libdl.a with stub entries :

      int dlopen() { return(0);}
      int dlclose() { return(0);}
      int dlsym() { return(0);}
      int dlerror() { return(0);}

      cc -Aa +DAportable -c stubs.c; ar ruv libdl.a stubs.o

      Make sure the LDFLAGS see this library and also add -ldld

   o Make sure that for HPUX 10. we have a -DHPUX_10_DL compiler flag.













-- 
  Gene Cohler
  Bear Stearns & Co.

[-- Attachment #2: dlfcn.h --]
[-- Type: text/plain, Size: 1120 bytes --]

/*
 * HPUX 10.0 dynamic loader stuff
 * Not needed under HPUX 11.0 which has dlopen() etc.
 *
 * This header needs to be seen with -DHPUX_10_DL 
 *
 * Note: configure needs 
 *
 *    a)  void *symlist1 = { 
 *        changed to
 *        void *symlist1[] = {
 *
 *        Otherwise configure thinks dynamic stuff is broken.
 *
 *    b) The test for dlopen needs to be faked out 
 *       I created a dummy with stub entries for dlopen, dlerror and
 *       dlsym otherwise configure thinks there are no entries.
 *       There is probably a smarter way.
 *
 * Tested using HP' cc compiler under HPUX 10.20.
 * Compiled with -Aa +DAportable
 */

#if defined(HPUX_10_DL)   
#if !defined(DLFCN_INC)
#define DLFCN_INC 1

#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
#define dlerror() 0
#endif
#endif

^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: 3.1.5-pws-3: Dynamic loading under HPUX 10
  1998-12-16  2:20 Dealing with module envy under HPUX 10.20 Gene Cohler
@ 1998-12-16 16:12 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1998-12-16 16:12 UTC (permalink / raw)
  To: Gene Cohler, zsh-workers

Gene Cohler wrote:
>    Suffering module envy can be a sad thing! I have tested the following
>    which seems to get the modules stuff working fine under HPUX 10.20.
>    (HPUX 11 comes pre-armed with dlopen() et al so it is not needed there).

Excellent, that's exactly what I wanted to know.  It means the
mechanism is not so very different from the standard one, so the
usual configure tests will work with just a bit of header hacking,
unlike AIX.

With the following patch, dynamic loading under HPUX 10.20 (and
presumably before, but that's the only one I have access too) is fully
supported.  I haven't sent patches for configure and config.h.in, so
you need to run both autoheader and autoconf before trying this out.
(I used gcc for testing, someone ought to check with the standard
compiler since the arguments will be different.)

Sorry it doesn't apply to straight 3.1.5, but there have been
considerable module changes --- the AIXDYNAMIC stuff is the main
culprit.  It's not beyond the wit of person to fix by hand.
Given the changes this week, I'll probably make one final
pre-Christmas version available at the end of the week.

I'm assuming .sl is the standard suffix for shared libraries with this
mechanism?  Or rather, I'm making the rather weaker assumption that
someone hasn't filled /usr/lib with .sl files just for a joke.

This would have been even neater if someone had worked out how to use
ad hoc include files with configure, but it's not so bad anyway.

There's no patch for the `void *symlist1[]' fix, since that seems to
have been fixed already, though I couldn't tell you when.

*** Src/module.c.hpux	Wed Dec 16 12:20:51 1998
--- Src/module.c	Wed Dec 16 16:40:00 1998
***************
*** 255,266 ****
  #ifdef HAVE_DLFCN_H
  # include <dlfcn.h>
  #else
! # include <sys/types.h>
! # include <nlist.h>
! # include <link.h>
  #endif
! #ifndef HAVE_DLCLOSE
! # define dlclose(X) ((X), 0)
  #endif
  
  #ifdef DLSYM_NEEDS_UNDERSCORE
--- 255,292 ----
  #ifdef HAVE_DLFCN_H
  # include <dlfcn.h>
  #else
! # ifdef HAVE_DL_H
! #  include <dl.h>
! #  define RTLD_LAZY BIND_DEFERRED
! #  define RTLD_GLOBAL DYNAMIC_PATH
! # else
! #  include <sys/types.h>
! #  include <nlist.h>
! #  include <link.h>
! # endif
  #endif
! 
! #ifdef HPUXDYNAMIC
! # define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
! # define dlclose(handle) shl_unload((shl_t)(handle))
! 
! /**/
! static
! void *
! hpux_dlsym(void *handle, char *name)
! {
!     void *sym_addr;
!     if (!shl_findsym((shl_t *)&handle, name, TYPE_UNDEFINED, &sym_addr))
! 	return sym_addr;
!     return NULL;
! }
! 
! # define dlsym(handle,name) hpux_dlsym(handle,name)
! # define dlerror() 0
! #else
! # ifndef HAVE_DLCLOSE
! #  define dlclose(X) ((X), 0)
! # endif
  #endif
  
  #ifdef DLSYM_NEEDS_UNDERSCORE
*** acconfig.h.hpux	Fri Oct 30 15:56:16 1998
--- acconfig.h	Wed Dec 16 14:56:33 1998
***************
*** 222,224 ****
--- 222,227 ----
  
  /* Define to 1 if you want to use dynamically loaded modules on AIX */
  #undef AIXDYNAMIC
+ 
+ /* Define to 1 if you want to use dynamically loaded modules on HPUX 10 */
+ #undef HPUXDYNAMIC
*** aczsh.m4.hpux	Tue Dec 15 09:47:50 1998
--- aczsh.m4	Wed Dec 16 15:29:44 1998
***************
*** 56,61 ****
--- 56,73 ----
  $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&5 2>&5 &&
  $DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&5 2>&5; then
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 63,68 ****
--- 75,81 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 116,121 ****
--- 129,146 ----
  $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&5 2>&5 &&
  $DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&5 2>&5; then
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 123,128 ****
--- 148,154 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 130,135 ****
--- 156,162 ----
  #define RTLD_GLOBAL 0
  #endif
  
+ 
  main()
  {
      void *handle1, *handle2;
***************
*** 177,182 ****
--- 204,221 ----
  $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest2.c 1>&5 2>&5 &&
  $DLLD -o conftest2.$DL_EXT $LDFLAGS $DLLDFLAGS conftest2.o $LIBS 1>&5 2>&5; then
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 184,189 ****
--- 223,229 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 234,239 ****
--- 274,291 ----
      save_ldflags=$LDFLAGS
      LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS"
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 241,246 ****
--- 293,299 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 294,299 ****
--- 347,364 ----
      save_ldflags=$LDFLAGS
      LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS -s"
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 301,306 ****
--- 366,372 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 348,359 ****
--- 414,438 ----
  if $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&5 2>&5 &&
  $DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS -s conftest1.o $LIBS 1>&5 2>&5; then
      AC_TRY_RUN([
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
  #include <sys/types.h>
  #include <nlist.h>
  #include <link.h>
+ #endif
  #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
*** configure.in.hpux	Tue Dec 15 10:01:29 1998
--- configure.in	Wed Dec 16 16:59:47 1998
***************
*** 214,220 ****
  fi
  if test -n "$auto_ldflags"; then
    case "${enable_zsh_debug}$host_os" in
!     yesaix*) ;;  # AIX ld does not accept -g
      yes*)    LDFLAGS=-g ;;
      *)       LDFLAGS=-s ;;
    esac
--- 214,220 ----
  fi
  if test -n "$auto_ldflags"; then
    case "${enable_zsh_debug}$host_os" in
!     yesaix*|yeshpux*) ;;  # AIX ld does not accept -g
      yes*)    LDFLAGS=-g ;;
      *)       LDFLAGS=-s ;;
    esac
***************
*** 343,348 ****
--- 343,349 ----
  		 utmp.h utmpx.h sys/types.h pwd.h grp.h)
  if test $dynamic = yes; then
    AC_CHECK_HEADERS(dlfcn.h)
+   AC_CHECK_HEADERS(dl.h)
  fi
  
  dnl Some SCO systems cannot include both sys/time.h and sys/select.h
***************
*** 622,628 ****
  	      getgrgid getgrnam getpwent getpwnam getpwuid)
  
  if test $dynamic = yes; then
!   AC_CHECK_FUNCS(dlopen dlerror dlsym dlclose load loadquery loadbind unload)
  fi
  
  
--- 623,630 ----
  	      getgrgid getgrnam getpwent getpwnam getpwuid)
  
  if test $dynamic = yes; then
!   AC_CHECK_FUNCS(dlopen dlerror dlsym dlclose load loadquery loadbind unload \
! 		shl_load shl_unload shl_findsym)
  fi
  
  
***************
*** 905,910 ****
--- 907,913 ----
  dnl ---------------
  L=N
  aixdynamic=no
+ hpuxdynamic=no
  if test "$ac_cv_func_dlopen"  != yes ||
     test "$ac_cv_func_dlsym"   != yes ||
     test "$ac_cv_func_dlerror" != yes; then
***************
*** 912,918 ****
       test "$ac_cv_func_unload"    != yes ||
       test "$ac_cv_func_loadbind"  != yes ||
       test "$ac_cv_func_loadquery" != yes; then
!     dynamic=no
    elif test "x$dynamic" = xyes; then
      aixdynamic=yes
    fi
--- 915,932 ----
       test "$ac_cv_func_unload"    != yes ||
       test "$ac_cv_func_loadbind"  != yes ||
       test "$ac_cv_func_loadquery" != yes; then
!     if test "$ac_cv_func_shl_load" != yes ||
!        test "$ac_cv_func_shl_unload" != yes ||
!        test "$ac_cv_func_shl_findsym" != yes; then
!       dynamic=no
!     elif test "x$dynamic" = xyes; then
!       hpuxdynamic=yes
!       DL_EXT="${DL_EXT=sl}"
! dnl Don't define HPUXDYNAMIC until after the tests.  However,
! dnl we need some way of telling the test programmes that we
! dnl want to try the HPUX <= 10 way of doing things.
!       AC_DEFINE(TEST_HPUXDYNAMIC)dnl
!     fi
    elif test "x$dynamic" = xyes; then
      aixdynamic=yes
    fi
***************
*** 993,998 ****
--- 1007,1024 ----
      $DLLD -o conftest.$DL_EXT $LDFLAGS $DLLDFLAGS conftest.o 1>&5 2>&5 &&
      AC_TRY_RUN([
  #include <stdio.h>
+ #ifdef TEST_HPUXDYNAMIC
+ #include <dl.h>
+ #define RTLD_LAZY BIND_DEFERRED
+ #define RTLD_GLOBAL DYNAMIC_PATH
+ 
+ char *zsh_gl_sym_addr ;
+ 
+ #define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
+ #define dlclose(handle) shl_unload((shl_t)(handle))
+ #define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
+ #define dlerror() 0
+ #else
  #ifdef HAVE_DLFCN_H
  #include <dlfcn.h>
  #else
***************
*** 1000,1005 ****
--- 1026,1032 ----
  #include <nlist.h>
  #include <link.h>
  #endif
+ #endif
  #ifndef RTLD_LAZY
  #define RTLD_LAZY 1
  #endif
***************
*** 1082,1087 ****
--- 1109,1118 ----
    AC_DEFINE(AIXDYNAMIC)dnl
  else
    E=N
+ fi
+ 
+ if test "x$hpuxdynamic" = xyes -a "x$dynamic" = xyes; then
+   AC_DEFINE(HPUXDYNAMIC)dnl
  fi
  
  AC_DEFINE_UNQUOTED(DL_EXT, "$DL_EXT")dnl

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-12-16 16:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-16  2:20 Dealing with module envy under HPUX 10.20 Gene Cohler
1998-12-16 16:12 ` PATCH: 3.1.5-pws-3: Dynamic loading under HPUX 10 Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).