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
From d9ee06fc45c31dd6e7857022c0775d1b3ccabd4a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@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 <wsanc...@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

From a0040d8d7b2ace5e1dece9dcf5d4fb4a647d8ed4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@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

From 689d31bbd8014c59051154a3130daf9fd3f81471 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@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

From b94f9c53bd1984933624c05103adb9879e0c503b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@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

From 94efb59833a3f9f79cfacc26c165ee7165f58b45 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@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

Reply via email to