[libvirt] [PATCH 0/5] build: eliminate more redundant/obsolete gnulib modules

A follow up to my previous series that was already pushed. This identifies some more unused modules, or things that are easily replaced. Daniel P. Berrangé (5): build: remove all gnulib bit manipulation modules build: drop the ignore-value gnulib module build: drop the ldexp gnulib module build: drop the isatty gnulib module build: remove the sched gnulib module bootstrap.conf | 9 --------- src/conf/capabilities.c | 3 +-- src/conf/domain_conf.c | 1 - src/conf/snapshot_conf.c | 1 - src/internal.h | 18 +++++++++++++++--- src/libxl/xen_common.c | 1 - src/util/Makefile.inc.am | 1 + src/util/virbitmap.c | 7 +++---- src/util/vircgroupv2.c | 2 +- src/util/virhashcode.c | 6 +++++- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - src/util/virrandom.c | 4 +--- tools/vsh.c | 2 +- 14 files changed, 28 insertions(+), 29 deletions(-) -- 2.21.0

We're using gnulib to get ffs, ffsl, rotl32, count_one_bits, and count_leading_zeros. Except for rotl32 they can all be replaced with gcc/clangs builtins. rotl32 is a one-line trivial function. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 5 ----- src/conf/capabilities.c | 3 +-- src/conf/domain_conf.c | 1 - src/conf/snapshot_conf.c | 1 - src/internal.h | 10 ++++++++-- src/libxl/xen_common.c | 1 - src/util/virbitmap.c | 7 +++---- src/util/vircgroupv2.c | 2 +- src/util/virhashcode.c | 6 +++++- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - src/util/virrandom.c | 4 +--- tools/vsh.c | 2 +- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index fe8f7fc9c3..7b20f1c371 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -22,7 +22,6 @@ accept areadlink base64 bind -bitrotate byteswap c-ctype c-strcase @@ -34,8 +33,6 @@ clock-time close connect configmake -count-leading-zeros -count-one-bits dirname-lgpl environ execinfo @@ -43,8 +40,6 @@ fclose fcntl fcntl-h fdatasync -ffs -ffsl fnmatch fsync getaddrinfo diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1231b9727c..7419d9cfc8 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -21,7 +21,6 @@ #include <config.h> -#include <strings.h> #include <unistd.h> #include "capabilities.h" @@ -1152,7 +1151,7 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, virBufferAddLit(buf, "<power_management>\n"); virBufferAdjustIndent(buf, 2); while (pm) { - int bit = ffs(pm) - 1; + int bit = __builtin_ffs(pm) - 1; virBufferAsprintf(buf, "<%s/>\n", virCapsHostPMTargetTypeToString(bit)); pm &= ~(1U << bit); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d090876f8..a53cd6a725 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -45,7 +45,6 @@ #include "virstoragefile.h" #include "virfile.h" #include "virbitmap.h" -#include "count-one-bits.h" #include "secret_conf.h" #include "netdev_vport_profile_conf.h" #include "netdev_bandwidth_conf.h" diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 96ad8ca953..a77f521302 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -29,7 +29,6 @@ #include "internal.h" #include "virbitmap.h" #include "virbuffer.h" -#include "count-one-bits.h" #include "datatypes.h" #include "domain_conf.h" #include "virlog.h" diff --git a/src/internal.h b/src/internal.h index adc1e3f496..fc251067f0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -27,6 +27,7 @@ #include <stdint.h> #include <stdio.h> #include <string.h> +#include <stdlib.h> #if STATIC_ANALYSIS # undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */ @@ -63,7 +64,6 @@ #include "c-strcase.h" #include "ignore-value.h" -#include "count-leading-zeros.h" /* String equality tests, suggested by Jim Meyering. */ #define STREQ(a, b) (strcmp(a, b) == 0) @@ -493,6 +493,12 @@ } while (0) +/* Count leading zeros in an unsigned int. + * + * Wrapper needed as __builtin_clz is undefined if value is zero + */ +#define VIR_CLZ(value) \ + (value ? __builtin_clz(value) : (8 * sizeof(unsigned))) /* divide value by size, rounding up */ #define VIR_DIV_UP(value, size) (((value) + (size) - 1) / (size)) @@ -504,7 +510,7 @@ * for 0 or number more than 2^31 (for 32bit unsigned int). */ #define VIR_ROUND_UP_POWER_OF_TWO(value) \ ((value) > 0 && (value) <= 1U << (sizeof(unsigned int) * 8 - 1) ? \ - 1U << (sizeof(unsigned int) * 8 - count_leading_zeros((value) - 1)) : 0) + 1U << (sizeof(unsigned int) * 8 - VIR_CLZ((value) - 1)) : 0) /* Specific error values for use in forwarding programs such as diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index d327f03d73..2680e88a60 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -31,7 +31,6 @@ #include "virconf.h" #include "viralloc.h" #include "viruuid.h" -#include "count-one-bits.h" #include "xenxs_private.h" #include "domain_conf.h" #include "virstring.h" diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index a61f4b2095..ed8f06acc7 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -27,7 +27,6 @@ #include "viralloc.h" #include "virbuffer.h" #include "c-ctype.h" -#include "count-one-bits.h" #include "virstring.h" #include "virutil.h" #include "virerror.h" @@ -1028,7 +1027,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, if (bits == 0) return -1; - return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; + return __builtin_ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; } @@ -1127,7 +1126,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, if (bits == 0) return -1; - return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; + return __builtin_ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; } @@ -1144,7 +1143,7 @@ virBitmapCountBits(virBitmapPtr bitmap) size_t ret = 0; for (i = 0; i < bitmap->map_len; i++) - ret += count_one_bits_l(bitmap->map[i]); + ret += __builtin_popcountl(bitmap->map[i]); return ret; } diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 143083e56f..ace04bba04 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -339,7 +339,7 @@ static int virCgroupV2GetAnyController(virCgroupPtr group) { /* The least significant bit is position 1. */ - return ffs(group->unified.controllers) - 1; + return __builtin_ffs(group->unified.controllers) - 1; } diff --git a/src/util/virhashcode.c b/src/util/virhashcode.c index 310ec891c8..98d5dceeba 100644 --- a/src/util/virhashcode.c +++ b/src/util/virhashcode.c @@ -28,7 +28,11 @@ #include <config.h> #include "virhashcode.h" -#include "bitrotate.h" + +static uint32_t rotl32(uint32_t x, int8_t r) +{ + return (x << r) | (x >> (32 - r)); +} /* slower than original but handles platforms that do only aligned reads */ static inline uint32_t getblock(const uint8_t *p, int i) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 8c00804b0e..83e4853006 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -44,7 +44,6 @@ #include "virhostcpupriv.h" #include "physmem.h" #include "virerror.h" -#include "count-one-bits.h" #include "intprops.h" #include "virarch.h" #include "virfile.h" diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index 19cd282724..d16e0217e5 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -37,7 +37,6 @@ #include "virhostmem.h" #include "physmem.h" #include "virerror.h" -#include "count-one-bits.h" #include "virarch.h" #include "virfile.h" #include "virtypedparam.h" diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 93c5bf3a2c..8dcab1ac47 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -20,7 +20,6 @@ #include <inttypes.h> #include <math.h> -#include <strings.h> #include <time.h> #include <fcntl.h> #include <sys/stat.h> @@ -32,7 +31,6 @@ #include "virrandom.h" #include "virthread.h" -#include "count-one-bits.h" #include "virutil.h" #include "virerror.h" #include "virfile.h" @@ -97,7 +95,7 @@ double virRandom(void) uint32_t virRandomInt(uint32_t max) { if ((max & (max - 1)) == 0) - return virRandomBits(ffs(max) - 1); + return virRandomBits(__builtin_ffs(max) - 1); double val = virRandom(); return val * max; diff --git a/tools/vsh.c b/tools/vsh.c index 9bdd90e362..bf8b6b412b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -555,7 +555,7 @@ vshCmddefGetData(const vshCmdDef *cmd, uint64_t *opts_need_arg, return NULL; /* Grab least-significant set bit */ - i = ffsl(*opts_need_arg) - 1; + i = __builtin_ffsl(*opts_need_arg) - 1; opt = &cmd->opts[i]; if (opt->type != VSH_OT_ARGV) *opts_need_arg &= ~(1ULL << i); -- 2.21.0

