bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shl_load (old HP-UX) loadable support


From: wooledg
Subject: shl_load (old HP-UX) loadable support
Date: 24 Feb 2009 20:44:48 -0000

Configuration Information [Automatically generated, do not change]:
Machine: hppa2.0
OS: hpux10.20
Compiler: /net/appl/gcc-3.3/bin/gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='hppa2.0' 
-DCONF_OSTYPE='hpux10.20' -DCONF_MACHTYPE='hppa2.0-hp-hpux10.20' 
-DCONF_VENDOR='hp' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DHPUX   -I.  -I. -I./include -I./lib -I./lib/intl 
-I/var/tmp/bash-4.0/lib/intl  -g -O2
uname output: HP-UX imadev B.10.20 A 9000/785 2008897791 two-user license
Machine Type: hppa2.0-hp-hpux10.20

Bash Version: 4.0
Patch Level: 0
Release Status: release

Description:
A patch to add support for the shl_load() family of functions.  Built against
bash 4.0 but it would probably work with older versions; the enable.def
code looks pretty much the same, I think.

Repeat-By:
(See patch.)

Fix:
This patch adds shl_load (old HP-UX) support to bash 4.0 for enabling
loadable builtins.  In order for bash on HP-UX to actually load most of
the builtins, it must be linked with the linker's -E flag as well, so
you'll need to do something like this:

 .../bash-4.0$ patch -p1 < ../bash-4.0-shl.diff
 .../bash-4.0$ autoconf
 .../bash-4.0$ CC=gcc LDFLAGS=-Wl,-E ./configure
 .../bash-4.0$ make

If you're using the native HP-UX compiler, then the options may differ.

--- bash-4.0/config.h.in        Sun Feb  1 17:07:23 2009
+++ bash-4.0-shl/config.h.in    Tue Feb 24 08:57:52 2009
@@ -537,6 +537,15 @@
 /* Define if you have the dlsym function.  */
 #undef HAVE_DLSYM
 
+/* Define if you have the shl_load function. */
+#undef HAVE_SHL_LOAD
+
+/* Define if you have the shl_unload function. */
+#undef HAVE_SHL_UNLOAD
+
+/* Define if you have the shl_findsym function. */
+#undef HAVE_SHL_FINDSYM
+
 /* Define if you don't have vprintf but do have _doprnt.  */
 #undef HAVE_DOPRNT
 
@@ -853,6 +862,9 @@
 
 /* Define if you have the <dirent.h> header file.  */
 #undef HAVE_DIRENT_H
+
+/* Define if you have the <dl.h> header file.  */
+#undef HAVE_DL_H
 
 /* Define if you have the <dlfcn.h> header file.  */
 #undef HAVE_DLFCN_H
--- bash-4.0/configure.in       Fri Feb  6 12:03:44 2009
+++ bash-4.0-shl/configure.in   Tue Feb 24 08:58:49 2009
@@ -650,7 +650,7 @@
 BASH_HEADER_INTTYPES
 
 AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
-                memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
+                memory.h locale.h termcap.h termio.h termios.h dl.h dlfcn.h \
                 stddef.h stdint.h netdb.h pwd.h grp.h strings.h regex.h)
 AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h \
                 sys/resource.h sys/param.h sys/socket.h sys/stat.h \
@@ -798,6 +798,8 @@
 if test "$opt_static_link" != yes; then
 AC_CHECK_LIB(dl, dlopen)
 AC_CHECK_FUNCS(dlopen dlclose dlsym)
+AC_CHECK_LIB(dld, shl_load)
+AC_CHECK_FUNCS(shl_load shl_unload shl_findsym)
 fi
 
 dnl this defines HAVE_DECL_SYS_SIGLIST
@@ -1062,7 +1064,8 @@
 # Shared object configuration section.  These values are generated by
 # ${srcdir}/support/shobj-conf
 #
