[llvm] r177872 - [ELF] add elf_hash function to compute the hash value of a symbol in the dynamic symbol table
Shankar Easwaran
shankare at codeaurora.org
Mon Mar 25 09:02:10 PDT 2013
Author: shankare
Date: Mon Mar 25 11:02:10 2013
New Revision: 177872
URL: http://llvm.org/viewvc/llvm-project?rev=177872&view=rev
Log:
[ELF] add elf_hash function to compute the hash value of a symbol in the dynamic symbol table
Modified:
llvm/trunk/include/llvm/Object/ELF.h
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=177872&r1=177871&r2=177872&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Mar 25 11:02:10 2013
@@ -2704,6 +2704,21 @@ static inline error_code GetELFSymbolVer
llvm_unreachable("Object passed to GetELFSymbolVersion() is not ELF");
}
+/// This function returns the hash value for a symbol in the .dynsym section
+/// Name of the API remains consistent as specified in the libelf
+/// REF : http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+static inline unsigned elf_hash(StringRef &symbolName) {
+ unsigned h = 0, g;
+ for (unsigned i = 0; i < symbolName.size(); i++) {
+ h = (h << 4) + symbolName[i];
+ g = h & 0xf0000000L;
+ if (g != 0)
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return h;
+}
+
}
}
More information about the llvm-commits
mailing list