]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: fix libcrypto version linked by sort at runtime
authorPádraig Brady <P@draigBrady.com>
Mon, 26 Feb 2024 16:38:41 +0000 (16:38 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 26 Feb 2024 17:33:02 +0000 (17:33 +0000)
One should link the versioned lib at runtime,
and the unversioned lib at build time,
as the unversioned lib may not be installed,
and better couples the binary with the required version.

* configure.ac: Define LIBCRYPTO_SONAME, determined from
the test binary linked with -lcrypto.  Also document
why we use SHA512() in the check, rather than MD5().
* src/sort.c (link_libcrypto): Use the versioned lib in dlopen().

configure.ac
src/sort.c

index 043081b907c1ede6481447f7a92c72ee79f87412..eb6c33aa45b4cced9954ff03e734f1ac4487bbd8 100644 (file)
@@ -365,12 +365,16 @@ AS_CASE([$LIB_CRYPTO],
           [AC_LANG_PROGRAM(
              [[#include <dlfcn.h>
                #include <openssl/sha.h>
+               /* Use SHA512 rather than MD5 here to avoid deprecation warnings.
+                  So need to check HAVE_OPENSSL_MD5.. with DLOPEN_LIBCRYPTO. */
              ]],
              [[return !(dlopen ("libcrypto.so", RTLD_LAZY | RTLD_GLOBAL)
                         && SHA512 (0, 0, 0));]])],
           [# readelf works with cross-builds; ldd works on more platforms.
-           AS_CASE([`(readelf -d conftest$EXEEXT || ldd conftest$EXEEXT
-                     ) 2>/dev/null`],
+           LIBCRYPTO_SONAME="`(readelf -d conftest$EXEEXT || ldd conftest$EXEEXT
+                              ) 2>/dev/null |
+                              sed -n 's/.*\(libcrypto.so.[[.0-9]]*\).*/\1/p'`"
+           AS_CASE([$LIBCRYPTO_SONAME],
              [*libcrypto*],
                [utils_cv_dlopen_libcrypto=yes])])
         LIBS=$saved_LIBS])
@@ -378,7 +382,10 @@ AS_CASE([$LIB_CRYPTO],
        [yes],
          [AC_DEFINE([DLOPEN_LIBCRYPTO], [1],
                     [Define to 1 if dlopen exists and libcrypto is
-                     linked dynamically.])])])
+                     linked dynamically.])
+          AC_DEFINE_UNQUOTED([LIBCRYPTO_SONAME], ["$LIBCRYPTO_SONAME"],
+                             [versioned libcrypto])
+         ])])
 
 # macOS >= 10.12
 AC_CHECK_FUNCS([fclonefileat])
index cefe381bfc917095decba08faba5f58df885cfdc..2d8324ca469a80adae81a5917f60d87ea057196f 100644 (file)
@@ -2125,7 +2125,7 @@ static void
 link_libcrypto (void)
 {
 #if DLOPEN_LIBCRYPTO && HAVE_OPENSSL_MD5
-  void *handle = dlopen ("libcrypto.so", RTLD_LAZY | RTLD_GLOBAL);
+  void *handle = dlopen (LIBCRYPTO_SONAME, RTLD_LAZY | RTLD_GLOBAL);
   if (!handle)
     link_failure ();
   ptr_MD5_Init = symbol_address (handle, "MD5_Init");