[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

elf_hash Subroutine


Compute hash value


cc [flag...] file... -lelf [library]...
#include <libelf.h>


unsigned long elf_hash(const char * name);


elf_hash computes a hash value, given a null terminated string, name. The returned hash value, h, can be used as a bucket index, typically after computing h mod x to ensure appropriate bounds.

Hash tables may be built on one machine and used on another because elf_hash uses unsigned arithmetic to avoid possible differences in various machines' signed arithmetic. Although name is shown as char* above, elf_hash treats it as unsigned char* to avoid sign extension differences. Using char* eliminates type conflicts with expressions such as elf_hash("name").

ELF files' symbol hash tables are computed using this function [see the elf_getdata and elf32_xlatetof subroutines]. The hash value returned is guaranteed not to be the bit pattern of all ones (~0UL).

Related Information

The elf_getdata (elf_getdata, elf_newdata, elf_rawdata Subroutine) subroutine, elf32_xlatetof (elf32_xlatetof, elf32_xlatetom, elf64_xlatetof, elf64_xlatetom Subroutine) subroutine.

Introduction to ELF Subroutines.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]