]> granicus.if.org Git - postgresql/commitdiff
Refactor dlopen() support
authorPeter Eisentraut <peter_e@gmx.net>
Thu, 6 Sep 2018 08:07:24 +0000 (10:07 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Thu, 6 Sep 2018 09:33:04 +0000 (11:33 +0200)
Nowadays, all platforms except Windows and older HP-UX have standard
dlopen() support.  So having a separate implementation per platform
under src/backend/port/dynloader/ is a bit excessive.  Instead, treat
dlopen() like other library functions that happen to be missing
sometimes and put a replacement implementation under src/port/.

Discussion: https://www.postgresql.org/message-id/flat/e11a49cb-570a-60b7-707d-7084c8de0e61%402ndquadrant.com#54e735ae37476a121abb4e33c2549b03

37 files changed:
configure
configure.in
src/backend/Makefile
src/backend/port/.gitignore
src/backend/port/Makefile
src/backend/port/dynloader/aix.c [deleted file]
src/backend/port/dynloader/aix.h [deleted file]
src/backend/port/dynloader/cygwin.c [deleted file]
src/backend/port/dynloader/cygwin.h [deleted file]
src/backend/port/dynloader/darwin.c [deleted file]
src/backend/port/dynloader/darwin.h [deleted file]
src/backend/port/dynloader/freebsd.c [deleted file]
src/backend/port/dynloader/freebsd.h [deleted file]
src/backend/port/dynloader/hpux.c [deleted file]
src/backend/port/dynloader/hpux.h [deleted file]
src/backend/port/dynloader/linux.c [deleted file]
src/backend/port/dynloader/linux.h [deleted file]
src/backend/port/dynloader/netbsd.c [deleted file]
src/backend/port/dynloader/netbsd.h [deleted file]
src/backend/port/dynloader/openbsd.c [deleted file]
src/backend/port/dynloader/openbsd.h [deleted file]
src/backend/port/dynloader/solaris.c [deleted file]
src/backend/port/dynloader/solaris.h [deleted file]
src/backend/port/dynloader/win32.h [deleted file]
src/backend/postmaster/postmaster.c
src/backend/utils/fmgr/dfmgr.c
src/include/.gitignore
src/include/Makefile
src/include/pg_config.h.in
src/include/pg_config.h.win32
src/include/port.h
src/include/utils/dynamic_loader.h [deleted file]
src/port/dlopen.c [moved from src/backend/port/dynloader/win32.c with 51% similarity]
src/tools/msvc/Install.pm
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Solution.pm
src/tools/msvc/clean.bat

index dd94c5bbaba6c40e43e6137d0923537df3bc7c4b..dd77742c462d2efcded1f78fd6005b488a8d7081 100755 (executable)
--- a/configure
+++ b/configure
@@ -15060,7 +15060,7 @@ fi
 LIBS_including_readline="$LIBS"
 LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
 
-for ac_func in cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open symlink sync_file_range utime utimes wcstombs_l
+for ac_func in cbrt clock_gettime fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open symlink sync_file_range utime utimes wcstombs_l
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15252,6 +15252,30 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+ac_fn_c_check_decl "$LINENO" "RTLD_GLOBAL" "ac_cv_have_decl_RTLD_GLOBAL" "#include <dlfcn.h>
+"
+if test "x$ac_cv_have_decl_RTLD_GLOBAL" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_RTLD_GLOBAL $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "RTLD_NOW" "ac_cv_have_decl_RTLD_NOW" "#include <dlfcn.h>
+"
+if test "x$ac_cv_have_decl_RTLD_NOW" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_RTLD_NOW $ac_have_decl
+_ACEOF
+
+
 HAVE_IPV6=no
 ac_fn_c_check_type "$LINENO" "struct sockaddr_in6" "ac_cv_type_struct_sockaddr_in6" "$ac_includes_default
 #include <netinet/in.h>
@@ -15461,6 +15485,19 @@ esac
 
 fi
 
+ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
+if test "x$ac_cv_func_dlopen" = xyes; then :
+  $as_echo "#define HAVE_DLOPEN 1" >>confdefs.h
+
+else
+  case " $LIBOBJS " in
+  *" dlopen.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS dlopen.$ac_objext"
+ ;;
+esac
+
+fi
+
 ac_fn_c_check_func "$LINENO" "fls" "ac_cv_func_fls"
 if test "x$ac_cv_func_fls" = xyes; then :
   $as_echo "#define HAVE_FLS 1" >>confdefs.h
@@ -19016,7 +19053,7 @@ fi
 ac_config_files="$ac_config_files GNUmakefile src/Makefile.global"
 
 
-ac_config_links="$ac_config_links src/backend/port/dynloader.c:src/backend/port/dynloader/${template}.c src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION} src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION} src/include/dynloader.h:src/backend/port/dynloader/${template}.h src/include/pg_config_os.h:src/include/port/${template}.h src/Makefile.port:src/makefiles/Makefile.${template}"
+ac_config_links="$ac_config_links src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION} src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION} src/include/pg_config_os.h:src/include/port/${template}.h src/Makefile.port:src/makefiles/Makefile.${template}"
 
 
 if test "$PORTNAME" = "win32"; then
     "src/backend/port/tas.s") CONFIG_LINKS="$CONFIG_LINKS src/backend/port/tas.s:src/backend/port/tas/${tas_file}" ;;
     "GNUmakefile") CONFIG_FILES="$CONFIG_FILES GNUmakefile" ;;
     "src/Makefile.global") CONFIG_FILES="$CONFIG_FILES src/Makefile.global" ;;
