[PATCH] D132696: [ELF] Provide the GNU hash function in libObject

Joseph Huber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 5 09:05:13 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1d19a848946: [ELF] Provide the GNU hash function in libObject (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D132696?vs=455681&id=458024#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132696/new/

https://reviews.llvm.org/D132696

Files:
  lld/ELF/SyntheticSections.cpp
  llvm/include/llvm/Object/ELF.h


Index: llvm/include/llvm/Object/ELF.h
===================================================================
--- llvm/include/llvm/Object/ELF.h
+++ 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
 
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132696.458024.patch
Type: text/x-patch
Size: 1180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220905/d0f497a3/attachment.bin>


More information about the llvm-commits mailing list