From: Pádraig Brady
Date: Mon, 26 Feb 2024 16:38:41 +0000 (+0000)
Subject: build: fix libcrypto version linked by sort at runtime
X-Git-Tag: v9.5~54
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bbdb39388cd0c5afdeb56e3048f90184cf07d6b;p=thirdparty%2Fcoreutils.git
build: fix libcrypto version linked by sort at runtime
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().
---
diff --git a/configure.ac b/configure.ac
index 043081b907..eb6c33aa45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -365,12 +365,16 @@ AS_CASE([$LIB_CRYPTO],
[AC_LANG_PROGRAM(
[[#include
#include
+ /* 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])
diff --git a/src/sort.c b/src/sort.c
index cefe381bfc..2d8324ca46 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -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");