diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2397,13 +2397,6 @@ } } -static uint32_t hashGnu(StringRef name) { - uint32_t h = 5381; - for (uint8_t c : name) - h = (h << 5) + h + c; - return h; -} - // Add symbols to this symbol hash table. Note that this function // destructively sort a given vector -- which is needed because // GNU-style hash table places some sorting requirements. diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -1223,6 +1223,16 @@ return h; } +/// This function returns the hash value for a symbol in the .dynsym section +/// for the GNU hash table. The implementation is defined in the GNU hash ABI. +/// REF : https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c#l222 +inline uint32_t hashGnu(StringRef Name) { + uint32_t H = 5381; + for (uint8_t C : Name) + H = (H << 5) + H + C; + return H; +} + } // end namespace object } // end namespace llvm