hash.c revision 1.1.6.2 1 1.1.6.2 sborrill /* $NetBSD: hash.c,v 1.1.6.2 2023/08/11 12:13:10 sborrill Exp $ */
2 1.1.6.2 sborrill
3 1.1.6.2 sborrill /*
4 1.1.6.2 sborrill * Copyright 1996 John D. Polstra.
5 1.1.6.2 sborrill * Copyright 1996 Matt Thomas <matt (at) 3am-software.com>
6 1.1.6.2 sborrill * Copyright 2002 Charles M. Hannum <root (at) ihack.net>
7 1.1.6.2 sborrill * All rights reserved.
8 1.1.6.2 sborrill *
9 1.1.6.2 sborrill * Redistribution and use in source and binary forms, with or without
10 1.1.6.2 sborrill * modification, are permitted provided that the following conditions
11 1.1.6.2 sborrill * are met:
12 1.1.6.2 sborrill * 1. Redistributions of source code must retain the above copyright
13 1.1.6.2 sborrill * notice, this list of conditions and the following disclaimer.
14 1.1.6.2 sborrill * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.6.2 sborrill * notice, this list of conditions and the following disclaimer in the
16 1.1.6.2 sborrill * documentation and/or other materials provided with the distribution.
17 1.1.6.2 sborrill * 3. All advertising materials mentioning features or use of this software
18 1.1.6.2 sborrill * must display the following acknowledgement:
19 1.1.6.2 sborrill * This product includes software developed by John Polstra.
20 1.1.6.2 sborrill * 4. The name of the author may not be used to endorse or promote products
21 1.1.6.2 sborrill * derived from this software without specific prior written permission.
22 1.1.6.2 sborrill *
23 1.1.6.2 sborrill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1.6.2 sborrill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1.6.2 sborrill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1.6.2 sborrill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1.6.2 sborrill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1.6.2 sborrill * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1.6.2 sborrill * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1.6.2 sborrill * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1.6.2 sborrill * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1.6.2 sborrill * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1.6.2 sborrill */
34 1.1.6.2 sborrill
35 1.1.6.2 sborrill /*
36 1.1.6.2 sborrill * Dynamic linker for ELF.
37 1.1.6.2 sborrill *
38 1.1.6.2 sborrill * John Polstra <jdp (at) polstra.com>.
39 1.1.6.2 sborrill */
40 1.1.6.2 sborrill
41 1.1.6.2 sborrill #include <sys/cdefs.h>
42 1.1.6.2 sborrill #ifndef lint
43 1.1.6.2 sborrill __RCSID("$NetBSD: hash.c,v 1.1.6.2 2023/08/11 12:13:10 sborrill Exp $");
44 1.1.6.2 sborrill #endif /* not lint */
45 1.1.6.2 sborrill
46 1.1.6.2 sborrill #include <stdint.h>
47 1.1.6.2 sborrill
48 1.1.6.2 sborrill #include "hash.h"
49 1.1.6.2 sborrill
50 1.1.6.2 sborrill /*
51 1.1.6.2 sborrill * SysV hash function for symbol table lookup. It is a slightly optimized
52 1.1.6.2 sborrill * version of the hash specified by the System V ABI.
53 1.1.6.2 sborrill */
54 1.1.6.2 sborrill Elf32_Word
55 1.1.6.2 sborrill _rtld_elf_hash(const char *name)
56 1.1.6.2 sborrill {
57 1.1.6.2 sborrill const unsigned char *p = (const unsigned char *) name;
58 1.1.6.2 sborrill Elf32_Word h = 0;
59 1.1.6.2 sborrill
60 1.1.6.2 sborrill while (__predict_true(*p != '\0')) {
61 1.1.6.2 sborrill h = (h << 4) + *p++;
62 1.1.6.2 sborrill h ^= (h >> 24) & 0xf0;
63 1.1.6.2 sborrill }
64 1.1.6.2 sborrill return (h & 0x0fffffff);
65 1.1.6.2 sborrill }
66