]> git.pld-linux.org Git - packages/kernel-tools.git/blame - kernel-tools-bpf-hashmap.patch
- typo, release 5
[packages/kernel-tools.git] / kernel-tools-bpf-hashmap.patch
CommitLineData
49505f6f
JB
1Fix libbpf hashmap on (I)LP32 architectures
2
3On ILP32, 64-bit result was shifted by value calculated for 32-bit long type
4and returned value was much outside hashmap capacity.
5As advised by Andrii Nakryiko, this patch uses different hashing variant for
6architectures with size_t shorter than long long.
7
a02a39f3
JB
8--- linux-5.7/tools/lib/bpf/hashmap.h.orig 2020-06-01 01:49:15.000000000 +0200
9+++ linux-5.7/tools/lib/bpf/hashmap.h 2020-06-21 15:22:07.298466419 +0200
49505f6f 10@@ -11,14 +11,18 @@
a02a39f3
JB
11 #include <stdbool.h>
12 #include <stddef.h>
49505f6f
JB
13 #include <limits.h>
14-#ifndef __WORDSIZE
15-#define __WORDSIZE (__SIZEOF_LONG__ * 8)
a02a39f3 16-#endif
a02a39f3
JB
17
18 static inline size_t hash_bits(size_t h, int bits)
19 {
20 /* shuffle bits and return requested number of upper bits */
21- return (h * 11400714819323198485llu) >> (__WORDSIZE - bits);
49505f6f
JB
22+#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
23+ /* LP64 case */
a02a39f3 24+ return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
49505f6f
JB
25+#elif (__SIZEOF_SIZE_T__ <= __SIZEOF_LONG__)
26+ return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits);
27+#else
28+# error "Unsupported size_t size"
29+#endif
a02a39f3
JB
30 }
31
32 typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);
This page took 0.069632 seconds and 4 git commands to generate.