ld: add the hash function
authorAlan Cox <alan@linux.intel.com>
Mon, 30 Oct 2017 17:40:58 +0000 (17:40 +0000)
committerAlan Cox <alan@linux.intel.com>
Mon, 30 Oct 2017 17:40:58 +0000 (17:40 +0000)
Applications/MWC/cmd/asz80/ld.c
Applications/MWC/cmd/asz80/ld.h

index 51751b1..0fdc7ea 100644 (file)
@@ -127,8 +127,13 @@ struct symbol *find_symbol(const char *name, int hash)
 
 static uint8_t hash_symbol(const char *name)
 {
-       /* TODO */
-       return 0;
+       int hash = 0;
+       uint8_t n = 16;
+
+       do {
+               hash += *name++;
+       } while (--n);
+       return (hash&(NHASH-1));
 }
 
 /* Check if a symbol name is known but undefined. We use this to decide
index 27b2dfc..b91a9fb 100644 (file)
@@ -23,5 +23,5 @@ struct object {
     off_t off;         /* For libraries */
 };
 
-#define NHASH  64
+#define NHASH  64      /* Must be a power of 2 */