remove ancient pre-dlopen dynloader code
The non-dlopen dynloader code for several operating systems is in some
cases decades obsolete, and I have had some doubts that it would even
compile anymore. Attached are patches for each operating system
removing the obsolete code, with references to when it became obsolete.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Remove-obsolete-darwin-dynloader-code.patchtext/plain; charset=UTF-8; name=0001-Remove-obsolete-darwin-dynloader-code.patch; x-mac-creator=0; x-mac-type=0Download
From d9ee06fc45c31dd6e7857022c0775d1b3ccabd4a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 10 Jul 2018 15:48:24 +0200
Subject: [PATCH 1/5] Remove obsolete darwin dynloader code
not needed since macOS 10.3 (2003)
---
src/backend/port/dynloader/darwin.c | 103 ----------------------------
1 file changed, 103 deletions(-)
diff --git a/src/backend/port/dynloader/darwin.c b/src/backend/port/dynloader/darwin.c
index 93f19878f5..65fa0e39f2 100644
--- a/src/backend/port/dynloader/darwin.c
+++ b/src/backend/port/dynloader/darwin.c
@@ -1,24 +1,15 @@
/*
* Dynamic loading support for macOS (Darwin)
*
- * If dlopen() is available (Darwin 10.3 and later), we just use it.
- * Otherwise we emulate it with the older, now deprecated, NSLinkModule API.
- *
* src/backend/port/dynloader/darwin.c
*/
#include "postgres.h"
-#ifdef HAVE_DLOPEN
#include <dlfcn.h>
-#else
-#include <mach-o/dyld.h>
-#endif
#include "dynloader.h"
-#ifdef HAVE_DLOPEN
-
void *
pg_dlopen(const char *filename)
{
@@ -34,7 +25,6 @@ pg_dlclose(void *handle)
PGFunction
pg_dlsym(void *handle, const char *funcname)
{
- /* Do not prepend an underscore: see dlopen(3) */
return dlsym(handle, funcname);
}
@@ -43,96 +33,3 @@ pg_dlerror(void)
{
return dlerror();
}
-#else /* !HAVE_DLOPEN */
-
-/*
- * These routines were taken from the Apache source, but were made
- * available with a PostgreSQL-compatible license. Kudos Wilfredo
- * Sánchez <wsanchez@apple.com>.
- */
-
-static NSObjectFileImageReturnCode cofiff_result = NSObjectFileImageFailure;
-
-void *
-pg_dlopen(const char *filename)
-{
- NSObjectFileImage image;
-
- cofiff_result = NSCreateObjectFileImageFromFile(filename, &image);
- if (cofiff_result != NSObjectFileImageSuccess)
- return NULL;
- return NSLinkModule(image, filename,
- NSLINKMODULE_OPTION_BINDNOW |
- NSLINKMODULE_OPTION_RETURN_ON_ERROR);
-}
-
-void
-pg_dlclose(void *handle)
-{
- NSUnLinkModule(handle, NSUNLINKMODULE_OPTION_NONE);
-}
-
-PGFunction
-pg_dlsym(void *handle, const char *funcname)
-{
- NSSymbol symbol;
- char *symname = (char *) malloc(strlen(funcname) + 2);
-
- if (!symname)
- return NULL;
-
- sprintf(symname, "_%s", funcname);
- if (NSIsSymbolNameDefined(symname))
- {
- symbol = NSLookupAndBindSymbol(symname);
-
- free(symname);
- return (PGFunction) NSAddressOfSymbol(symbol);
- }
- else
- {
- free(symname);
- return NULL;
- }
-}
-
-char *
-pg_dlerror(void)
-{
- NSLinkEditErrors c;
- int errorNumber;
- const char *fileName;
- const char *errorString = NULL;
-
- switch (cofiff_result)
- {
- case NSObjectFileImageSuccess:
- /* must have failed in NSLinkModule */
- NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
- if (errorString == NULL || *errorString == '\0')
- errorString = "unknown link-edit failure";
- break;
- case NSObjectFileImageFailure:
- errorString = "failed to open object file";
- break;
- case NSObjectFileImageInappropriateFile:
- errorString = "inappropriate object file";
- break;
- case NSObjectFileImageArch:
- errorString = "object file is for wrong architecture";
- break;
- case NSObjectFileImageFormat:
- errorString = "object file has wrong format";
- break;
- case NSObjectFileImageAccess:
- errorString = "insufficient permissions for object file";
- break;
- default:
- errorString = "unknown failure to open object file";
- break;
- }
-
- return (char *) errorString;
-}
-
-#endif /* HAVE_DLOPEN */
--
2.18.0
0002-Remove-obsolete-linux-dynloader-code.patchtext/plain; charset=UTF-8; name=0002-Remove-obsolete-linux-dynloader-code.patch; x-mac-creator=0; x-mac-type=0Download
From a0040d8d7b2ace5e1dece9dcf5d4fb4a647d8ed4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 10 Jul 2018 15:50:28 +0200
Subject: [PATCH 2/5] Remove obsolete linux dynloader code
This has been obsolete probably since the late 1990s.
---
configure | 2 +-
configure.in | 2 +-
src/backend/port/dynloader/linux.c | 134 +----------------------------
src/backend/port/dynloader/linux.h | 6 --
src/include/pg_config.h.in | 3 -
src/include/pg_config.h.win32 | 3 -
6 files changed, 6 insertions(+), 144 deletions(-)
diff --git a/configure b/configure
index 26652133d5..067fc43e4e 100755
--- a/configure
+++ b/configure
@@ -12495,7 +12495,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
fi
-for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
+for ac_header in atomic.h crypt.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/configure.in b/configure.in
index 397f6bc765..49257e5301 100644
--- a/configure.in
+++ b/configure.in
@@ -1260,7 +1260,7 @@ AC_SUBST(UUID_LIBS)
AC_HEADER_STDBOOL
-AC_CHECK_HEADERS([atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h])
+AC_CHECK_HEADERS([atomic.h crypt.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h])
# On BSD, test for net/if.h will fail unless sys/socket.h
# is included first.
diff --git a/src/backend/port/dynloader/linux.c b/src/backend/port/dynloader/linux.c
index 8735767add..2126576e8f 100644
--- a/src/backend/port/dynloader/linux.c
+++ b/src/backend/port/dynloader/linux.c
@@ -1,133 +1,7 @@
-/*-------------------------------------------------------------------------
+/*
+ * src/backend/port/dynloader/linux.c
*
- * linux.c
- * Dynamic Loader for Postgres for Linux, generated from those for
- * Ultrix.
+ * Dummy file used for nothing at this point
*
- * You need to install the dld library on your Linux system!
- *
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * src/backend/port/dynloader/linux.c
- *
- *-------------------------------------------------------------------------
+ * see linux.h
*/
-
-#include "postgres.h"
-
-#ifdef HAVE_DLD_H
-#include <dld.h>
-#endif
-
-#include "dynloader.h"
-#include "miscadmin.h"
-
-
-#ifndef HAVE_DLOPEN
-
-void *
-pg_dlopen(const char *filename)
-{
-#ifndef HAVE_DLD_H
- elog(ERROR, "dynamic load not supported");
- return NULL;
-#else
- static int dl_initialized = 0;
-
- /*
- * initializes the dynamic loader with the executable's pathname. (only
- * needs to do this the first time pg_dlopen is called.)
- */
- if (!dl_initialized)
- {
- if (dld_init(dld_find_executable(my_exec_path)))
- return NULL;
-
- /*
- * if there are undefined symbols, we want dl to search from the
- * following libraries also.
- */
- dl_initialized = 1;
- }
-
- /*
- * link the file, then check for undefined symbols!
- */
- if (dld_link(filename))
- return NULL;
-
- /*
- * If undefined symbols: try to link with the C and math libraries! This
- * could be smarter, if the dynamic linker was able to handle shared libs!
- */
- if (dld_undefined_sym_count > 0)
- {
- if (dld_link("/usr/lib/libc.a"))
- {
- elog(WARNING, "could not link C library");
- return NULL;
- }
- if (dld_undefined_sym_count > 0)
- {
- if (dld_link("/usr/lib/libm.a"))
- {
- elog(WARNING, "could not link math library");
- return NULL;
- }
- if (dld_undefined_sym_count > 0)
- {
- int count = dld_undefined_sym_count;
- char **list = dld_list_undefined_sym();
-
- /* list the undefined symbols, if any */
- do
- {
- elog(WARNING, "\"%s\" is undefined", *list);
- list++;
- count--;
- } while (count > 0);
-
- dld_unlink_by_file(filename, 1);
- return NULL;
- }
- }
- }
-
- return (void *) strdup(filename);
-#endif
-}
-
-PGFunction
-pg_dlsym(void *handle, const char *funcname)
-{
-#ifndef HAVE_DLD_H
- return NULL;
-#else
- return (PGFunction) dld_get_func((funcname));
-#endif
-}
-
-void
-pg_dlclose(void *handle)
-{
-#ifndef HAVE_DLD_H
-#else
- dld_unlink_by_file(handle, 1);
- free(handle);
-#endif
-}
-
-char *
-pg_dlerror(void)
-{
-#ifndef HAVE_DLD_H
- return "dynaloader unsupported";
-#else
- return dld_strerror(dld_errno);
-#endif
-}
-
-#endif /* !HAVE_DLOPEN */
diff --git a/src/backend/port/dynloader/linux.h b/src/backend/port/dynloader/linux.h
index df2852ac58..6beb3d63f8 100644
--- a/src/backend/port/dynloader/linux.h
+++ b/src/backend/port/dynloader/linux.h
@@ -15,12 +15,7 @@
#define PORT_PROTOS_H
#include "utils/dynamic_loader.h" /* pgrminclude ignore */
-#ifdef HAVE_DLOPEN
#include <dlfcn.h>
-#endif
-
-
-#ifdef HAVE_DLOPEN
/*
* In some older systems, the RTLD_NOW flag isn't defined and the mode
@@ -39,6 +34,5 @@
#define pg_dlsym dlsym
#define pg_dlclose dlclose
#define pg_dlerror dlerror
-#endif /* HAVE_DLOPEN */
#endif /* PORT_PROTOS_H */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index b7e469670f..827574ee40 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -186,9 +186,6 @@
don't. */
#undef HAVE_DECL_VSNPRINTF
-/* Define to 1 if you have the <dld.h> header file. */
-#undef HAVE_DLD_H
-
/* Define to 1 if you have the `dlopen' function. */
#undef HAVE_DLOPEN
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index ab276f7a95..46ce49def2 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -143,9 +143,6 @@
don't. */
#define HAVE_DECL_VSNPRINTF 1
-/* Define to 1 if you have the <dld.h> header file. */
-/* #undef HAVE_DLD_H */
-
/* Define to 1 if you have the `dlopen' function. */
/* #undef HAVE_DLOPEN */
--
2.18.0
0003-Remove-obsolete-freebsd-dynloader-code.patchtext/plain; charset=UTF-8; name=0003-Remove-obsolete-freebsd-dynloader-code.patch; x-mac-creator=0; x-mac-type=0Download
From 689d31bbd8014c59051154a3130daf9fd3f81471 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 10 Jul 2018 15:59:25 +0200
Subject: [PATCH 3/5] Remove obsolete freebsd dynloader code
dlopen() has been documented since FreeBSD 3.0 (1989).
---
src/backend/port/dynloader/freebsd.c | 103 +--------------------------
src/backend/port/dynloader/freebsd.h | 28 ++------
2 files changed, 6 insertions(+), 125 deletions(-)
diff --git a/src/backend/port/dynloader/freebsd.c b/src/backend/port/dynloader/freebsd.c
index 54ee0e8448..41b96ebaf0 100644
--- a/src/backend/port/dynloader/freebsd.c
+++ b/src/backend/port/dynloader/freebsd.c
@@ -1,106 +1,7 @@
/*
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
* src/backend/port/dynloader/freebsd.c
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * Dummy file used for nothing at this point
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * see freebsd.h
*/
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)dl.c 5.4 (Berkeley) 2/23/91";
-#endif /* LIBC_SCCS and not lint */
-
-#include "postgres.h"
-
-#include <nlist.h>
-#include <link.h>
-#include <dlfcn.h>
-
-#include "dynloader.h"
-
-static char error_message[BUFSIZ];
-
-char *
-BSD44_derived_dlerror(void)
-{
- static char ret[BUFSIZ];
-
- strcpy(ret, error_message);
- error_message[0] = 0;
- return (ret[0] == 0) ? NULL : ret;
-}
-
-void *
-BSD44_derived_dlopen(const char *file, int num)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) not supported", file);
- return NULL;
-#else
- void *vp;
-
- if ((vp = dlopen((char *) file, num)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) failed: %s", file, dlerror());
- return vp;
-#endif
-}
-
-void *
-BSD44_derived_dlsym(void *handle, const char *name)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return NULL;
-#else
- void *vp;
-
-#ifndef __ELF__
- char buf[BUFSIZ];
-
- if (*name != '_')
- {
- snprintf(buf, sizeof(buf), "_%s", name);
- name = buf;
- }
-#endif /* !__ELF__ */
- if ((vp = dlsym(handle, (char *) name)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return vp;
-#endif
-}
-
-void
-BSD44_derived_dlclose(void *handle)
-{
-#if defined(HAVE_DLOPEN)
- dlclose(handle);
-#endif
-}
diff --git a/src/backend/port/dynloader/freebsd.h b/src/backend/port/dynloader/freebsd.h
index d047b1662e..dbdd03cb3a 100644
--- a/src/backend/port/dynloader/freebsd.h
+++ b/src/backend/port/dynloader/freebsd.h
@@ -13,25 +13,10 @@
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
-#include <nlist.h>
-#include <link.h>
#include <dlfcn.h>
#include "utils/dynamic_loader.h" /* pgrminclude ignore */
-/*
- * Dynamic Loader on NetBSD 1.0.
- *
- * this dynamic loader uses the system dynamic loading interface for shared
- * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
- * library as the file to be dynamically loaded.
- *
- * agc - I know this is all a bit crufty, but it does work, is fairly
- * portable, and works (the stipulation that the d.l. function must
- * begin with an underscore is fairly tricky, and some versions of
- * NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
- */
-
/*
* 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
@@ -45,14 +30,9 @@
#define RTLD_GLOBAL 0
#endif
-#define pg_dlopen(f) BSD44_derived_dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym BSD44_derived_dlsym
-#define pg_dlclose BSD44_derived_dlclose
-#define pg_dlerror BSD44_derived_dlerror
-
-char *BSD44_derived_dlerror(void);
-void *BSD44_derived_dlopen(const char *filename, int num);
-void *BSD44_derived_dlsym(void *handle, const char *name);
-void BSD44_derived_dlclose(void *handle);
+#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 */
--
2.18.0
0004-Remove-obsolete-openbsd-dynloader-code.patchtext/plain; charset=UTF-8; name=0004-Remove-obsolete-openbsd-dynloader-code.patch; x-mac-creator=0; x-mac-type=0Download
From b94f9c53bd1984933624c05103adb9879e0c503b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 10 Jul 2018 16:04:03 +0200
Subject: [PATCH 4/5] Remove obsolete openbsd dynloader code
dlopen() has been documented since OpenBSD 2.0 (1996).
---
src/backend/port/dynloader/openbsd.c | 103 +--------------------------
src/backend/port/dynloader/openbsd.h | 28 ++------
2 files changed, 6 insertions(+), 125 deletions(-)
diff --git a/src/backend/port/dynloader/openbsd.c b/src/backend/port/dynloader/openbsd.c
index 2104915c6c..6a8e1d89d7 100644
--- a/src/backend/port/dynloader/openbsd.c
+++ b/src/backend/port/dynloader/openbsd.c
@@ -1,106 +1,7 @@
/*
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
* src/backend/port/dynloader/openbsd.c
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * Dummy file used for nothing at this point
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * see openbsd.h
*/
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)dl.c 5.4 (Berkeley) 2/23/91";
-#endif /* LIBC_SCCS and not lint */
-
-#include "postgres.h"
-
-#include <nlist.h>
-#include <link.h>
-#include <dlfcn.h>
-
-#include "dynloader.h"
-
-static char error_message[BUFSIZ];
-
-char *
-BSD44_derived_dlerror(void)
-{
- static char ret[BUFSIZ];
-
- strcpy(ret, error_message);
- error_message[0] = 0;
- return (ret[0] == 0) ? NULL : ret;
-}
-
-void *
-BSD44_derived_dlopen(const char *file, int num)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) not supported", file);
- return NULL;
-#else
- void *vp;
-
- if ((vp = dlopen((char *) file, num)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) failed: %s", file, dlerror());
- return vp;
-#endif
-}
-
-void *
-BSD44_derived_dlsym(void *handle, const char *name)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return NULL;
-#else
- void *vp;
-
-#ifndef __ELF__
- char buf[BUFSIZ];
-
- if (*name != '_')
- {
- snprintf(buf, sizeof(buf), "_%s", name);
- name = buf;
- }
-#endif /* !__ELF__ */
- if ((vp = dlsym(handle, (char *) name)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return vp;
-#endif
-}
-
-void
-BSD44_derived_dlclose(void *handle)
-{
-#if defined(HAVE_DLOPEN)
- dlclose(handle);
-#endif
-}
diff --git a/src/backend/port/dynloader/openbsd.h b/src/backend/port/dynloader/openbsd.h
index a184ca8ecd..78bfbed694 100644
--- a/src/backend/port/dynloader/openbsd.h
+++ b/src/backend/port/dynloader/openbsd.h
@@ -13,25 +13,10 @@
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
-#include <nlist.h>
-#include <link.h>
#include <dlfcn.h>
#include "utils/dynamic_loader.h" /* pgrminclude ignore */
-/*
- * Dynamic Loader on NetBSD 1.0.
- *
- * this dynamic loader uses the system dynamic loading interface for shared
- * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
- * library as the file to be dynamically loaded.
- *
- * agc - I know this is all a bit crufty, but it does work, is fairly
- * portable, and works (the stipulation that the d.l. function must
- * begin with an underscore is fairly tricky, and some versions of
- * NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
- */
-
/*
* 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
@@ -45,14 +30,9 @@
#define RTLD_GLOBAL 0
#endif
-#define pg_dlopen(f) BSD44_derived_dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym BSD44_derived_dlsym
-#define pg_dlclose BSD44_derived_dlclose
-#define pg_dlerror BSD44_derived_dlerror
-
-char *BSD44_derived_dlerror(void);
-void *BSD44_derived_dlopen(const char *filename, int num);
-void *BSD44_derived_dlsym(void *handle, const char *name);
-void BSD44_derived_dlclose(void *handle);
+#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 */
--
2.18.0
0005-Remove-obsolete-netbsd-dynloader-code.patchtext/plain; charset=UTF-8; name=0005-Remove-obsolete-netbsd-dynloader-code.patch; x-mac-creator=0; x-mac-type=0Download
From 94efb59833a3f9f79cfacc26c165ee7165f58b45 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 10 Jul 2018 16:07:10 +0200
Subject: [PATCH 5/5] Remove obsolete netbsd dynloader code
dlopen() has been documented since NetBSD 1.1 (1995).
---
src/backend/port/dynloader/netbsd.c | 103 +---------------------------
src/backend/port/dynloader/netbsd.h | 29 ++------
2 files changed, 6 insertions(+), 126 deletions(-)
diff --git a/src/backend/port/dynloader/netbsd.c b/src/backend/port/dynloader/netbsd.c
index 7b8d90caa7..8f7f56864d 100644
--- a/src/backend/port/dynloader/netbsd.c
+++ b/src/backend/port/dynloader/netbsd.c
@@ -1,106 +1,7 @@
/*
- * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
- * Portions Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
* src/backend/port/dynloader/netbsd.c
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * Dummy file used for nothing at this point
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * see netbsd.h
*/
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)dl.c 5.4 (Berkeley) 2/23/91";
-#endif /* LIBC_SCCS and not lint */
-
-#include "postgres.h"
-
-#include <nlist.h>
-#include <link.h>
-#include <dlfcn.h>
-
-#include "dynloader.h"
-
-static char error_message[BUFSIZ];
-
-char *
-BSD44_derived_dlerror(void)
-{
- static char ret[BUFSIZ];
-
- strcpy(ret, error_message);
- error_message[0] = 0;
- return (ret[0] == 0) ? NULL : ret;
-}
-
-void *
-BSD44_derived_dlopen(const char *file, int num)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) not supported", file);
- return NULL;
-#else
- void *vp;
-
- if ((vp = dlopen((char *) file, num)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlopen (%s) failed: %s", file, dlerror());
- return vp;
-#endif
-}
-
-void *
-BSD44_derived_dlsym(void *handle, const char *name)
-{
-#if !defined(HAVE_DLOPEN)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return NULL;
-#else
- void *vp;
-
-#ifndef __ELF__
- char buf[BUFSIZ];
-
- if (*name != '_')
- {
- snprintf(buf, sizeof(buf), "_%s", name);
- name = buf;
- }
-#endif /* !__ELF__ */
- if ((vp = dlsym(handle, (char *) name)) == NULL)
- snprintf(error_message, sizeof(error_message),
- "dlsym (%s) failed", name);
- return vp;
-#endif
-}
-
-void
-BSD44_derived_dlclose(void *handle)
-{
-#if defined(HAVE_DLOPEN)
- dlclose(handle);
-#endif
-}
diff --git a/src/backend/port/dynloader/netbsd.h b/src/backend/port/dynloader/netbsd.h
index 823574abf0..f3c38eb98a 100644
--- a/src/backend/port/dynloader/netbsd.h
+++ b/src/backend/port/dynloader/netbsd.h
@@ -3,7 +3,6 @@
* 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
*
@@ -14,25 +13,10 @@
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H
-#include <nlist.h>
-#include <link.h>
#include <dlfcn.h>
#include "utils/dynamic_loader.h" /* pgrminclude ignore */
-/*
- * Dynamic Loader on NetBSD 1.0.
- *
- * this dynamic loader uses the system dynamic loading interface for shared
- * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
- * library as the file to be dynamically loaded.
- *
- * agc - I know this is all a bit crufty, but it does work, is fairly
- * portable, and works (the stipulation that the d.l. function must
- * begin with an underscore is fairly tricky, and some versions of
- * NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
- */
-
/*
* 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
@@ -46,14 +30,9 @@
#define RTLD_GLOBAL 0
#endif
-#define pg_dlopen(f) BSD44_derived_dlopen((f), RTLD_NOW | RTLD_GLOBAL)
-#define pg_dlsym BSD44_derived_dlsym
-#define pg_dlclose BSD44_derived_dlclose
-#define pg_dlerror BSD44_derived_dlerror
-
-char *BSD44_derived_dlerror(void);
-void *BSD44_derived_dlopen(const char *filename, int num);
-void *BSD44_derived_dlsym(void *handle, const char *name);
-void BSD44_derived_dlclose(void *handle);
+#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 */
--
2.18.0
Hi,
On 2018-08-09 14:29:08 +0200, Peter Eisentraut wrote:
The non-dlopen dynloader code for several operating systems is in some
cases decades obsolete, and I have had some doubts that it would even
compile anymore. Attached are patches for each operating system
removing the obsolete code, with references to when it became obsolete.
Cool, I encountered those files a couple times when grepping for
things. +1 for the removal.
Greetings,
Andres Freund
Andres Freund <andres@anarazel.de> writes:
On 2018-08-09 14:29:08 +0200, Peter Eisentraut wrote:
The non-dlopen dynloader code for several operating systems is in some
cases decades obsolete, and I have had some doubts that it would even
compile anymore. Attached are patches for each operating system
removing the obsolete code, with references to when it became obsolete.
Cool, I encountered those files a couple times when grepping for
things. +1 for the removal.
LGTM, too.
regards, tom lane
On 2018-08-09 10:03:43 -0400, Tom Lane wrote:
Andres Freund <andres@anarazel.de> writes:
On 2018-08-09 14:29:08 +0200, Peter Eisentraut wrote:
The non-dlopen dynloader code for several operating systems is in some
cases decades obsolete, and I have had some doubts that it would even
compile anymore. Attached are patches for each operating system
removing the obsolete code, with references to when it became obsolete.Cool, I encountered those files a couple times when grepping for
things. +1 for the removal.LGTM, too.
This now generates a super nitpicky warning on at at least some linux +
clang configurations. I use -Weverything plus a lot of -Wno-*, and this
change added:
dynloader.c:7:4: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit]
*/
^
1 warning generated.
I'll probably just neuter the warning, but I wanted to nevertheless
raise the "issue".
Greetings,
Andres Freund
Andres Freund <andres@anarazel.de> writes:
This now generates a super nitpicky warning on at at least some linux +
clang configurations. I use -Weverything plus a lot of -Wno-*, and this
change added:
dynloader.c:7:4: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit]
We've been seeing that (or equivalents) on other platforms for years,
if not decades. I can't get too excited about it really.
The lazy man's way to get rid of it would be to put something like
"int bogus = 0;" in the empty dynloader.c files. Better would be
to not have the empty .c files at all, but I'm not sure how much
we'd have to contort the Makefiles to support that.
regards, tom lane
On 2018-08-16 09:22:14 -0400, Tom Lane wrote:
Andres Freund <andres@anarazel.de> writes:
This now generates a super nitpicky warning on at at least some linux +
clang configurations. I use -Weverything plus a lot of -Wno-*, and this
change added:
dynloader.c:7:4: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit]We've been seeing that (or equivalents) on other platforms for years,
if not decades. I can't get too excited about it really.
Yea, me neither.
The lazy man's way to get rid of it would be to put something like
"int bogus = 0;" in the empty dynloader.c files. Better would be
to not have the empty .c files at all, but I'm not sure how much
we'd have to contort the Makefiles to support that.
If I had my druthers, we'd just remove all that configure magic for
selecting these files and just use ifdefs. Personally I find it
occasionally that they're linked into place, rather than built under
their original name.
Greetings,
Andres Freund
Andres Freund <andres@anarazel.de> writes:
On 2018-08-16 09:22:14 -0400, Tom Lane wrote:
The lazy man's way to get rid of it would be to put something like
"int bogus = 0;" in the empty dynloader.c files. Better would be
to not have the empty .c files at all, but I'm not sure how much
we'd have to contort the Makefiles to support that.
If I had my druthers, we'd just remove all that configure magic for
selecting these files and just use ifdefs. Personally I find it
occasionally that they're linked into place, rather than built under
their original name.
Even if we all agreed that was an improvement (which I'm not sure of),
it wouldn't fix this problem would it? On affected platforms, the
file would still be empty after preprocessing.
regards, tom lane
On 2018-08-16 10:07:04 -0400, Tom Lane wrote:
Andres Freund <andres@anarazel.de> writes:
On 2018-08-16 09:22:14 -0400, Tom Lane wrote:
The lazy man's way to get rid of it would be to put something like
"int bogus = 0;" in the empty dynloader.c files. Better would be
to not have the empty .c files at all, but I'm not sure how much
we'd have to contort the Makefiles to support that.If I had my druthers, we'd just remove all that configure magic for
selecting these files and just use ifdefs. Personally I find it
occasionally that they're linked into place, rather than built under
their original name.Even if we all agreed that was an improvement (which I'm not sure of),
it wouldn't fix this problem would it? On affected platforms, the
file would still be empty after preprocessing.
Well, that depends on what you put into that file, it seems
realistically combinable with a bunch of non-conditional code...
Anyway, I'm not planning to do something here right now besides putting
-Wno-empty-translation-unit into my scripts, I just wanted to make sure
people are aware that we hit this now.
Greetings,
Andres Freund
On 16/08/2018 16:10, Andres Freund wrote:
If I had my druthers, we'd just remove all that configure magic for
selecting these files and just use ifdefs. Personally I find it
occasionally that they're linked into place, rather than built under
their original name.Even if we all agreed that was an improvement (which I'm not sure of),
it wouldn't fix this problem would it? On affected platforms, the
file would still be empty after preprocessing.Well, that depends on what you put into that file, it seems
realistically combinable with a bunch of non-conditional code...
How about this: We only have two nonstandard dlopen() implementations
left: Windows and (old) HP-UX. We move those into src/port/dlopen.c and
treat it like a regular libpgport member. That gets rid of all those
duplicative empty per-platform files.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Refactor-dlopen-support.patchtext/plain; charset=UTF-8; name=0001-Refactor-dlopen-support.patch; x-mac-creator=0; x-mac-type=0Download
From 4511238fb6eab337e697e6080f1a1f33ba114f99 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Wed, 29 Aug 2018 20:57:07 +0200
Subject: [PATCH] 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/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 | 3 -
src/tools/msvc/Solution.pm | 7 --
src/tools/msvc/clean.bat | 1 -
36 files changed, 163 insertions(+), 539 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 <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
@@ -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 <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}
])
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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 */
}
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/port.h b/src/include/port.h
index 74a9dc4d4d..cfe5982db4 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -400,6 +400,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 <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
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..efa975a0bf 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -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
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
How about this: We only have two nonstandard dlopen() implementations
left: Windows and (old) HP-UX. We move those into src/port/dlopen.c and
treat it like a regular libpgport member. That gets rid of all those
duplicative empty per-platform files.
+1. I eyeballed the patch quickly and it looks sane, but I didn't
try to test it. Being a lazy person, I don't want to test it manually,
but I'll be happy to queue up a gaur run as soon as you push it
(and if by some chance that shows a problem, I'll fix it).
regards, tom lane
On 2018-08-31 10:52:18 +0200, Peter Eisentraut wrote:
How about this: We only have two nonstandard dlopen() implementations
left: Windows and (old) HP-UX. We move those into src/port/dlopen.c and
treat it like a regular libpgport member. That gets rid of all those
duplicative empty per-platform files.
Great! Quickly skimmed the patch and it looks good. I don't quite know
why you moved the implementation to src/port rather than
src/backend/port, but either is fine with me... Long term the former
probably is better.
Greetings,
Andres Freund
On 31/08/2018 10:52, Peter Eisentraut wrote:
On 16/08/2018 16:10, Andres Freund wrote:
If I had my druthers, we'd just remove all that configure magic for
selecting these files and just use ifdefs. Personally I find it
occasionally that they're linked into place, rather than built under
their original name.Even if we all agreed that was an improvement (which I'm not sure of),
it wouldn't fix this problem would it? On affected platforms, the
file would still be empty after preprocessing.Well, that depends on what you put into that file, it seems
realistically combinable with a bunch of non-conditional code...How about this: We only have two nonstandard dlopen() implementations
left: Windows and (old) HP-UX. We move those into src/port/dlopen.c and
treat it like a regular libpgport member. That gets rid of all those
duplicative empty per-platform files.
Updated patch. It needed some adjustments for Windows, per Appveyor,
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v2-0001-Refactor-dlopen-support.patchtext/plain; charset=UTF-8; name=v2-0001-Refactor-dlopen-support.patch; x-mac-creator=0; x-mac-type=0Download
From cb7ba655d4eb032412be0e63d75c4e4cd07ee049 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
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 <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
@@ -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 <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}
])
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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 */
}
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 <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
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
On 01/09/2018 06:51, Peter Eisentraut wrote:
How about this: We only have two nonstandard dlopen() implementations
left: Windows and (old) HP-UX. We move those into src/port/dlopen.c and
treat it like a regular libpgport member. That gets rid of all those
duplicative empty per-platform files.Updated patch. It needed some adjustments for Windows, per Appveyor,
I'm going to use this thread for a moment to work out some details with
the cfbot.
The v2 patch I sent previously was created using git format-patch with
default settings. This detected a rename:
rename src/{backend/port/dynloader/win32.c => port/dlopen.c} (51%)
which is fair enough. However, whatever method the cfbot uses to apply
patches fails to handle that. The tree that is sent for testing by
Appveyor still contains a full src/backend/port/dynloader/win32.c and no
src/port/dlopen.c, which expectedly makes the build fail. (It also
still contains src/backend/port/dynloader/otherplatform.c, but empty, so
the patching doesn't remove empty files, which is another but minor
problem.)
The v3 patch attached here was made with git format-patch --no-renames.
Let's see how that works out.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v3-0001-Refactor-dlopen-support.patchtext/plain; charset=UTF-8; name=v3-0001-Refactor-dlopen-support.patch; x-mac-creator=0; x-mac-type=0Download
From 297f4f6ac3ae46b3678554964a5985d71e5908b9 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 6 Sep 2018 10:07:24 +0200
Subject: [PATCH v3] 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.c | 85 ----------------
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 -----
src/port/dlopen.c | 145 +++++++++++++++++++++++++++
src/tools/msvc/Install.pm | 5 +-
src/tools/msvc/Mkvcbuild.pm | 5 +-
src/tools/msvc/Solution.pm | 7 --
src/tools/msvc/clean.bat | 1 -
38 files changed, 251 insertions(+), 619 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.c
delete mode 100644 src/backend/port/dynloader/win32.h
delete mode 100644 src/include/utils/dynamic_loader.h
create mode 100644 src/port/dlopen.c
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 <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
@@ -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 <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}
])
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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
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 <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.c b/src/backend/port/dynloader/win32.c
deleted file mode 100644
index c59823e367..0000000000
--- a/src/backend/port/dynloader/win32.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* src/backend/port/dynloader/win32.c */
-
-#include "postgres.h"
-
-char *dlerror(void);
-int dlclose(void *handle);
-void *dlsym(void *handle, const char *symbol);
-void *dlopen(const char *path, int mode);
-
-static char last_dyn_error[512];
-
-static void
-set_dl_error(void)
-{
- DWORD err = GetLastError();
-
- if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- err,
- MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
- last_dyn_error,
- sizeof(last_dyn_error) - 1,
- NULL) == 0)
- {
- snprintf(last_dyn_error, sizeof(last_dyn_error) - 1,
- "unknown error %lu", err);
- }
-}
-
-char *
-dlerror(void)
-{
- if (last_dyn_error[0])
- return last_dyn_error;
- else
- return NULL;
-}
-
-int
-dlclose(void *handle)
-{
- if (!FreeLibrary((HMODULE) handle))
- {
- set_dl_error();
- return 1;
- }
- last_dyn_error[0] = 0;
- return 0;
-}
-
-void *
-dlsym(void *handle, const char *symbol)
-{
- void *ptr;
-
- ptr = GetProcAddress((HMODULE) handle, symbol);
- if (!ptr)
- {
- set_dl_error();
- return NULL;
- }
- last_dyn_error[0] = 0;
- return ptr;
-}
-
-void *
-dlopen(const char *path, int mode)
-{
- HMODULE h;
- int prevmode;
-
- /* Disable popup error messages when loading DLLs */
- prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
- h = LoadLibrary(path);
- SetErrorMode(prevmode);
-
- if (!h)
- {
- set_dl_error();
- return NULL;
- }
- last_dyn_error[0] = 0;
- return (void *) 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 7fb4296b7a..305ff36258 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 <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 */
}
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..d92756111f 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.
+ */
+#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
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/port/dlopen.c b/src/port/dlopen.c
new file mode 100644
index 0000000000..897407c3af
--- /dev/null
+++ b/src/port/dlopen.c
@@ -0,0 +1,145 @@
+/*-------------------------------------------------------------------------
+ *
+ * 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 "c.h"
+
+#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];
+
+static void
+set_dl_error(void)
+{
+ DWORD err = GetLastError();
+
+ if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ err,
+ MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
+ last_dyn_error,
+ sizeof(last_dyn_error) - 1,
+ NULL) == 0)
+ {
+ snprintf(last_dyn_error, sizeof(last_dyn_error) - 1,
+ "unknown error %lu", err);
+ }
+}
+
+char *
+dlerror(void)
+{
+ if (last_dyn_error[0])
+ return last_dyn_error;
+ else
+ return NULL;
+}
+
+int
+dlclose(void *handle)
+{
+ if (!FreeLibrary((HMODULE) handle))
+ {
+ set_dl_error();
+ return 1;
+ }
+ last_dyn_error[0] = 0;
+ return 0;
+}
+
+void *
+dlsym(void *handle, const char *symbol)
+{
+ void *ptr;
+
+ ptr = GetProcAddress((HMODULE) handle, symbol);
+ if (!ptr)
+ {
+ set_dl_error();
+ return NULL;
+ }
+ last_dyn_error[0] = 0;
+ return ptr;
+}
+
+void *
+dlopen(const char *path, int mode)
+{
+ HMODULE h;
+ int prevmode;
+
+ /* Disable popup error messages when loading DLLs */
+ prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+ h = LoadLibrary(path);
+ SetErrorMode(prevmode);
+
+ if (!h)
+ {
+ set_dl_error();
+ return NULL;
+ }
+ 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
On 06/09/2018 10:16, Peter Eisentraut wrote:
The v3 patch attached here was made with git format-patch --no-renames.
Let's see how that works out.
That worked, and the patch has been committed.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
On 06/09/2018 10:16, Peter Eisentraut wrote:
The v3 patch attached here was made with git format-patch --no-renames.
Let's see how that works out.
That worked, and the patch has been committed.
Sure enough, gaur's not happy. I'll take a look in a bit.
regards, tom lane
On Thu, Sep 6, 2018 at 1:16 AM Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
I'm going to use this thread for a moment to work out some details with
the cfbot.The v2 patch I sent previously was created using git format-patch with
default settings. This detected a rename:rename src/{backend/port/dynloader/win32.c => port/dlopen.c} (51%)
which is fair enough. However, whatever method the cfbot uses to apply
patches fails to handle that.
Interesting. Its version of "patch" doesn't understand that. I am
not sure if other versions of patch do. Currently cfbot doesn't use
git am because not everyone is posting patches created with
format-patch, and I thought good old patch could handle basically
anything. I wasn't aware of this quirk. I'll see if there is some
way I can convince patch to respect renames, or I should try to apply
with git first and then fall back to patch only if that fails.
--
Thomas Munro
http://www.enterprisedb.com