-    "src/backend/port/dynloader.c") CONFIG_LINKS="$CONFIG_LINKS src/backend/port/dynloader.c:src/backend/port/dynloader/${template}.c" ;;
     "src/backend/port/pg_sema.c") CONFIG_LINKS="$CONFIG_LINKS src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION}" ;;
     "src/backend/port/pg_shmem.c") CONFIG_LINKS="$CONFIG_LINKS src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION}" ;;
-    "src/include/dynloader.h") CONFIG_LINKS="$CONFIG_LINKS src/include/dynloader.h:src/backend/port/dynloader/${template}.h" ;;
     "src/include/pg_config_os.h") CONFIG_LINKS="$CONFIG_LINKS src/include/pg_config_os.h:src/include/port/${template}.h" ;;
     "src/Makefile.port") CONFIG_LINKS="$CONFIG_LINKS src/Makefile.port:src/makefiles/Makefile.${template}" ;;
     "check_win32_symlinks") CONFIG_COMMANDS="$CONFIG_COMMANDS check_win32_symlinks" ;;
index 3280afa0dabf8d4c2515af8fa333f575582f98f0..3ada48b5f9541dcd95e5d465d683d7909f0a8250 100644 (file)
@@ -1544,7 +1544,7 @@ PGAC_FUNC_WCSTOMBS_L
 LIBS_including_readline="$LIBS"
 LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
 
-AC_CHECK_FUNCS([cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open symlink sync_file_range utime utimes wcstombs_l])
+AC_CHECK_FUNCS([cbrt clock_gettime fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open symlink sync_file_range utime utimes wcstombs_l])
 
 AC_REPLACE_FUNCS(fseeko)
 case $host_os in
@@ -1570,6 +1570,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
 # This is probably only present on macOS, but may as well check always
 AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
 
+AC_CHECK_DECLS([RTLD_GLOBAL, RTLD_NOW], [], [], [#include <dlfcn.h>])
+
 HAVE_IPV6=no
 AC_CHECK_TYPE([struct sockaddr_in6],
         [AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if you have support for IPv6.])
@@ -1658,7 +1660,7 @@ else
   AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
 fi
 
-AC_REPLACE_FUNCS([crypt fls getopt getrusage inet_aton mkdtemp random rint srandom strerror strlcat strlcpy strnlen])
+AC_REPLACE_FUNCS([crypt dlopen fls getopt getrusage inet_aton mkdtemp random rint srandom strerror strlcat strlcpy strnlen])
 
 case $host_os in
 
@@ -2382,10 +2384,8 @@ AC_SUBST(vpath_build)
 AC_CONFIG_FILES([GNUmakefile src/Makefile.global])
 
 AC_CONFIG_LINKS([
-  src/backend/port/dynloader.c:src/backend/port/dynloader/${template}.c
   src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION}
   src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION}
-  src/include/dynloader.h:src/backend/port/dynloader/${template}.h
   src/include/pg_config_os.h:src/include/port/${template}.h
   src/Makefile.port:src/makefiles/Makefile.${template}
 ])
