From 5ca54c66862b8edee1bd300bb284b90306eef87b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 25 Nov 2021 14:23:25 -0800 Subject: [PATCH] [ELF] Simplify GnuHashSection::write. NFC --- lld/ELF/SyntheticSections.cpp | 21 ++++----------------- lld/ELF/SyntheticSections.h | 3 --- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index d251419cd73d..3936f0f0d74f 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2380,21 +2380,8 @@ void GnuHashTableSection::writeTo(uint8_t *buf) { write32(buf + 12, Shift2); buf += 16; - // Write a bloom filter and a hash table. - writeBloomFilter(buf); - buf += config->wordsize * maskWords; - writeHashTable(buf); -} - -// This function writes a 2-bit bloom filter. This bloom filter alone -// usually filters out 80% or more of all symbol lookups [1]. -// The dynamic linker uses the hash table only when a symbol is not -// filtered out by a bloom filter. -// -// [1] Ulrich Drepper (2011), "How To Write Shared Libraries" (Ver. 4.1.2), -// p.9, https://www.akkadia.org/drepper/dsohowto.pdf -void GnuHashTableSection::writeBloomFilter(uint8_t *buf) { - unsigned c = config->is64 ? 64 : 32; + // Write the 2-bit bloom filter. + const unsigned c = config->is64 ? 64 : 32; for (const Entry &sym : symbols) { // When C = 64, we choose a word with bits [6:...] and set 1 to two bits in // the word using bits [0:5] and [26:31]. @@ -2404,9 +2391,9 @@ void GnuHashTableSection::writeBloomFilter(uint8_t *buf) { val |= uint64_t(1) << ((sym.hash >> Shift2) % c); writeUint(buf + i * config->wordsize, val); } -} + buf += config->wordsize * maskWords; -void GnuHashTableSection::writeHashTable(uint8_t *buf) { + // Write the hash table. uint32_t *buckets = reinterpret_cast(buf); uint32_t oldBucket = -1; uint32_t *values = buckets + nBuckets; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 2bc9b5bf9c31..3d2e73071d09 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -675,9 +675,6 @@ private: // See the comment in writeBloomFilter. enum { Shift2 = 26 }; - void writeBloomFilter(uint8_t *buf); - void writeHashTable(uint8_t *buf); - struct Entry { Symbol *sym; size_t strTabOffset;