[packages/libbpf] - added hashmap patch (fix hashmap on (I)LP32 archs); release 2
qboosh
qboosh at pld-linux.org
Sat Jun 27 10:27:39 CEST 2020
commit 7b27c4946474f44213f804bd3d21e4dacedfb318
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date: Sat Jun 27 10:28:02 2020 +0200
- added hashmap patch (fix hashmap on (I)LP32 archs); release 2
libbpf-hashmap.patch | 32 ++++++++++++++++++++++++++++++++
libbpf.spec | 4 +++-
2 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/libbpf.spec b/libbpf.spec
index 06d2e86..68de6fd 100644
--- a/libbpf.spec
+++ b/libbpf.spec
@@ -2,12 +2,13 @@ Summary: Libbpf library
Summary(pl.UTF-8): Biblioteka libbpf
Name: libbpf
Version: 0.0.9
-Release: 1
+Release: 2
License: LGPL v2.1 or BSD
Group: Libraries
#Source0Download: https://github.com/libbpf/libbpf/releases
Source0: https://github.com/libbpf/libbpf/archive/v%{version}/%{name}-%{version}.tar.gz
# Source0-md5: 6582f932a012710cc93d7c01e04da63c
+Patch0: %{name}-hashmap.patch
URL: https://github.com/libbpf/libbpf
BuildRequires: elfutils-devel
BuildRequires: linux-libc-headers >= 7:5.4.0
@@ -58,6 +59,7 @@ wykorzystujących libbpf.
%prep
%setup -q
+%patch0 -p1
%build
# use NO_PKG_CONFIG to link with -lelf -lz, not $(pkg-config --libs libelf) which doesn't contain -lz
diff --git a/libbpf-hashmap.patch b/libbpf-hashmap.patch
new file mode 100644
index 0000000..45c0660
--- /dev/null
+++ b/libbpf-hashmap.patch
@@ -0,0 +1,32 @@
+Fix libbpf hashmap on (I)LP32 architectures
+
+On ILP32, 64-bit result was shifted by value calculated for 32-bit long type
+and returned value was much outside hashmap capacity.
+As advised by Andrii Nakryiko, this patch uses different hashing variant for
+architectures with size_t shorter than long long.
+
+--- libbpf-0.0.9/src/hashmap.h.orig 2020-06-17 20:48:22.000000000 +0200
++++ libbpf-0.0.9/src/hashmap.h 2020-06-27 10:19:51.561635722 +0200
+@@ -11,14 +11,18 @@
+ #include <stdbool.h>
+ #include <stddef.h>
+ #include <limits.h>
+-#ifndef __WORDSIZE
+-#define __WORDSIZE (__SIZEOF_LONG__ * 8)
+-#endif
+
+ static inline size_t hash_bits(size_t h, int bits)
+ {
+ /* shuffle bits and return requested number of upper bits */
+- return (h * 11400714819323198485llu) >> (__WORDSIZE - bits);
++#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
++ /* LP64 case */
++ return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
++#elif (__SIZEOF_SIZE_T__ <= __SIZEOF_LONG__)
++ return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits);
++#else
++# error "Unsupported size_t size"
++#endif
+ }
+
+ typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/libbpf.git/commitdiff/7b27c4946474f44213f804bd3d21e4dacedfb318
More information about the pld-cvs-commit
mailing list