index 25af514fba59c9b87db41ba2b65940906e07d1a8..3a58bf6685bb722f3ba93fb06922f7300fa7f24b 100644 (file)
@@ -293,7 +293,7 @@ ifeq ($(PORTNAME), win32)
 endif
 
 distclean: clean
-       rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
+       rm -f port/tas.s port/pg_sema.c port/pg_shmem.c
 
 maintainer-clean: distclean
        $(MAKE) -C catalog $@
index 9f4f1af5e93690ec275833b78cc03371fac4ba6b..4ef36b82c77150f41172b096d112f28c7ded5f2f 100644 (file)
@@ -1,4 +1,3 @@
-/dynloader.c
 /pg_sema.c
 /pg_shmem.c
 /tas.s
index aba1e92fe1fc4f743773072c80a973595d4f273b..f4120bec55f8240c899fbcd1341b0bd629c3c051 100644 (file)
@@ -21,7 +21,7 @@ subdir = src/backend/port
 top_builddir = ../../..
 include $(top_builddir)/src/Makefile.global
 
-OBJS = atomics.o dynloader.o pg_sema.o pg_shmem.o $(TAS)
+OBJS = atomics.o pg_sema.o pg_shmem.o $(TAS)
 
 ifeq ($(PORTNAME), win32)
 SUBDIRS += win32
