elf_hash.c revision 4484
14484Sbinkertn@umich.edu/*- 24484Sbinkertn@umich.edu * Copyright (c) 2006 Joseph Koshy 34484Sbinkertn@umich.edu * All rights reserved. 44484Sbinkertn@umich.edu * 54484Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64484Sbinkertn@umich.edu * modification, are permitted provided that the following conditions 74484Sbinkertn@umich.edu * are met: 84484Sbinkertn@umich.edu * 1. Redistributions of source code must retain the above copyright 94484Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer. 104484Sbinkertn@umich.edu * 2. Redistributions in binary form must reproduce the above copyright 114484Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 124484Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution. 134484Sbinkertn@umich.edu * 144484Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 154484Sbinkertn@umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 164484Sbinkertn@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 174484Sbinkertn@umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 184484Sbinkertn@umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 194484Sbinkertn@umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 204484Sbinkertn@umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 214484Sbinkertn@umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 224484Sbinkertn@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 234484Sbinkertn@umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 244484Sbinkertn@umich.edu * SUCH DAMAGE. 254484Sbinkertn@umich.edu */ 264484Sbinkertn@umich.edu 274484Sbinkertn@umich.edu 284484Sbinkertn@umich.edu#include "libelf.h" 294484Sbinkertn@umich.edu 304484Sbinkertn@umich.edu/* 314484Sbinkertn@umich.edu * This elf_hash function is defined by the System V ABI. It must be 324484Sbinkertn@umich.edu * kept compatible with "src/libexec/rtld-elf/rtld.c". 334484Sbinkertn@umich.edu */ 344484Sbinkertn@umich.edu 354484Sbinkertn@umich.eduunsigned long 364484Sbinkertn@umich.eduelf_hash(const char *name) 374484Sbinkertn@umich.edu{ 384484Sbinkertn@umich.edu unsigned long h, t; 394484Sbinkertn@umich.edu const unsigned char *s; 404484Sbinkertn@umich.edu 414484Sbinkertn@umich.edu s = (const unsigned char *) name; 424484Sbinkertn@umich.edu h = t = 0; 434484Sbinkertn@umich.edu 444484Sbinkertn@umich.edu for (; *s != '\0'; h = h & ~t) { 454484Sbinkertn@umich.edu h = (h << 4) + *s++; 464484Sbinkertn@umich.edu t = h & 0xF0000000UL; 474484Sbinkertn@umich.edu if (t) 484484Sbinkertn@umich.edu h ^= t >> 24; 494484Sbinkertn@umich.edu } 504484Sbinkertn@umich.edu 514484Sbinkertn@umich.edu return (h); 524484Sbinkertn@umich.edu} 53