-if test "$ac_cv_func_dlopen" = "yes" && test -f ${srcdir}/support/shobj-conf
+if ( test "$ac_cv_func_dlopen" = "yes" || test "$ac_cv_func_shl_load" = "yes" 
)\
+  && test -f ${srcdir}/support/shobj-conf
 then
        AC_MSG_CHECKING(shared object configuration for loadable builtins)
        eval `${CONFIG_SHELL-/bin/sh} ${srcdir}/support/shobj-conf -C "${CC}" 
-c "${host_cpu}" -o "${host_os}" -v "${host_vendor}"`
--- bash-4.0/builtins/enable.def        Sun Jan  4 14:32:22 2009
+++ bash-4.0-shl/builtins/enable.def    Tue Feb 24 12:39:24 2009
@@ -82,11 +82,11 @@
 #define PFLAG  0x10
 #define SFLAG  0x20
 
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined 
(HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
 static int dyn_load_builtin __P((WORD_LIST *, int, char *));
 #endif
 
-#if defined (HAVE_DLCLOSE)
+#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
 static int dyn_unload_builtin __P((char *));
 static void delete_builtin __P((struct builtin *));
 static int local_dlclose __P((void *));
@@ -104,7 +104,7 @@
 {
   int result, flags;
   int opt, filter;
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined 
(HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
   char *filename;
 #endif
 
@@ -129,7 +129,7 @@
          flags |= SFLAG;
          break;
        case 'f':
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined 
(HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
          flags |= FFLAG;
          filename = list_optarg;
          break;
@@ -137,7 +137,7 @@
          builtin_error (_("dynamic loading not available"));
          return (EX_USAGE);
 #endif
-#if defined (HAVE_DLCLOSE)
+#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
        case 'd':
          flags |= DFLAG;
          break;
@@ -172,7 +172,7 @@
 
       list_some_builtins (filter);
     }
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined 
(HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
   else if (flags & FFLAG)
     {
       filter = (flags & NFLAG) ? DISABLED : ENABLED;
@@ -185,7 +185,7 @@
 #endif
     }
 #endif
-#if defined (HAVE_DLCLOSE)
+#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
   else if (flags & DFLAG)
     {
       while (list)
@@ -275,11 +275,17 @@
   return (EXECUTION_SUCCESS);
 }
 
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined 
(HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
 
 #if defined (HAVE_DLFCN_H)
 #  include <dlfcn.h>
 #endif
+#if defined (HAVE_DL_H)
+#  include <dl.h>
+#endif
+#if defined (HAVE_ERRNO_H)
+#  include <errno.h>
+#endif
 
 static int
 dyn_load_builtin (list, flags, filename)
@@ -288,7 +294,11 @@
      char *filename;
 {
   WORD_LIST *l;
+#if defined (HAVE_DLOPEN)
   void *handle;
+#elif defined (HAVE_SHL_LOAD)
+  shl_t handle;
+#endif
   
   int total, size, new, replaced;
   char *struct_name, *name;
@@ -301,15 +311,22 @@
 #define RTLD_LAZY 1
 #endif
 
-#if defined (_AIX)
+#if defined (HAVE_DLOPEN) && defined (_AIX)
   handle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL);
-#else
+#elif defined (HAVE_DLOPEN)
   handle = dlopen (filename, RTLD_LAZY);
+#elif defined (HAVE_SHL_LOAD)
+  handle = shl_load (filename, BIND_IMMEDIATE | BIND_VERBOSE, 0L);
 #endif /* !_AIX */
 
   if (handle == 0)
     {
-      builtin_error (_("cannot open shared object %s: %s"), filename, dlerror 
());
+      builtin_error (_("cannot open shared object %s: %s"), filename,
+#if defined (HAVE_DLOPEN)
+        dlerror ());
+#elif defined (HAVE_SHL_LOAD)
+        strerror (errno));
+#endif
       return (EXECUTION_FAILURE);
     }
 
@@ -329,11 +346,20 @@
       strcpy (struct_name, name);
       strcpy (struct_name + size, "_struct");
 
+#if defined (HAVE_DLSYM)
       b = (struct builtin *)dlsym (handle, struct_name);
       if (b == 0)
+#elif defined (HAVE_SHL_FINDSYM)
+      if (0 != shl_findsym (&handle, struct_name, TYPE_UNDEFINED, (void *) &b))
+#endif
        {
          builtin_error (_("cannot find %s in shared object %s: %s"),
-                         struct_name, filename, dlerror ());
+                         struct_name, filename,
+#if defined (HAVE_DLOPEN)
+                         dlerror ());
+#elif defined (HAVE_SHL_LOAD)
+                         strerror (errno));
+#endif
          free (struct_name);
          continue;
        }
@@ -357,7 +383,11 @@
   if (replaced == 0 && new == 0)
     {
       free (new_builtins);
+#if defined (HAVE_DLCLOSE)
       dlclose (handle);
+#elif defined (HAVE_SHL_UNLOAD)
+      shl_unload (handle);
+#endif
       return (EXECUTION_FAILURE);
     }
 
@@ -391,7 +421,7 @@
 }
 #endif
 
-#if defined (HAVE_DLCLOSE)
+#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
 static void
 delete_builtin (b)
      struct builtin *b;
@@ -432,12 +462,16 @@
 local_dlclose (handle)
      void *handle;
 {
+#if defined (HAVE_DLCLOSE)
 #if !defined (__MACHTEN__)
   return (dlclose (handle));
 #else /* __MACHTEN__ */
   dlclose (handle);
   return ((dlerror () != NULL) ? -1 : 0);    
 #endif /* __MACHTEN__ */
+#elif defined (HAVE_SHL_UNLOAD)
+  return (shl_unload (handle));
+#endif /* HAVE_DLCLOSE or HAVE_SHL_UNLOAD */
 }
 
 static int
@@ -471,7 +505,12 @@
      using it drops to zero. */
   if (ref == 1 && local_dlclose (handle) != 0)
     {
-      builtin_error (_("%s: cannot delete: %s"), name, dlerror ());
+      builtin_error (_("%s: cannot delete: %s"), name,
+#if defined (HAVE_DLOPEN)
+        dlerror ());
+#elif defined (HAVE_SHL_LOAD)
+        strerror (errno));
+#endif
       return (EXECUTION_FAILURE);
     }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]