We don't need to care about very old GCC versions, so implementing the ignore_value macro directly is not a significant burden. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 1 - src/internal.h | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7b20f1c371..8d3963fa2c 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -50,7 +50,6 @@ getpeername getsockname gettimeofday gnumakefile -ignore-value intprops ioctl isatty diff --git a/src/internal.h b/src/internal.h index fc251067f0..e1a69be9f2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -63,7 +63,13 @@ #include "libvirt/virterror.h" #include "c-strcase.h" -#include "ignore-value.h" + +/* Merely casting to (void) is not sufficient since the + * introduction of the "warn_unused_result" attribute + */ +#define ignore_value(x) \ + (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) + /* String equality tests, suggested by Jim Meyering. */ #define STREQ(a, b) (strcmp(a, b) == 0) -- 2.21.0

The ldexp gnulib module adds "-lm" to the $LIBS variable if-and-only-if the ldexp() function require linking to libm. There is no harm in linking to libm even if it isn't required for ldexp(), so simply drop the gnulib module. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 1 - src/util/Makefile.inc.am | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.conf b/bootstrap.conf index 8d3963fa2c..96ce1504ba 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -54,7 +54,6 @@ intprops ioctl isatty largefile -ldexp listen localeconv maintainer-makefile diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 482b657a90..9747816fac 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -279,6 +279,7 @@ libvirt_util_la_CFLAGS = \ $(ACL_CFLAGS) \ $(NULL) libvirt_util_la_LIBADD = \ + -lm \ $(CAPNG_LIBS) \ $(YAJL_LIBS) \ $(LIBNL_LIBS) \ -- 2.21.0

