Remove configure probe for dlopen, and refactor.
authorThomas Munro <tmunro@postgresql.org>
Thu, 4 Aug 2022 21:12:45 +0000 (09:12 +1200)
committerThomas Munro <tmunro@postgresql.org>
Thu, 4 Aug 2022 21:12:45 +0000 (09:12 +1200)
dlopen() is in SUSv2 and all targeted Unix systems have it.  We still
need replacement functions for Windows, but we don't need a configure
probe for that.

Since it's no longer needed by other operating systems, rename dlopen.c
to win32dlopen.c and move the declarations into win32_port.h.

Likewise, the macros RTLD_NOW and RTLD_GLOBAL now only need to be
defined on Windows, since all targeted Unix systems have 'em.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com

configure
configure.ac
src/backend/utils/fmgr/dfmgr.c
src/include/pg_config.h.in
src/include/port.h
src/include/port/win32_port.h
src/port/win32dlopen.c [moved from src/port/dlopen.c with 93% similarity]
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Solution.pm

index c5bc382395804c9921b76a50412844abd7369201..2583a04a876209c2e85a33fa0660484c96e929ff 100755 (executable)
--- a/configure
+++ b/configure
@@ -16618,30 +16618,6 @@ 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
-
-
 ac_fn_c_check_type "$LINENO" "struct sockaddr_in6" "ac_cv_type_struct_sockaddr_in6" "$ac_includes_default
 #include <netinet/in.h>
 "
@@ -16687,19 +16663,6 @@ $as_echo "#define HAVE_PS_STRINGS 1" >>confdefs.h
 
 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" "explicit_bzero" "ac_cv_func_explicit_bzero"
 if test "x$ac_cv_func_explicit_bzero" = xyes; then :
   $as_echo "#define HAVE_EXPLICIT_BZERO 1" >>confdefs.h
@@ -17078,6 +17041,12 @@ esac
  ;;
 esac
 
+  case " $LIBOBJS " in
+  *" win32dlopen.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS win32dlopen.$ac_objext"
+ ;;
+esac
+
   case " $LIBOBJS " in
   *" win32env.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS win32env.$ac_objext"
index 61d0dd5d5869e465b78a4a62d98ab0241392ae0d..84bdaeb46c51cb87c580c6a965a716f94d9636f6 100644 (file)
@@ -1858,8 +1858,6 @@ AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
 # 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>])
-
 AC_CHECK_TYPE([struct sockaddr_in6],
         [AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if you have support for IPv6.])],
         [],
