aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2013-03-25 16:02:10 +0000
committerShankar Easwaran <shankare@codeaurora.org>2013-03-25 16:02:10 +0000
commit11987c4719749d6d053cc848e3ebb28579393f51 (patch)
tree9de5b13d400dd0e362d53e4a14c31895927c7e4c
parent6a19f7b9de706f6ce895580a8e55996f3f9162e7 (diff)
[ELF] add elf_hash function to compute the hash value of a symbol in the dynamic symbol table
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177872 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/ELF.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h
index 36e35f5748..9c2c7a64d5 100644
--- a/include/llvm/Object/ELF.h
+++ b/include/llvm/Object/ELF.h
@@ -2704,6 +2704,21 @@ static inline error_code GetELFSymbolVersion(const ObjectFile *Obj,
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;
+}
+
}
}