libbsd: Branch 'master' - 6 commits
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Feb 9 05:28:52 UTC 2021
configure.ac | 31 ++++++++++++-----
include/bsd/sys/cdefs.h | 10 ++---
src/Makefile.am | 4 --
src/libbsd.pc.in | 1
src/md5.c | 86 ++++++++++++++++++++++++++++++++----------------
test/Makefile.am | 2 -
6 files changed, 88 insertions(+), 46 deletions(-)
New commits:
commit 1fb25b7dcad8f40ee8944208224ea0c625af8d82
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 06:14:25 2021 +0100
Release libbsd 0.11.3
diff --git a/configure.ac b/configure.ac
index 07cbb5d..09cb310 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,7 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
LIBBSD_ABI_MAJOR=0
LIBBSD_ABI_MINOR=11
-LIBBSD_ABI_PATCH=2
+LIBBSD_ABI_PATCH=3
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
AC_SUBST([LIBBSD_ABI])
commit 31f034e3862debda8615a449b1c11c4d6920dcc7
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 05:57:37 2021 +0100
Switch libmd wrapper to use dlsym()
Switch from the previous versioned symbol implementation which required
users to also link against the message digest provider explicitly, or
they would fail to find the symbols, to an implementation that loads
the symbols from the linked library providing the functions using
dlsym(), thus preserving backwards compatibility.
diff --git a/configure.ac b/configure.ac
index 3281efb..07cbb5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,9 +64,15 @@ AM_CONDITIONAL([HAVE_LIBTESTU01],
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([dlsym], [dl], [
+ AS_IF([test "x$ac_cv_search_dlsym" != "xnone required"], [
+ LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_dlsym"
+ ])
+], [
+ AC_MSG_ERROR([cannot find required dlsym function])
+])
AC_SEARCH_LIBS([MD5Update], [md], [
AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
- MD_LIBS="$ac_cv_search_MD5Update"
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_MD5Update"
])
], [
@@ -74,13 +80,11 @@ AC_SEARCH_LIBS([MD5Update], [md], [
])
AC_SEARCH_LIBS([SHA512Update], [md], [
AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
- MD_LIBS="$ac_cv_search_SHA512Update"
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_SHA512Update"
])
], [
AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
])
-AC_SUBST([MD_LIBS])
LIBS="$saved_LIBS"
is_windows=no
diff --git a/src/md5.c b/src/md5.c
index b74ce7d..da99876 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -24,68 +24,100 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stddef.h>
+#include <stdlib.h>
+#include <dlfcn.h>
#include <md5.h>
-#include "local-link.h"
+
+static void (*libmd_MD5Init)(MD5_CTX *);
+static void (*libmd_MD5Update)(MD5_CTX *, const uint8_t *, size_t);
+static void (*libmd_MD5Pad)(MD5_CTX *);
+static void (*libmd_MD5Final)(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
+static void (*libmd_MD5Transform)(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]);
+static char *(*libmd_MD5End)(MD5_CTX *, char *);
+static char *(*libmd_MD5File)(const char *, char *);
+static char *(*libmd_MD5FileChunk)(const char *, char *, off_t, off_t);
+static char *(*libmd_MD5Data)(const uint8_t *, size_t, char *);
+
+static void *
+libmd_loader(const char *symbol)
+{
+ void *func;
+
+ func = dlsym(RTLD_NEXT, symbol);
+ if (func == NULL) {
+ fprintf(stderr,
+ "libbsd: cannot find wrapped symbol %s in libc or libmd\n",
+ symbol);
+ abort();
+ }
+
+ return func;
+}
+
+#define libmd_wrapper(symbol) \
+ if (libmd_ ## symbol == NULL) \
+ libmd_ ## symbol = libmd_loader(#symbol)
void
-bsd_MD5Init(MD5_CTX *context)
+MD5Init(MD5_CTX *context)
{
- MD5Init(context);
+ libmd_wrapper(MD5Init);
+ libmd_MD5Init(context);
}
-libbsd_symver_variant(MD5Init, bsd_MD5Init, LIBBSD_0.0);
void
-bsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
+MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
{
- MD5Update(context, data, len);
+ libmd_wrapper(MD5Update);
+ libmd_MD5Update(context, data, len);
}
-libbsd_symver_variant(MD5Update, bsd_MD5Update, LIBBSD_0.0);
void
-bsd_MD5Pad(MD5_CTX *context)
+MD5Pad(MD5_CTX *context)
{
- MD5Pad(context);
+ libmd_wrapper(MD5Pad);
+ libmd_MD5Pad(context);
}
-libbsd_symver_variant(MD5Pad, bsd_MD5Pad, LIBBSD_0.0);
void
-bsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
+MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
{
- MD5Final(digest, context);
+ libmd_wrapper(MD5Final);
+ libmd_MD5Final(digest, context);
}
-libbsd_symver_variant(MD5Final, bsd_MD5Final, LIBBSD_0.0);
void
-bsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
+MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
{
- MD5Transform(state, block);
+ libmd_wrapper(MD5Transform);
+ libmd_MD5Transform(state, block);
}
-libbsd_symver_variant(MD5Transform, bsd_MD5Transform, LIBBSD_0.0);
char *
-bsd_MD5End(MD5_CTX *context, char *buf)
+MD5End(MD5_CTX *context, char *buf)
{
- return MD5End(context, buf);
+ libmd_wrapper(MD5End);
+ return libmd_MD5End(context, buf);
}
-libbsd_symver_variant(MD5End, bsd_MD5End, LIBBSD_0.0);
char *
-bsd_MD5File(const char *filename, char *buf)
+MD5File(const char *filename, char *buf)
{
+ libmd_wrapper(MD5File);
return MD5File(filename, buf);
}
-libbsd_symver_variant(MD5File, bsd_MD5File, LIBBSD_0.0);
char *
-bsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
+MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
{
- return MD5FileChunk(filename, buf, offset, length);
+ libmd_wrapper(MD5FileChunk);
+ return libmd_MD5FileChunk(filename, buf, offset, length);
}
-libbsd_symver_variant(MD5FileChunk, bsd_MD5FileChunk, LIBBSD_0.0);
char *
-bsd_MD5Data(const uint8_t *data, size_t len, char *buf)
+MD5Data(const uint8_t *data, size_t len, char *buf)
{
- return MD5Data(data, len, buf);
+ libmd_wrapper(MD5Data);
+ return libmd_MD5Data(data, len, buf);
}
-libbsd_symver_variant(MD5Data, bsd_MD5Data, LIBBSD_0.0);
diff --git a/test/Makefile.am b/test/Makefile.am
index a1c8e68..90fe384 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -52,8 +52,6 @@ check_PROGRAMS = \
vis-openbsd \
$(nil)
-md5_LDADD = $(LDADD) $(MD_LIBS)
-
if HAVE_LIBTESTU01
arc4random_LDADD = $(LDADD) $(TESTU01_LIBS)
commit 2374f409defb380d0c5c07f28b9c166ef8bdc742
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 05:56:49 2021 +0100
build: Add a Libs.private field to pkg-config file
We need to list all internal libraries there so that we can statically
link.
diff --git a/src/libbsd.pc.in b/src/libbsd.pc.in
index d141fea..2c0ac17 100644
--- a/src/libbsd.pc.in
+++ b/src/libbsd.pc.in
@@ -8,4 +8,5 @@ Description: Utility functions from BSD systems
Version: @VERSION@
URL: https://libbsd.freedesktop.org/
Libs: -L${libdir} -lbsd
+Libs.private: @LIBBSD_LIBS@
Cflags: -I${includedir}
commit a4e0db2b9773d28e2e1601f5e6dc77b7bc2df60b
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 06:04:38 2021 +0100
build: Use a single variable to track libraries to link against
Using various variables means we have to keep these in sync in various
places. Just use a single variable that we can use anywhere where this
is needed.
diff --git a/configure.ac b/configure.ac
index 7afc7af..3281efb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,7 @@ saved_LIBS="$LIBS"
AC_SEARCH_LIBS([MD5Update], [md], [
AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
MD_LIBS="$ac_cv_search_MD5Update"
+ LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_MD5Update"
])
], [
AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
@@ -74,6 +75,7 @@ AC_SEARCH_LIBS([MD5Update], [md], [
AC_SEARCH_LIBS([SHA512Update], [md], [
AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
MD_LIBS="$ac_cv_search_SHA512Update"
+ LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_SHA512Update"
])
], [
AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
@@ -88,10 +90,9 @@ AS_CASE([$host_os],
saved_LIBS="$LIBS"
AC_SEARCH_LIBS([clock_gettime], [rt], [
AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
- CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
+ LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_clock_gettime"
])
])
- AC_SUBST([CLOCK_GETTIME_LIBS])
LIBS="$saved_LIBS"
],
[*-musl*], [
@@ -199,8 +200,7 @@ AC_LINK_IFELSE(
[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
[Define to 1 if you have __register_atfork])
AC_MSG_RESULT([yes])],
- [ARC4RANDOM_ATFORK_LIBS="-pthread"
- AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
+ [LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
AC_MSG_RESULT([no])
])
@@ -209,6 +209,8 @@ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
pstat_getproc sysconf])
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
+AC_SUBST([LIBBSD_LIBS])
+
AC_CONFIG_FILES([
Makefile
include/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 48fb1fa..7ef2013 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,9 +52,7 @@ libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \
libbsd.map
libbsd_la_LIBADD = \
- $(MD_LIBS) \
- $(CLOCK_GETTIME_LIBS) \
- $(ARC4RANDOM_ATFORK_LIBS) \
+ $(LIBBSD_LIBS) \
$(nil)
libbsd_la_LDFLAGS = \
-version-number $(LIBBSD_ABI)
commit 43d34c9d3b2a24113d3901c3c7d229656cd4ce98
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 06:02:46 2021 +0100
build: Fix message digest library checks
They were not failing when not finding the SHA-2 functions and
were hardcoding -lmd regardless of what library had been found.
diff --git a/configure.ac b/configure.ac
index f100045..7afc7af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,11 +65,18 @@ AM_CONDITIONAL([HAVE_LIBTESTU01],
saved_LIBS="$LIBS"
AC_SEARCH_LIBS([MD5Update], [md], [
- AC_SEARCH_LIBS([SHA512Update], [md], [
- MD_LIBS="-lmd"
+ AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
+ MD_LIBS="$ac_cv_search_MD5Update"
])
], [
- AC_MSG_ERROR([cannot find required message digest functions in libc or libmd])
+ AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
+])
+AC_SEARCH_LIBS([SHA512Update], [md], [
+ AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
+ MD_LIBS="$ac_cv_search_SHA512Update"
+ ])
+], [
+ AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
])
AC_SUBST([MD_LIBS])
LIBS="$saved_LIBS"
commit 1c3ff61699a6343ea4b5b6a757300581c5374d35
Author: Guillem Jover <guillem at hadrons.org>
Date: Tue Feb 9 02:46:49 2021 +0100
Use uintptr_t and size_t instead of __-prefixed types in <sys/cdefs.h>
The __-prefixed types cannot be assumed to be defined. Use the standard
types instead.
Closes: #6
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index 999bda2..ac18296 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -187,10 +187,10 @@
# else
# ifndef __cplusplus
# define __offsetof(type, field) \
- ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
+ ((size_t)(uintptr_t)((const volatile void *)&((type *)0)->field))
# else
# define __offsetof(type, field) \
- (__offsetof__ (reinterpret_cast <__size_t> \
+ (__offsetof__ (reinterpret_cast <size_t> \
(&reinterpret_cast <const volatile char &> \
(static_cast<type *> (0)->field))))
# endif
@@ -243,15 +243,15 @@
#endif
#ifndef __DECONST
-#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
+#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif
#ifndef __DEVOLATILE
-#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
+#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var))
#endif
#ifndef __DEQUALIFY
-#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
+#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var))
#endif
#endif
More information about the libbsd
mailing list