summaryrefslogtreecommitdiffstats
path: root/tools/apriori/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/apriori/hash.c')
-rw-r--r--tools/apriori/hash.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/apriori/hash.c b/tools/apriori/hash.c
new file mode 100644
index 0000000..9f1a614
--- /dev/null
+++ b/tools/apriori/hash.c
@@ -0,0 +1,27 @@
+#include <common.h>
+#include <debug.h>
+#include <libelf.h>
+#include <hash.h>
+#include <string.h>
+
+int hash_lookup(Elf *elf,
+ Elf_Data *hash,
+ Elf_Data *symtab,
+ Elf_Data *symstr,
+ const char *symname) {
+ Elf32_Word *hash_data = (Elf32_Word *)hash->d_buf;
+ Elf32_Word index;
+ Elf32_Word nbuckets = *hash_data++;
+ Elf32_Word *buckets = ++hash_data;
+ Elf32_Word *chains = hash_data + nbuckets;
+
+ index = buckets[elf_hash(symname) % nbuckets];
+ while (index != STN_UNDEF &&
+ strcmp((char *)symstr->d_buf +
+ ((Elf32_Sym *)symtab->d_buf)[index].st_name,
+ symname)) {
+ index = chains[index];
+ }
+
+ return index;
+}