From cb5e41b160838880de7d03100afa02e4edee5a9e Mon Sep 17 00:00:00 2001 From: Robert Clausecker Date: Fri, 11 Oct 2024 17:41:52 +0200 Subject: [PATCH] lib/libcrypt: unbundle hash functions libcrypt bundles the various hash functions it needs, duplicating code that is also found in libmd. Unbundle the hash functions and apply the same hack used for libncursesw so static consumers link -lmd in addition to -lcrypt. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D47062 --- Makefile.inc1 | 1 + lib/Makefile | 1 + lib/libcrypt/Makefile | 41 ++++++++++++++++++--------------- lib/libcrypt/libcrypt.aldscript | 1 + lib/libcrypt/libcrypt.ldscript | 1 + share/mk/src.libnames.mk | 1 + 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 lib/libcrypt/libcrypt.aldscript create mode 100644 lib/libcrypt/libcrypt.ldscript diff --git a/Makefile.inc1 b/Makefile.inc1 index 0a8895933bea..69a1ad2c8d01 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -3223,6 +3223,7 @@ lib/libc__L: lib/libsys__L lib/libgcc_s__L: lib/libc__L lib/libgcc_s__L: lib/libc_nonshared__L lib/libcxxrt__L: lib/libgcc_s__L +lib/libcrypt__L: lib/libmd__L _prebuild_libs= ${_kerberos5_lib_libasn1} \ ${_kerberos5_lib_libhdb} \ diff --git a/lib/Makefile b/lib/Makefile index e4a4aa95a1ef..fdfe198bea10 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -128,6 +128,7 @@ SUBDIR_DEPEND_libc++:= libcxxrt SUBDIR_DEPEND_libc= libsys libcompiler_rt libssp_nonshared SUBDIR_DEPEND_libcam= libsbuf SUBDIR_DEPEND_libcasper= libnv +SUBDIR_DEPEND_libcrypt= libmd SUBDIR_DEPEND_libdevstat= libkvm SUBDIR_DEPEND_libdpv= libfigpar ncurses libutil SUBDIR_DEPEND_libedit= ncurses diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile index d9bd85f7e699..5a9eac4c682f 100644 --- a/lib/libcrypt/Makefile +++ b/lib/libcrypt/Makefile @@ -10,17 +10,15 @@ PACKAGE= runtime SHLIB_MAJOR= 5 LIB= crypt -.PATH: ${SRCTOP}/sys/kern ${SRCTOP}/sys/crypto/sha2 SRCS= crypt.c misc.c \ - crypt-md5.c md5c.c \ - crypt-nthash.c md4c.c \ - crypt-sha256.c sha256c.c \ - crypt-sha512.c sha512c.c + crypt-md5.c \ + crypt-nthash.c \ + crypt-sha256.c \ + crypt-sha512.c MAN= crypt.3 MLINKS= crypt.3 crypt_get_format.3 crypt.3 crypt_r.3 \ crypt.3 crypt_set_format.3 -CFLAGS+= -I${SRCTOP}/lib/libmd \ - -I${SRCTOP}/sys/crypto/sha2 +CFLAGS+= -I${SRCTOP}/lib/libmd # Pull in the strong crypto, if it is present. .if exists(${SRCTOP}/secure/lib/libcrypt) && ${MK_CRYPT} != "no" @@ -29,17 +27,6 @@ SRCS+= crypt-des.c crypt-blowfish.c blowfish.c CFLAGS+= -I${.CURDIR} -DHAS_DES -DHAS_BLOWFISH .endif -.for sym in MD4Init MD4Final MD4Update MD4Pad \ - MD5Init MD5Final MD5Update MD5Pad \ - SHA224_Init SHA224_Final SHA224_Update \ - SHA256_Init SHA256_Final SHA256_Update \ - SHA512_224_Init SHA512_224_Final SHA512_224_Update \ - SHA512_256_Init SHA512_256_Final SHA512_256_Update \ - SHA384_Init SHA384_Final SHA384_Update \ - SHA512_Init SHA512_Final SHA512_Update -CFLAGS+= -D${sym}=__${sym} -.endfor - WARNS?= 2 PRECIOUSLIB= @@ -47,4 +34,22 @@ PRECIOUSLIB= HAS_TESTS= SUBDIR.${MK_TESTS}+= tests +LIBADD+= md +SHLIB_LDSCRIPT= libcrypt.ldscript +STATIC_LDSCRIPT= libcrypt.aldscript +CLEANFILES+= libcrypt.ald + +libcrypt.ald: ${.CURDIR}/${STATIC_LDSCRIPT} + sed -e 's,@@LIB@@,${LIB},g' \ + -e 's,@@STATICLIB_SUFFIX@@,${_STATICLIB_SUFFIX},g' \ + ${.ALLSRC} > ${.TARGET} + +all: ${STATIC_LDSCRIPT} libcrypt.ald + +install-libcrypt.a: libcrypt.ald + ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ + ${_INSTALLFLAGS} libcrypt.ald ${DESTDIR}${_LIBDIR}/lib${LIB}.a + +realinstall: install-libcrypt.a + .include diff --git a/lib/libcrypt/libcrypt.aldscript b/lib/libcrypt/libcrypt.aldscript new file mode 100644 index 000000000000..cfc8020dd9e3 --- /dev/null +++ b/lib/libcrypt/libcrypt.aldscript @@ -0,0 +1 @@ +INPUT(-l@@LIB@@@@STATICLIB_SUFFIX@@ -lmd) diff --git a/lib/libcrypt/libcrypt.ldscript b/lib/libcrypt/libcrypt.ldscript new file mode 100644 index 000000000000..a0b20fa43fe8 --- /dev/null +++ b/lib/libcrypt/libcrypt.ldscript @@ -0,0 +1 @@ +INPUT(@@SHLIB@@ AS_NEEDED(-lmd)) diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk index 092e1b444beb..588291d8ec9c 100644 --- a/share/mk/src.libnames.mk +++ b/share/mk/src.libnames.mk @@ -322,6 +322,7 @@ _DP_cap_grp= nv _DP_cap_pwd= nv _DP_cap_sysctl= nv _DP_cap_syslog= nv +_DP_crypt= md .if ${MK_OFED} != "no" _DP_pcap= ibverbs mlx5 .endif