From cb7ba655d4eb032412be0e63d75c4e4cd07ee049 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 1 Sep 2018 06:41:17 +0200 Subject: [PATCH v2] Refactor dlopen() support 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/. --- configure | 43 +++++++++-- configure.in | 8 +-- src/backend/Makefile | 2 +- src/backend/port/.gitignore | 1 - src/backend/port/Makefile | 2 +- src/backend/port/dynloader/aix.c | 7 -- src/backend/port/dynloader/aix.h | 39 ---------- src/backend/port/dynloader/cygwin.c | 3 - src/backend/port/dynloader/cygwin.h | 36 ---------- src/backend/port/dynloader/darwin.c | 35 --------- src/backend/port/dynloader/darwin.h | 8 --- src/backend/port/dynloader/freebsd.c | 7 -- src/backend/port/dynloader/freebsd.h | 38 ---------- src/backend/port/dynloader/hpux.c | 68 ------------------ src/backend/port/dynloader/hpux.h | 25 ------- src/backend/port/dynloader/linux.c | 7 -- src/backend/port/dynloader/linux.h | 38 ---------- src/backend/port/dynloader/netbsd.c | 7 -- src/backend/port/dynloader/netbsd.h | 38 ---------- src/backend/port/dynloader/openbsd.c | 7 -- src/backend/port/dynloader/openbsd.h | 38 ---------- src/backend/port/dynloader/solaris.c | 7 -- src/backend/port/dynloader/solaris.h | 38 ---------- src/backend/port/dynloader/win32.h | 19 ----- src/backend/postmaster/postmaster.c | 1 - src/backend/utils/fmgr/dfmgr.c | 31 ++++---- src/include/.gitignore | 1 - src/include/Makefile | 4 +- src/include/pg_config.h.in | 8 +++ src/include/pg_config.h.win32 | 8 +++ src/include/port.h | 23 ++++++ src/include/utils/dynamic_loader.h | 25 ------- .../port/dynloader/win32.c => port/dlopen.c} | 72 +++++++++++++++++-- src/tools/msvc/Install.pm | 5 +- src/tools/msvc/Mkvcbuild.pm | 5 +- src/tools/msvc/Solution.pm | 7 -- src/tools/msvc/clean.bat | 1 - 37 files changed, 172 insertions(+), 540 deletions(-) delete mode 100644 src/backend/port/dynloader/aix.c delete mode 100644 src/backend/port/dynloader/aix.h delete mode 100644 src/backend/port/dynloader/cygwin.c delete mode 100644 src/backend/port/dynloader/cygwin.h delete mode 100644 src/backend/port/dynloader/darwin.c delete mode 100644 src/backend/port/dynloader/darwin.h delete mode 100644 src/backend/port/dynloader/freebsd.c delete mode 100644 src/backend/port/dynloader/freebsd.h delete mode 100644 src/backend/port/dynloader/hpux.c delete mode 100644 src/backend/port/dynloader/hpux.h delete mode 100644 src/backend/port/dynloader/linux.c delete mode 100644 src/backend/port/dynloader/linux.h delete mode 100644 src/backend/port/dynloader/netbsd.c delete mode 100644 src/backend/port/dynloader/netbsd.h delete mode 100644 src/backend/port/dynloader/openbsd.c delete mode 100644 src/backend/port/dynloader/openbsd.h delete mode 100644 src/backend/port/dynloader/solaris.c delete mode 100644 src/backend/port/dynloader/solaris.h delete mode 100644 src/backend/port/dynloader/win32.h delete mode 100644 src/include/utils/dynamic_loader.h rename src/{backend/port/dynloader/win32.c => port/dlopen.c} (51%) diff --git a/configure b/configure index dd94c5bbab..dd77742c46 100755 --- 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 +" +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 +" +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 @@ -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 @@ -19737,10 +19774,8 @@ do "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" ;; diff --git a/configure.in b/configure.in index 3280afa0da..3ada48b5f9 100644 --- a/configure.in +++ b/configure.in @@ -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 ]) +AC_CHECK_DECLS([RTLD_GLOBAL, RTLD_NOW], [], [], [#include ]) + 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} ]) diff --git a/src/backend/Makefile b/src/backend/Makefile index 25af514fba..3a58bf6685 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -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 $@ diff --git a/src/backend/port/.gitignore b/src/backend/port/.gitignore index 9f4f1af5e9..4ef36b82c7 100644 --- a/src/backend/port/.gitignore +++ b/src/backend/port/.gitignore @@ -1,4 +1,3 @@ -/dynloader.c /pg_sema.c /pg_shmem.c /tas.s diff --git a/src/backend/port/Makefile b/src/backend/port/Makefile index aba1e92fe1..f4120bec55 100644 --- a/src/backend/port/Makefile +++ b/src/backend/port/Makefile @@ -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 index bf6ec257e7..0000000000 --- a/src/backend/port/dynloader/aix.c +++ /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 index df4f5d5a1a..0000000000 --- a/src/backend/port/dynloader/aix.h +++ /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 -#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 index 5c52bf6147..0000000000 --- a/src/backend/port/dynloader/cygwin.c +++ /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 index ef05e6b416..0000000000 --- a/src/backend/port/dynloader/cygwin.h +++ /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 -#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 index 65fa0e39f2..0000000000 --- a/src/backend/port/dynloader/darwin.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Dynamic loading support for macOS (Darwin) - * - * src/backend/port/dynloader/darwin.c - */ -#include "postgres.h" - -#include - -#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 index 292a31de13..0000000000 --- a/src/backend/port/dynloader/darwin.h +++ /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 index 41b96ebaf0..0000000000 --- a/src/backend/port/dynloader/freebsd.c +++ /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 index dbdd03cb3a..0000000000 --- a/src/backend/port/dynloader/freebsd.h +++ /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 - -#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 index d82dd7603b..0000000000 --- a/src/backend/port/dynloader/hpux.c +++ /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 -#include - -#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 index 1cbc46960e..0000000000 --- a/src/backend/port/dynloader/hpux.h +++ /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 index 2126576e8f..0000000000 --- a/src/backend/port/dynloader/linux.c +++ /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 index 6beb3d63f8..0000000000 --- a/src/backend/port/dynloader/linux.h +++ /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 - -/* - * 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 index 8f7f56864d..0000000000 --- a/src/backend/port/dynloader/netbsd.c +++ /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 index f3c38eb98a..0000000000 --- a/src/backend/port/dynloader/netbsd.h +++ /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 - -#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 index 6a8e1d89d7..0000000000 --- a/src/backend/port/dynloader/openbsd.c +++ /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 index 78bfbed694..0000000000 --- a/src/backend/port/dynloader/openbsd.h +++ /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 - -#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 index 19adcedc5e..0000000000 --- a/src/backend/port/dynloader/solaris.c +++ /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 index b583c266cf..0000000000 --- a/src/backend/port/dynloader/solaris.h +++ /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 -#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 index ddbf866520..0000000000 --- a/src/backend/port/dynloader/win32.h +++ /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 */ diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 2215ebbb5a..6d20b102f9 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -124,7 +124,6 @@ #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" diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index 1b0dbad82c..c2a257258d 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -16,11 +16,14 @@ #include -#include "dynloader.h" +#ifdef HAVE_DLOPEN +#include +#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 */ } diff --git a/src/include/.gitignore b/src/include/.gitignore index 49d108dbed..51819fb4dd 100644 --- a/src/include/.gitignore +++ b/src/include/.gitignore @@ -3,4 +3,3 @@ /pg_config.h /pg_config_ext.h /pg_config_os.h -/dynloader.h diff --git a/src/include/Makefile b/src/include/Makefile index 901eddbd44..6bdfd7db91 100644 --- a/src/include/Makefile +++ b/src/include/Makefile @@ -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 diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 347d5b56dc..4094e22776 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -158,6 +158,14 @@ 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 diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index 7a92d88999..6618b43587 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -127,6 +127,14 @@ 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 diff --git a/src/include/port.h b/src/include/port.h index 0ce72e50e5..6dd4e96cf3 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -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. + */ +#ifndef 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. + */ +#ifndef 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 index e2455b52ca..0000000000 --- a/src/include/utils/dynamic_loader.h +++ /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 */ diff --git a/src/backend/port/dynloader/win32.c b/src/port/dlopen.c similarity index 51% rename from src/backend/port/dynloader/win32.c rename to src/port/dlopen.c index c59823e367..897407c3af 100644 --- a/src/backend/port/dynloader/win32.c +++ b/src/port/dlopen.c @@ -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 +#include + +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 diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm index 60b5639df8..c8ae1a0dc7 100644 --- a/src/tools/msvc/Install.pm +++ b/src/tools/msvc/Install.pm @@ -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/', diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 4543d87d83..14d2a3c4cf 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -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', diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 7d7ce8b031..68cf812f01 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -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"; diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat index 1d9cd40bdb..7a23a2b55f 100755 --- a/src/tools/msvc/clean.bat +++ b/src/tools/msvc/clean.bat @@ -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 -- 2.18.0