@@ -1880,7 +1878,6 @@ if test "$pgac_cv_var_PS_STRINGS" = yes ; then
 fi
 
 AC_REPLACE_FUNCS(m4_normalize([
-   dlopen
    explicit_bzero
    getopt
    getpeereid
@@ -1962,6 +1959,7 @@ if test "$PORTNAME" = "win32"; then
   AC_LIBOBJ(kill)
   AC_LIBOBJ(open)
   AC_LIBOBJ(system)
+  AC_LIBOBJ(win32dlopen)
   AC_LIBOBJ(win32env)
   AC_LIBOBJ(win32error)
   AC_LIBOBJ(win32ntdll)
index 7f9ea9728042fe86f9fc00c79b33509eebf804e9..08fd7e1264889b5b7b913df17e23757c2d38a534 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <sys/stat.h>
 
-#ifdef HAVE_DLOPEN
+#ifndef WIN32
 #include <dlfcn.h>
 
 /*
@@ -28,7 +28,7 @@
 #undef bool
 #endif
 #endif
-#endif                         /* HAVE_DLOPEN */
+#endif                         /* !WIN32 */
 
 #include "fmgr.h"
 #include "lib/stringinfo.h"
index f9618e19863778ffa7e7076cbcf5b8008d4dad67..ab812bca8913c5918de5b73d14d87fe90b4a45fa 100644 (file)
    don't. */
 #undef HAVE_DECL_PWRITEV
 
-/* 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 `strlcat', and to 0 if you
    don't. */
 #undef HAVE_DECL_STRLCAT
    don't. */
 #undef HAVE_DECL_STRTOULL
 
-/* Define to 1 if you have the `dlopen' function. */
-#undef HAVE_DLOPEN
-
 /* Define to 1 if you have the <editline/history.h> header file. */
 #undef HAVE_EDITLINE_HISTORY_H
 
index d39b04141f994d5f0f61921a594314cf6b7ee47a..323df8f9eded01ff2857c6cb1e9ce8c98658f986 100644 (file)
@@ -455,29 +455,6 @@ extern int setenv(const char *name, const char *value, int overwrite);
 extern int unsetenv(const char *name);
 #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.c */
 #ifndef WIN32
 extern bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen);
index 4de5bf3bf606c37ecf7fb612fd8d7c1f285959fe..a48eed53eb705965fb5c179f1eb72ac6bdea5242 100644 (file)
@@ -503,6 +503,15 @@ extern int pgwin32_ReserveSharedMemoryRegion(HANDLE);
 /* in backend/port/win32/crashdump.c */
 extern void pgwin32_install_crashdump_handler(void);
 
+/* in port/win32dlopen.c */
+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);
+
+#define RTLD_NOW 1
+#define RTLD_GLOBAL 0
+
 /* in port/win32error.c */
 extern void _dosmaperr(unsigned long);
 
similarity index 93%
rename from src/port/dlopen.c
rename to src/port/win32dlopen.c
index 6ff9f4bf64f859b7e755ca971396bbedd68d4e03..2657537c29497c874fa80514e4250bb8f681fa05 100644 (file)
@@ -1,22 +1,20 @@
 /*-------------------------------------------------------------------------
  *
- * dlopen.c
- *   dynamic loader for platforms without dlopen()
+ * win32dlopen.c
+ *   dynamic loader for Windows
  *
  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *   src/port/dlopen.c
+ *   src/port/win32dlopen.c
  *
  *-------------------------------------------------------------------------
  */
 
 #include "c.h"
 
-#if defined(WIN32)
-
 static char last_dyn_error[512];
 
 static void
@@ -93,5 +91,3 @@ dlopen(const char *file, int mode)
    last_dyn_error[0] = 0;
    return (void *) h;
 }
-
-#endif
index c935f776e51badd9281b875f2c4714421279a7c0..266f98e2ed4d1460fc04e77b099ad22fb30d5922 100644 (file)
@@ -103,11 +103,12 @@ sub mkvcbuild
      getpeereid.c getrusage.c inet_aton.c
      getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
      snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
-     dirent.c dlopen.c getopt.c getopt_long.c link.c
+     dirent.c getopt.c getopt_long.c link.c
      pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c
      pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
      pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c
      strerror.c tar.c
+     win32dlopen.c
      win32env.c win32error.c win32ntdll.c
      win32security.c win32setlocale.c win32stat.c);
 
index b09872e018d29f3c77cae302dead3b5ba470a684..a7a5c31a5b63c46081a6216f38b692af7f7a92e6 100644 (file)
@@ -244,14 +244,11 @@ sub GenerateFiles
        HAVE_DECL_POSIX_FADVISE                     => 0,
        HAVE_DECL_PREADV                            => 0,
        HAVE_DECL_PWRITEV                           => 0,
-       HAVE_DECL_RTLD_GLOBAL                       => 0,
-       HAVE_DECL_RTLD_NOW                          => 0,
        HAVE_DECL_STRLCAT                           => 0,
        HAVE_DECL_STRLCPY                           => 0,
        HAVE_DECL_STRNLEN                           => 1,
        HAVE_DECL_STRTOLL                           => 1,
        HAVE_DECL_STRTOULL                          => 1,
-       HAVE_DLOPEN                                 => undef,
        HAVE_EDITLINE_HISTORY_H                     => undef,
        HAVE_EDITLINE_READLINE_H                    => undef,
        HAVE_EXECINFO_H                             => undef,