Paul Eggert wrote: > I installed the > attached patch into coreutils. With it, 'sort -R' continues to use MD5 > but on GNUish platforms 'sort' links libcrypto dynamically only if -R is > used (Bruno's suggestion). This doesn't significantly affect 'sort -R' > performance, and reduces the startup overhead of plain 'sort'
The patch has no effect on openSUSE 15.5: DLOPEN_LIBCRYPTO is not defined in config.h. config.log shows a link error of the test program: undefined reference to symbol 'dlopen@@GLIBC_2.2.5' Both the test program and 'sort' need to link with -ldl. This is generally true on the following platforms: - glibc < 2.34, - Android (with some compilers, not with Termux (*)). (*) In the Android Termux environment, the compiler is configured to pass the options '-ldl -lc', rather than just '-lc', to the linker. Thus, we don't need to pass '-ldl' to the compiler. But the 'sort' program will be linked with -ldl. In other Android environments, things may be different, though. The proposed attached patch fixes the problem: It defines a variable LIB_DL that contains '-ldl' where needed or '' if not needed, and uses it with the test program and with 'sort'. You might think that this patch is no win, because it trades one link dependency for another link dependency? But that's not what it does: 'ldd' shows that without the patch, 'sort' loads the libraries linux-vdso.so.1 libcrypto.so.3 libpthread.so.0 libc.so.6 libz.so.1 libdl.so.2 /lib64/ld-linux-x86-64.so.2 and with the patch, 'sort' loads the libraries linux-vdso.so.1 libdl.so.2 libpthread.so.0 libc.so.6 /lib64/ld-linux-x86-64.so.2 — that is, libdl.so.2 is getting loaded anyway.
>From c30a0e55c95e0ae7062ee2ececf85cd0dbfe49fb Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 27 Feb 2024 12:12:59 +0100 Subject: [PATCH] sort: Make the startup time optimization effective on glibc < 2.34 * configure.ac: Test where to find the dlopen function. Set LIB_DL. Use it in the DLOPEN_LIBCRYPTO test. * src/local.mk (src_sort_LDADD): Add $(LIB_DL). --- configure.ac | 11 ++++++++++- src/local.mk | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index fe8408a06..248e30ca2 100644 --- a/configure.ac +++ b/configure.ac @@ -351,6 +351,15 @@ if test $utils_cv_localtime_cache = yes; then AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME]) fi +# Find the library for dynamic loading of shared libraries. +AC_SEARCH_LIBS([dlopen], [dl]) +AS_CASE([$ac_cv_search_dlopen], + [no | 'none required'], + [LIB_DL=], + [*], + [LIB_DL="$ac_cv_search_dlopen"]) +AC_SUBST([LIB_DL]) + # Should 'sort' link libcrypto dynamically? AS_CASE([$LIB_CRYPTO], [-lcrypto], @@ -360,7 +369,7 @@ AS_CASE([$LIB_CRYPTO], [utils_cv_dlopen_libcrypto], [utils_cv_dlopen_libcrypto=no saved_LIBS=$LIBS - LIBS="$LIBS $LIB_CRYPTO" + LIBS="$LIBS $LIB_DL $LIB_CRYPTO" AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include <dlfcn.h> diff --git a/src/local.mk b/src/local.mk index 7bc5ba5bc..96ee941ca 100644 --- a/src/local.mk +++ b/src/local.mk @@ -304,7 +304,7 @@ src_printf_LDADD += $(LIBICONV) # for libcrypto hash routines src_md5sum_LDADD += $(LIB_CRYPTO) -src_sort_LDADD += $(LIB_CRYPTO) +src_sort_LDADD += $(LIB_DL) $(LIB_CRYPTO) src_sha1sum_LDADD += $(LIB_CRYPTO) src_sha224sum_LDADD += $(LIB_CRYPTO) src_sha256sum_LDADD += $(LIB_CRYPTO) -- 2.34.1