]> git.pld-linux.org Git - packages/libbpf.git/commitdiff
- added hashmap patch (fix hashmap on (I)LP32 archs); release 2 auto/th/libbpf-0.0.9-2
authorJakub Bogusz <qboosh@pld-linux.org>
Sat, 27 Jun 2020 08:28:02 +0000 (10:28 +0200)
committerJakub Bogusz <qboosh@pld-linux.org>
Sat, 27 Jun 2020 08:28:02 +0000 (10:28 +0200)
libbpf-hashmap.patch [new file with mode: 0644]
libbpf.spec

diff --git a/libbpf-hashmap.patch b/libbpf-hashmap.patch
new file mode 100644 (file)
index 0000000..45c0660
--- /dev/null
@@ -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);
index 06d2e86a7a9f7096a20d71166f2c9478466c1e4f..68de6fd41c2457402349bf3039e8a6a31f874f18 100644 (file)
@@ -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
This page took 0.330519 seconds and 4 git commands to generate.