diff --git a/src/backend/port/dynloader/aix.c b/src/backend/port/dynloader/aix.c
deleted file mode 100644 (file)
index bf6ec25..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/aix.c
- *
- * Dummy file used for nothing at this point
- *
- * see aix.h
- */
diff --git a/src/backend/port/dynloader/aix.h b/src/backend/port/dynloader/aix.h
deleted file mode 100644 (file)
index df4f5d5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * aix.h
- *       prototypes for AIX-specific routines
- *
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/aix.h
- *
- *-------------------------------------------------------------------------
- */
-
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define  pg_dlopen(f)  dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define  pg_dlsym(h, f) ((PGFunction) dlsym(h, f))
-#define  pg_dlclose(h) dlclose(h)
-#define  pg_dlerror()  dlerror()
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/cygwin.c b/src/backend/port/dynloader/cygwin.c
deleted file mode 100644 (file)
index 5c52bf6..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/* src/backend/port/dynloader/cygwin.c */
-
-/* Dummy file used for nothing at this point; see cygwin.h */
diff --git a/src/backend/port/dynloader/cygwin.h b/src/backend/port/dynloader/cygwin.h
deleted file mode 100644 (file)
index ef05e6b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Dynamic loader declarations for Cygwin
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/cygwin.h
- *
- *-------------------------------------------------------------------------
-  */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/darwin.c b/src/backend/port/dynloader/darwin.c
deleted file mode 100644 (file)
index 65fa0e3..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Dynamic loading support for macOS (Darwin)
- *
- * src/backend/port/dynloader/darwin.c
- */
-#include "postgres.h"
-
-#include <dlfcn.h>
-
-#include "dynloader.h"
-
-
-void *
-pg_dlopen(const char *filename)
-{
-       return dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
-}
-
-void
-pg_dlclose(void *handle)
-{
-       dlclose(handle);
-}
-
-PGFunction
-pg_dlsym(void *handle, const char *funcname)
-{
-       return dlsym(handle, funcname);
-}
-
-char *
-pg_dlerror(void)
-{
-       return dlerror();
-}
diff --git a/src/backend/port/dynloader/darwin.h b/src/backend/port/dynloader/darwin.h
deleted file mode 100644 (file)
index 292a31d..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* src/backend/port/dynloader/darwin.h */
-
-#include "fmgr.h"
-
-void      *pg_dlopen(const char *filename);
-PGFunction     pg_dlsym(void *handle, const char *funcname);
-void           pg_dlclose(void *handle);
-char      *pg_dlerror(void);
diff --git a/src/backend/port/dynloader/freebsd.c b/src/backend/port/dynloader/freebsd.c
deleted file mode 100644 (file)
index 41b96eb..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/freebsd.c
- *
- * Dummy file used for nothing at this point
- *
- * see freebsd.h
- */
diff --git a/src/backend/port/dynloader/freebsd.h b/src/backend/port/dynloader/freebsd.h
deleted file mode 100644 (file)
index dbdd03c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * freebsd.h
- *       port-specific prototypes for FreeBSD
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/freebsd.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/hpux.c b/src/backend/port/dynloader/hpux.c
deleted file mode 100644 (file)
index d82dd76..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * dynloader.c
- *       dynamic loader for HP-UX using the shared library mechanism
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *       src/backend/port/dynloader/hpux.c
- *
- *     NOTES
- *             all functions are defined here -- it's impossible to trace the
- *             shl_* routines from the bundled HP-UX debugger.
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-/* System includes */
-#include <a.out.h>
-#include <dl.h>
-
-#include "dynloader.h"
-#include "utils/dynamic_loader.h"
-
-void *
-pg_dlopen(const char *filename)
-{
-       /*
-        * Use BIND_IMMEDIATE so that undefined symbols cause a failure return
-        * from shl_load(), rather than an abort() later on when we attempt to
-        * call the library!
-        */
-       shl_t           handle = shl_load(filename,
-                                                                 BIND_IMMEDIATE | BIND_VERBOSE | DYNAMIC_PATH,
-                                                                 0L);
-
-       return (void *) handle;
-}
-
-PGFunction
-pg_dlsym(void *handle, const char *funcname)
-{
-       PGFunction      f;
-
-       if (shl_findsym((shl_t *) & handle, funcname, TYPE_PROCEDURE, &f) == -1)
-               f = (PGFunction) NULL;
-       return f;
-}
-
-void
-pg_dlclose(void *handle)
-{
-       shl_unload((shl_t) handle);
-}
-
-char *
-pg_dlerror(void)
-{
-       static char errmsg[] = "shl_load failed";
-
-       if (errno)
-               return strerror(errno);
-
-       return errmsg;
-}
diff --git a/src/backend/port/dynloader/hpux.h b/src/backend/port/dynloader/hpux.h
deleted file mode 100644 (file)
index 1cbc469..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * dynloader.h
- *       dynamic loader for HP-UX using the shared library mechanism
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *       src/backend/port/dynloader/hpux.h
- *
- *     NOTES
- *             all functions are defined here -- it's impossible to trace the
- *             shl_* routines from the bundled HP-UX debugger.
- *
- *-------------------------------------------------------------------------
- */
-/* System includes */
-#include "fmgr.h"
-
-extern void *pg_dlopen(const char *filename);
-extern PGFunction pg_dlsym(void *handle, const char *funcname);
-extern void pg_dlclose(void *handle);
-extern char *pg_dlerror(void);
diff --git a/src/backend/port/dynloader/linux.c b/src/backend/port/dynloader/linux.c
deleted file mode 100644 (file)
index 2126576..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/linux.c
- *
- * Dummy file used for nothing at this point
- *
- * see linux.h
- */
diff --git a/src/backend/port/dynloader/linux.h b/src/backend/port/dynloader/linux.h
deleted file mode 100644 (file)
index 6beb3d6..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * linux.h
- *             Port-specific prototypes for Linux
- *
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/linux.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-#include <dlfcn.h>
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/netbsd.c b/src/backend/port/dynloader/netbsd.c
deleted file mode 100644 (file)
index 8f7f568..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/netbsd.c
- *
- * Dummy file used for nothing at this point
- *
- * see netbsd.h
- */
diff --git a/src/backend/port/dynloader/netbsd.h b/src/backend/port/dynloader/netbsd.h
deleted file mode 100644 (file)
index f3c38eb..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * netbsd.h
- *       port-specific prototypes for NetBSD
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/netbsd.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/openbsd.c b/src/backend/port/dynloader/openbsd.c
deleted file mode 100644 (file)
index 6a8e1d8..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/openbsd.c
- *
- * Dummy file used for nothing at this point
- *
- * see openbsd.h
- */
diff --git a/src/backend/port/dynloader/openbsd.h b/src/backend/port/dynloader/openbsd.h
deleted file mode 100644 (file)
index 78bfbed..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * openbsd.h
- *       port-specific prototypes for OpenBSD
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/openbsd.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/solaris.c b/src/backend/port/dynloader/solaris.c
deleted file mode 100644 (file)
index 19adced..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * src/backend/port/dynloader/solaris.c
- *
- * Dummy file used for nothing at this point
- *
- * see solaris.h
- */
diff --git a/src/backend/port/dynloader/solaris.h b/src/backend/port/dynloader/solaris.h
deleted file mode 100644 (file)
index b583c26..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * solaris.h
- *       port-specific prototypes for Solaris
- *
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/backend/port/dynloader/solaris.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include <dlfcn.h>
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-/*
- * In some older systems, the RTLD_NOW flag isn't defined and the mode
- * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
- * if available, but it doesn't exist everywhere.
- * If it doesn't exist, set it to 0 so it has no effect.
- */
-#ifndef RTLD_NOW
-#define RTLD_NOW 1
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
-
-#define pg_dlopen(f)   dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-#endif                                                 /* PORT_PROTOS_H */
diff --git a/src/backend/port/dynloader/win32.h b/src/backend/port/dynloader/win32.h
deleted file mode 100644 (file)
index ddbf866..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * src/backend/port/dynloader/win32.h
- */
-#ifndef PORT_PROTOS_H
-#define PORT_PROTOS_H
-
-#include "utils/dynamic_loader.h"      /* pgrminclude ignore */
-
-#define pg_dlopen(f)   dlopen((f), 1)
-#define pg_dlsym               dlsym
-#define pg_dlclose             dlclose
-#define pg_dlerror             dlerror
-
-char      *dlerror(void);
-int                    dlclose(void *handle);
-void      *dlsym(void *handle, const char *symbol);
-void      *dlopen(const char *path, int mode);
-
-#endif                                                 /* PORT_PROTOS_H */
index 7fb4296b7a40f1258e8df3cdead9b49e778a4266..305ff3625814927dae20239ad2ed838b21e97841 100644 (file)
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
 #include "utils/datetime.h"
