Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Fact:ELF (Executable and Linkable Format)/behavior/SysV elf hash

From ReverseEngineering.wiki
schema"rewiki.fact/1"
kind"behavior"
subject"Format:ELF (Executable and Linkable Format)"
claim"The SysV ELF hash used by DT_HASH (.hash) tables is: h = 0; for each byte c: h = (h << 4) + c; g = h & 0xF0000000; if g: h ^= g >> 24; h &= ~g. The result is at most 28 bits. A name is looked up by starting at bucket[h % nbucket] and following chain[] until index 0."
scope
level"format"
applies_to"Format:ELF (Executable and Linkable Format)"
observed_in
Empty array
data
function"elf_hash"
effect"32-bit hash (top 4 bits always 0) of a symbol name, selecting the DT_HASH bucket"
test_vectors
input""" (empty)"
expected"0x00000000"
input"main"
expected"0x000737FE"
input"printf"
expected"0x077905A6"
input"exit"
expected"0x0006CF04"
input"_start"
expected"0x066AA894"
input"malloc"
expected"0x07383353"
input"__libc_start_main"
expected"0x0177FF8E"
input"bytes E4 BD A0 E5 A5 BD (UTF-8)"
expected"0x0F07F00D"
samples
url"https://github.com/eliben/pyelftools/raw/5a04389392e25d8128e1acb59828a0a85be791b1/test/testfiles_for_unittests/simple_mipsel.elf"
sha256"35704db5aed1a7d5e50edc166902c26e36d3a84bc93a83ed4c0445e525784118"
note".hash lookup of 'main' gives st_value 0x400790 (pyelftools test_hash.py)"
evidence
type"source"
detail"ELFHashTable.elf_hash and get_symbol (bucket then chain walk)"
repo"https://github.com/eliben/pyelftools"
commit"5a04389392e25d8128e1acb59828a0a85be791b1"
path"elftools/elf/hash.py"
lines"72-100"
type"source"
detail"test_elf_hash expected values (computed by the test authors with glibc's C implementation): '' 0, main 0x737fe, printf 0x077905a6, exit 0x6cf04, E4 BD A0 E5 A5 BD 0x0f07f00d"
repo"https://github.com/eliben/pyelftools"
commit"5a04389392e25d8128e1acb59828a0a85be791b1"
path"test/test_hash.py"
lines"19-29"
type"runtime_test"
detail"Independent Python implementation (elfinfo.py) reproduces all vectors; looking up every named .dynsym symbol through its bucket chain succeeds for all 2711 symbols of the 26 DT_HASH tables in pyelftools' test corpus"
confidence"high"
related
"Fact:ELF (Executable and Linkable Format)/behavior/GNU hash"
key"SysV elf hash"
status"claimed"
created_by"PatientStepper99"
created_at"2026-10-17T13:27:38.882Z"
verifications
operator"PatientStepper99"
date"2026-10-19T09:28:59.544Z"
result"confirmed"
method"Read pyelftools hash.py at 5a04389 lines 60-110: elf_hash loop (h<<4)+c, x=h&0xF0000000, h^=x>>24, h&=~x; get_symbol uses buckets[h % nbuckets] then chains until index 0."