diff --git a/mold.h b/mold.h index d980973c..2f9d99ac 100644 --- a/mold.h +++ b/mold.h @@ -1684,7 +1684,7 @@ inline u32 elf_hash(std::string_view name) { return h; } -inline u32 gnu_hash(std::string_view name) { +inline u32 djb_hash(std::string_view name) { u32 h = 5381; for (u8 c : name) h = (h << 5) + h + c; diff --git a/output_chunks.cc b/output_chunks.cc index cc9eb6d8..6c996380 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -868,7 +868,7 @@ void DynsymSection::sort_symbols(Context &ctx) { ctx.gnu_hash->symoffset = first_global - vec.begin(); tbb::parallel_for_each(first_global, vec.end(), [&](T &x) { - x.hash = gnu_hash(x.sym->name) % ctx.gnu_hash->num_buckets; + x.hash = djb_hash(x.sym->name) % ctx.gnu_hash->num_buckets; }); tbb::parallel_sort(first_global, vec.end(), [&](const T &a, const T &b) { @@ -1006,12 +1006,12 @@ void GnuHashSection::copy_buf(Context &ctx) { std::vector hashes(symbols.size()); for (i64 i = 0; i < symbols.size(); i++) - hashes[i] = gnu_hash(symbols[i]->name); + hashes[i] = djb_hash(symbols[i]->name); // Write a bloom filter - u64 *bloom = (u64 *)(base + HEADER_SIZE); + typename E::word *bloom = (typename E::word *)(base + HEADER_SIZE); for (i64 hash : hashes) { - i64 idx = (hash / 64) % num_bloom; + i64 idx = (hash / ELFCLASS_BITS) % num_bloom; bloom[idx] |= (u64)1 << (hash % ELFCLASS_BITS); bloom[idx] |= (u64)1 << ((hash >> BLOOM_SHIFT) % ELFCLASS_BITS); }