-#include "utils/dynamic_loader.h"
 #include "utils/memutils.h"
 #include "utils/pidfile.h"
 #include "utils/ps_status.h"
index 1b0dbad82c7fb64ae3a3489730401639971f1fd9..c2a257258deefa2f6b88bf0a017a1443be16a1a5 100644 (file)
 
 #include <sys/stat.h>
 
-#include "dynloader.h"
+#ifdef HAVE_DLOPEN
+#include <dlfcn.h>
+#endif
+
+#include "fmgr.h"
 #include "lib/stringinfo.h"
 #include "miscadmin.h"
 #include "storage/shmem.h"
-#include "utils/dynamic_loader.h"
 #include "utils/hsearch.h"
 
 
@@ -113,7 +116,7 @@ load_external_function(const char *filename, const char *funcname,
         * should declare its second argument as "const char *", but older
         * platforms might not, so for the time being we just cast away const.
         */
-       retval = (PGFunction) pg_dlsym(lib_handle, (char *) funcname);
+       retval = (PGFunction) dlsym(lib_handle, (char *) funcname);
 
        if (retval == NULL && signalNotFound)
                ereport(ERROR,
@@ -162,7 +165,7 @@ PGFunction
 lookup_external_function(void *filehandle, const char *funcname)
 {
        /* as above, cast away const for the time being */
-       return (PGFunction) pg_dlsym(filehandle, (char *) funcname);
+       return (PGFunction) dlsym(filehandle, (char *) funcname);
 }
 
 
@@ -228,10 +231,10 @@ internal_load_library(const char *libname)
 #endif
                file_scanner->next = NULL;
 
-               file_scanner->handle = pg_dlopen(file_scanner->filename);
+               file_scanner->handle = dlopen(file_scanner->filename, RTLD_NOW | RTLD_GLOBAL);
                if (file_scanner->handle == NULL)
                {
-                       load_error = (char *) pg_dlerror();
+                       load_error = dlerror();
                        free((char *) file_scanner);
                        /* errcode_for_file_access might not be appropriate here? */
                        ereport(ERROR,
@@ -242,7 +245,7 @@ internal_load_library(const char *libname)
 
                /* Check the magic function to determine compatibility */
                magic_func = (PGModuleMagicFunction)
-                       pg_dlsym(file_scanner->handle, PG_MAGIC_FUNCTION_NAME_STRING);
+                       dlsym(file_scanner->handle, PG_MAGIC_FUNCTION_NAME_STRING);
                if (magic_func)
                {
                        const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
@@ -253,8 +256,8 @@ internal_load_library(const char *libname)
                                /* copy data block before unlinking library */
                                Pg_magic_struct module_magic_data = *magic_data_ptr;
 
-                               /* try to unlink library */
-                               pg_dlclose(file_scanner->handle);
+                               /* try to close library */
+                               dlclose(file_scanner->handle);
                                free((char *) file_scanner);
 
                                /* issue suitable complaint */
@@ -263,8 +266,8 @@ internal_load_library(const char *libname)
                }
                else
                {
-                       /* try to unlink library */
-                       pg_dlclose(file_scanner->handle);
+                       /* try to close library */
+                       dlclose(file_scanner->handle);
                        free((char *) file_scanner);
                        /* complain */
                        ereport(ERROR,
@@ -276,7 +279,7 @@ internal_load_library(const char *libname)
                /*
                 * If the library has a _PG_init() function, call it.
                 */
-               PG_init = (PG_init_t) pg_dlsym(file_scanner->handle, "_PG_init");
+               PG_init = (PG_init_t) dlsym(file_scanner->handle, "_PG_init");
                if (PG_init)
                        (*PG_init) ();
 
@@ -436,12 +439,12 @@ internal_unload_library(const char *libname)
                        /*
                         * If the library has a _PG_fini() function, call it.
                         */
-                       PG_fini = (PG_fini_t) pg_dlsym(file_scanner->handle, "_PG_fini");
+                       PG_fini = (PG_fini_t) dlsym(file_scanner->handle, "_PG_fini");
                        if (PG_fini)
                                (*PG_fini) ();
 
                        clear_external_function_hash(file_scanner->handle);
-                       pg_dlclose(file_scanner->handle);
+                       dlclose(file_scanner->handle);
                        free((char *) file_scanner);
                        /* prv does not change */
                }
index 49d108dbed32e431bbaa4414e3f1040f0bb67e62..51819fb4dddc920e7300294e766b84cbc8b0d9a0 100644 (file)
@@ -3,4 +3,3 @@
 /pg_config.h
 /pg_config_ext.h
 /pg_config_os.h
-/dynloader.h
index 901eddbd4485c6401d813ae6c3d2048099139f8b..6bdfd7db911ce5b6ed1bf8bd691aa2ca85fc7da7 100644 (file)
@@ -54,7 +54,7 @@ install: all installdirs
          cp $(srcdir)/$$dir/*.h '$(DESTDIR)$(includedir_server)'/$$dir/ || exit; \
        done
 ifeq ($(vpath_build),yes)
-       for file in dynloader.h catalog/schemapg.h catalog/pg_*_d.h parser/gram.h storage/lwlocknames.h utils/probes.h; do \
+       for file in catalog/schemapg.h catalog/pg_*_d.h parser/gram.h storage/lwlocknames.h utils/probes.h; do \
          cp $$file '$(DESTDIR)$(includedir_server)'/$$file || exit; \
        done
 endif
@@ -82,4 +82,4 @@ clean:
        rm -f catalog/schemapg.h catalog/pg_*_d.h catalog/header-stamp
 
 distclean maintainer-clean: clean
-       rm -f pg_config.h pg_config_ext.h pg_config_os.h dynloader.h stamp-h stamp-ext-h
+       rm -f pg_config.h pg_config_ext.h pg_config_os.h stamp-h stamp-ext-h
index 347d5b56dcb53d76107b54c8b310d5fec51ca2e6..4094e22776c3d6424e308fa121cf63c56168c1eb 100644 (file)
    don't. */
 #undef HAVE_DECL_POSIX_FADVISE
 
+/* Define to 1 if you have the declaration of `RTLD_GLOBAL', and to 0 if you
+   don't. */
+#undef HAVE_DECL_RTLD_GLOBAL
+
+/* Define to 1 if you have the declaration of `RTLD_NOW', and to 0 if you
+   don't. */
+#undef HAVE_DECL_RTLD_NOW
+
 /* Define to 1 if you have the declaration of `snprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_SNPRINTF
index 7a92d889996bf91b2118357512976619c2dc9d3b..6618b43587456187ac8b529af523d2e6da079335 100644 (file)
    to 0 if you don't. */
 #define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN 0
 
+/* Define to 1 if you have the declaration of `RTLD_GLOBAL', and to 0 if you
+   don't. */
+#define HAVE_DECL_RTLD_GLOBAL 0
+
+/* Define to 1 if you have the declaration of `RTLD_NOW', and to 0 if you
+   don't. */
+#define HAVE_DECL_RTLD_NOW 0
+
 /* Define to 1 if you have the declaration of `snprintf', and to 0 if you
    don't. */
 #define HAVE_DECL_SNPRINTF 1
index 0ce72e50e5e85cdb0956d17252534468fcca067d..d92756111f2b873c8a2c4c44cb906a19e88475aa 100644 (file)
@@ -403,6 +403,29 @@ extern void srandom(unsigned int seed);
 #define SSL_get_current_compression(x) 0
 #endif
 
+#ifndef HAVE_DLOPEN
+extern void *dlopen(const char *file, int mode);
+extern void *dlsym(void *handle, const char *symbol);
+extern int dlclose(void *handle);
+extern char *dlerror(void);
+#endif
+
+/*
+ * In some older systems, the RTLD_NOW flag isn't defined and the mode
+ * argument to dlopen must always be 1.
+ */
+#if !HAVE_DECL_RTLD_NOW
+#define RTLD_NOW 1
+#endif
+
+/*
+ * The RTLD_GLOBAL flag is wanted if available, but it doesn't exist
+ * everywhere.  If it doesn't exist, set it to 0 so it has no effect.
+ */
+#if !HAVE_DECL_RTLD_GLOBAL
+#define RTLD_GLOBAL 0
+#endif
+
 /* thread.h */
 extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
 
diff --git a/src/include/utils/dynamic_loader.h b/src/include/utils/dynamic_loader.h
deleted file mode 100644 (file)
index e2455b5..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * dynamic_loader.h
- *
- *
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/include/utils/dynamic_loader.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef DYNAMIC_LOADER_H
-#define DYNAMIC_LOADER_H
-
-#include "fmgr.h"
-
-
-extern void *pg_dlopen(const char *filename);
-extern PGFunction pg_dlsym(void *handle, const char *funcname);
-extern void pg_dlclose(void *handle);
-extern char *pg_dlerror(void);
-
-#endif                                                 /* DYNAMIC_LOADER_H */
similarity index 51%
rename from src/backend/port/dynloader/win32.c
rename to src/port/dlopen.c
index c59823e3675af65383b0063dc4f42dea73d0bf50..897407c3af3ae9d0b1d550b624026c7cf679d8f0 100644 (file)
@@ -1,11 +1,69 @@
-/* src/backend/port/dynloader/win32.c */
+/*-------------------------------------------------------------------------
+ *
+ * dlopen.c
+ *       dynamic loader for platforms without dlopen()
+ *
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *       src/port/dlopen.c
+ *
+ *-------------------------------------------------------------------------
+ */
 
-#include "postgres.h"
+#include "c.h"
 
-char      *dlerror(void);
-int                    dlclose(void *handle);
-void      *dlsym(void *handle, const char *symbol);
-void      *dlopen(const char *path, int mode);
+#if defined(__hpux)
+
+/* System includes */
+#include <a.out.h>
+#include <dl.h>
+
+void *
+dlopen(const char *file, int mode)
+{
+       int             flags = 0;
+
+       if (mode & RTLD_NOW)
+               flags |= BIND_IMMEDIATE;
+#ifdef NOT_USED
+       if (mode & RTLD_LAZY)
+               flags |= BIND_DEFERRED;
+#endif
+
+       return shl_load(filename, flags | BIND_VERBOSE, 0L);
+}
+
+void *
+dlsym(void *handle, const char *symbol)
+{
+       void       *value;
+
+       if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &value) == -1)
+               return NULL;
+       return value;
+}
+
+int
+dlclose(void *handle)
+{
+       return shl_unload((shl_t) handle);
+}
+
+char *
+dlerror(void)
+{
+       static char errmsg[] = "shl_load failed";
+
+       if (errno)
+               return strerror(errno);
+
+       return errmsg;
+}
+
+#elif defined(WIN32)
 
 static char last_dyn_error[512];
 
@@ -83,3 +141,5 @@ dlopen(const char *path, int mode)
        last_dyn_error[0] = 0;
        return (void *) h;
 }
+
+#endif
index 60b5639df85724a4499fe2745b69e3121a62c0ee..c8ae1a0dc7fe6423ff7bea4fdbdf020e051b3b31 100644 (file)
@@ -654,7 +654,7 @@ sub CopyIncludeFiles
                'Public headers', $target . '/include/',
                'src/include/',   'postgres_ext.h',
                'pg_config.h',    'pg_config_ext.h',
-               'pg_config_os.h', 'dynloader.h',
+               'pg_config_os.h',
                'pg_config_manual.h');
        lcopy('src/include/libpq/libpq-fs.h', $target . '/include/libpq/')
          || croak 'Could not copy libpq-fs.h';
@@ -678,8 +678,7 @@ sub CopyIncludeFiles
        CopyFiles(
                'Server headers',
                $target . '/include/server/',
-               'src/include/', 'pg_config.h', 'pg_config_ext.h', 'pg_config_os.h',
-               'dynloader.h');
+               'src/include/', 'pg_config.h', 'pg_config_ext.h', 'pg_config_os.h');
        CopyFiles(
                'Grammar header',
                $target . '/include/server/parser/',
index 4543d87d83b6ff9d9298201f251762a67ba5a091..14d2a3c4cfde4a315fe1df015ac452800f18fc0c 100644 (file)
@@ -98,7 +98,7 @@ sub mkvcbuild
          erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
          pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
          pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c
-         sprompt.c tar.c thread.c getopt.c getopt_long.c dirent.c
+         sprompt.c tar.c thread.c getopt.c getopt_long.c dirent.c dlopen.c
          win32env.c win32error.c win32security.c win32setlocale.c);
 
        push(@pgportfiles, 'rint.c') if ($vsVersion < '12.00');