The isatty gnulib module adds a fix for Win32 platforms where it doesn't work correctly with character devices like NUL. This is not a compelling enough problem for libvirt to be concerned with. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap.conf b/bootstrap.conf index 96ce1504ba..f501ef6c25 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -52,7 +52,6 @@ gettimeofday gnumakefile intprops ioctl -isatty largefile listen localeconv -- 2.21.0

The 'sched' module provides a sched.h header file for platforms which lack it. We already check for the functions we need in configure, and protect the use of sched.h where relevant, so don't need the compat header in libvirt. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap.conf b/bootstrap.conf index f501ef6c25..e40170a77b 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -74,7 +74,6 @@ posix-shell pthread_sigmask recv regex -sched send setenv setsockopt -- 2.21.0

On Mon, Oct 07, 2019 at 12:44:23PM +0100, Daniel P. Berrangé wrote:
A follow up to my previous series that was already pushed. This identifies some more unused modules, or things that are easily replaced.
Daniel P. Berrangé (5): build: remove all gnulib bit manipulation modules build: drop the ignore-value gnulib module build: drop the ldexp gnulib module build: drop the isatty gnulib module build: remove the sched gnulib module
bootstrap.conf | 9 --------- src/conf/capabilities.c | 3 +-- src/conf/domain_conf.c | 1 - src/conf/snapshot_conf.c | 1 - src/internal.h | 18 +++++++++++++++--- src/libxl/xen_common.c | 1 - src/util/Makefile.inc.am | 1 + src/util/virbitmap.c | 7 +++---- src/util/vircgroupv2.c | 2 +- src/util/virhashcode.c | 6 +++++- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - src/util/virrandom.c | 4 +--- tools/vsh.c | 2 +- 14 files changed, 28 insertions(+), 29 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Daniel P. Berrangé
-
Ján Tomko