Richard W.M. Jones
2021-Aug-24 14:10 UTC
[Libguestfs] [PATCH nbdkit v3] tests: Improve test for libc_malloc_debug
Previous commits tried to add support for new glibc 2.34 feature libc_malloc_debug by checking for the specific version of glibc. However this risks setting LD_PRELOAD to a non-existent path (eg. if the user does not specify any ./configure --prefix which results in setting LD_PRELOAD=/usr/local/lib/libc_malloc_debug.so.0). While LD_PRELOAD normally just warns (noisily) if it cannot find the library, the warning causes some tests to fail. In any case it's better not to set LD_PRELOAD at all in this case. Instead let's test for the presence of libc_malloc_debug on the provided --prefix or --libdir path in ./configure, and then use that to enable the LD_PRELOAD stuff. Fixes: commit 8972831aa2a32d4b5820465d37c1827eb76450e4 Fixes: commit 362e0fdcae37db876e13b944102a5c152e6bc563 --- configure.ac | 31 ++++++++++++++++++++----------- tests/Makefile.am | 4 ++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index ea13c75c..0e4c4a28 100644 --- a/configure.ac +++ b/configure.ac @@ -569,17 +569,26 @@ AS_IF([test "x$is_windows" = "xyes"],[ AC_SEARCH_LIBS([getaddrinfo], [network socket]) -dnl Does this platform require libc_malloc_debug.so.0 (glibc >= 2.34)? -AC_MSG_CHECKING([if this is glibc >= 2.34]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include <limits.h> -#if !defined(__GLIBC__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 34) -#error "not glibc 2.34" -#endif - ]])], [is_glibc_234=yes], [is_glibc_234=no] -) -AC_MSG_RESULT([$is_glibc_234]) -AM_CONDITIONAL([HAVE_GLIBC_234], [test "x$is_glibc_234" = "xyes"]) +dnl Does this platform have $libdir/libc_malloc_debug.so.0 (glibc >+dnl 2.34)? We have to override the idiotic exec_prefix misfeature to +dnl get to the real libdir. +real_libdir="$( + if test "x$prefix" != xNONE; then + exec_prefix="$prefix" + else + exec_prefix="$ac_default_prefix" + fi + eval echo $libdir +)" +LIBC_MALLOC_DEBUG="$real_libdir/libc_malloc_debug.so.0" +AC_MSG_CHECKING([for $LIBC_MALLOC_DEBUG]) +AS_IF([test -r $LIBC_MALLOC_DEBUG], [ + have_libc_malloc_debug=yes + AC_SUBST([LIBC_MALLOC_DEBUG]) +],[have_libc_malloc_debug=no]) +AC_MSG_RESULT([$have_libc_malloc_debug]) +AM_CONDITIONAL([HAVE_LIBC_MALLOC_DEBUG], + [test "x$have_libc_malloc_debug" = xyes]) dnl Check for SELinux socket labelling (optional). PKG_CHECK_MODULES([LIBSELINUX], [libselinux], [ diff --git a/tests/Makefile.am b/tests/Makefile.am index 35b2e4a6..109853ea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -74,9 +74,9 @@ TESTS_ENVIRONMENT = \ # uninitialized read problems when using glibc, and doesn't affect # normal operation or other libc. random = $(shell bash -c 'echo $$(( 1 + (RANDOM & 255) ))') -if HAVE_GLIBC_234 +if HAVE_LIBC_MALLOC_DEBUG TESTS_ENVIRONMENT += \ - LD_PRELOAD="$${LD_PRELOAD:+"$$LD_PRELOAD:"}$(libdir)/libc_malloc_debug.so.0" \ + LD_PRELOAD="$${LD_PRELOAD:+"$$LD_PRELOAD:"}$(LIBC_MALLOC_DEBUG)" \ GLIBC_TUNABLES=glibc.malloc.check=1:glibc.malloc.perturb=$(random) \ $(NULL) else -- 2.32.0
Richard W.M. Jones
2021-Aug-24 16:00 UTC
[Libguestfs] [PATCH nbdkit v3] tests: Improve test for libc_malloc_debug
On Tue, Aug 24, 2021 at 03:10:40PM +0100, Richard W.M. Jones wrote:> +dnl Does this platform have $libdir/libc_malloc_debug.so.0 (glibc >> +dnl 2.34)? We have to override the idiotic exec_prefix misfeature to > +dnl get to the real libdir. > +real_libdir="$( > + if test "x$prefix" != xNONE; then > + exec_prefix="$prefix" > + else > + exec_prefix="$ac_default_prefix" > + fi > + eval echo $libdir > +)" > +LIBC_MALLOC_DEBUG="$real_libdir/libc_malloc_debug.so.0" > +AC_MSG_CHECKING([for $LIBC_MALLOC_DEBUG]) > +AS_IF([test -r $LIBC_MALLOC_DEBUG], [ > + have_libc_malloc_debug=yes > + AC_SUBST([LIBC_MALLOC_DEBUG]) > +],[have_libc_malloc_debug=no]) > +AC_MSG_RESULT([$have_libc_malloc_debug]) > +AM_CONDITIONAL([HAVE_LIBC_MALLOC_DEBUG], > + [test "x$have_libc_malloc_debug" = xyes])Oh hang on here, LD_PRELOAD obeys the normal path searching?! So I don't need any of this. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW