elf_hash.c revision 164190
137535Sdes/*- 2135546Sdes * Copyright (c) 2006 Joseph Koshy 337535Sdes * All rights reserved. 437535Sdes * 537535Sdes * Redistribution and use in source and binary forms, with or without 637535Sdes * modification, are permitted provided that the following conditions 737535Sdes * are met: 837535Sdes * 1. Redistributions of source code must retain the above copyright 937535Sdes * notice, this list of conditions and the following disclaimer. 1037535Sdes * 2. Redistributions in binary form must reproduce the above copyright 1137535Sdes * notice, this list of conditions and the following disclaimer in the 1237535Sdes * documentation and/or other materials provided with the distribution. 1337535Sdes * 1437535Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1563012Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1637535Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1737535Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1837535Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1937535Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2037535Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2137535Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2237535Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2337535Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2437535Sdes * SUCH DAMAGE. 2537535Sdes */ 2637535Sdes 2737535Sdes#include <sys/cdefs.h> 2837535Sdes__FBSDID("$FreeBSD: head/lib/libelf/elf_hash.c 164190 2006-11-11 17:16:35Z jkoshy $"); 2984203Sdillon 3084203Sdillon#include <libelf.h> 3184203Sdillon 3263236Sdes/* 3363236Sdes * This elf_hash function is defined by the System V ABI. It must be 3463236Sdes * kept compatible with "src/libexec/rtld-elf/rtld.c". 3563236Sdes */ 3663236Sdes 3763236Sdesunsigned long 3863236Sdeself_hash(const char *name) 3963236Sdes{ 4063236Sdes unsigned long h, t; 4163236Sdes const unsigned char *s; 4263236Sdes 4363236Sdes s = (const unsigned char *) name; 4463236Sdes h = t = 0; 4563236Sdes 4663236Sdes for (; *s != '\0'; h = h & ~t) { 4763236Sdes h = (h << 4) + *s++; 4863236Sdes t = h & 0xF0000000UL; 4990267Sdes if (t) 5063236Sdes h ^= t >> 24; 5163236Sdes } 5263236Sdes 5363236Sdes return (h); 5463236Sdes} 5563236Sdes