[PATCH 2/5] scripts: restore support for 64-bit pointers in host hash functions

From: Julian Braha

Date: Thu Nov 26 2026 - 19:00:40 EST


This partially reverts commit f93d6bfbd2f7 ("kconfig: use hash table to
reuse expressions").

When the kernel's hash headers were copied over for host usage, hash_ptr()
was also simplified to remove the bit count parameter, with only the "fast
32bit" path in use.

With the bit count parameter restored, let's restore support for passing a
64-bit pointer to hash_ptr(), rather than truncating to 32 bits.

Like other headers in tools/, use __SIZEOF_LONG__ to check the host word
size, as opposed to the in-kernel BITS_PER_LONG.

Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
---
scripts/include/hash.h | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/include/hash.h b/scripts/include/hash.h
index ae0d3fc8d470..08e901b8a43d 100644
--- a/scripts/include/hash.h
+++ b/scripts/include/hash.h
@@ -12,17 +12,29 @@ static inline unsigned int hash_str(const char *s)
return hash;
}

+#if __SIZEOF_LONG__ == 4
+#define hash_long(val, bits) hash_32(val, bits)
+#else
+#define hash_long(val, bits) hash_64(val, bits)
+#endif
+
/* simplified version of functions from include/linux/hash.h */
#define GOLDEN_RATIO_32 0x61C88647
+#define GOLDEN_RATIO_64 0x61C8864680B583EBull

static inline unsigned int hash_32(unsigned int val, unsigned int bits)
{
return bits ? (val * GOLDEN_RATIO_32) >> (32 - bits) : 0;
}

+static inline unsigned int hash_64(unsigned long long val, unsigned int bits)
+{
+ return bits ? (val * GOLDEN_RATIO_64) >> (64 - bits) : 0;
+}
+
static inline unsigned int hash_ptr(const void *ptr, unsigned int bits)
{
- return hash_32((unsigned int)(unsigned long)ptr, bits);
+ return hash_long((unsigned long)ptr, bits);
}

#endif /* HASH_H */
--
2.56.0