@@ -155,9 +155,6 @@ sub mkvcbuild
        $postgres->AddIncludeDir('src/backend');
        $postgres->AddDir('src/backend/port/win32');
        $postgres->AddFile('src/backend/utils/fmgrtab.c');
-       $postgres->ReplaceFile(
-               'src/backend/port/dynloader.c',
-               'src/backend/port/dynloader/win32.c');
        $postgres->ReplaceFile('src/backend/port/pg_sema.c',
                'src/backend/port/win32_sema.c');
        $postgres->ReplaceFile('src/backend/port/pg_shmem.c',
index 7d7ce8b03124700716fe221ec368c6df8687b4eb..68cf812f01df7e7979318752e90a1ee6ce39770a 100644 (file)
@@ -321,13 +321,6 @@ sub GenerateFiles
                        'src/include/storage/lwlocknames.h');
        }
 
-       if (IsNewer(
-                       'src/include/dynloader.h', 'src/backend/port/dynloader/win32.h'))
-       {
-               copyFile('src/backend/port/dynloader/win32.h',
-                       'src/include/dynloader.h');
-       }
-
        if (IsNewer('src/include/utils/probes.h', 'src/backend/utils/probes.d'))
        {
                print "Generating probes.h...\n";
index 1d9cd40bdb1e1f9081a3aaabbe5e633e4fcbf848..7a23a2b55f715cf0259af5c43e65e24fbbe928e3 100755 (executable)
@@ -40,7 +40,6 @@ REM Delete files created with GenerateFiles() in Solution.pm
 if exist src\include\pg_config.h del /q src\include\pg_config.h
 if exist src\include\pg_config_ext.h del /q src\include\pg_config_ext.h
 if exist src\include\pg_config_os.h del /q src\include\pg_config_os.h
-if exist src\include\dynloader.h del /q src\include\dynloader.h
 if %DIST%==1 if exist src\backend\parser\gram.h del /q src\backend\parser\gram.h
 if exist src\include\utils\errcodes.h del /q src\include\utils\errcodes.h
 if exist src\include\utils\fmgroids.h del /q src\include\utils\fmgroids.h