Class: ELFTools::Dynamic::HashTable::SysV

Inherits:
HashTable
  • Object
show all
Defined in:
lib/elftools/dynamic/hash_table.rb

Overview

The table DT_HASH points at, which the System V ABI defines.

A chain of it belongs to every symbol, so it is the one table that records how many there are.

Constant Summary collapse

HEADER =

The header the table starts with.

Structs::ELF_Hash

Instance Method Summary collapse

Instance Method Details

#covers_every_symbol?Boolean

Whether the table is built over every symbol rather than over a subset of them.

Two things follow where it is. How many symbols it is built over is how many there are, rather than how far it reaches. And a name it does not lead to is not one the file records, so nothing is left to search.

Returns:

  • (Boolean)

    The answer.



81
82
83
# File 'lib/elftools/dynamic/hash_table.rb', line 81

def covers_every_symbol?
  true
end

#index_of(name) {|index| ... } ⇒ Integer?

The index a name sits at.

A bucket leads to a chain of the indices whose names hash alike, so the block is what tells them apart.

Parameters:

  • name (String)

    The name.

Yield Parameters:

  • index (Integer)

    An index whose name hashes like name.

Yield Returns:

  • (Boolean)

    Whether the symbol there is the one wanted.

Returns:

  • (Integer, nil)

    The index, nil if the table does not lead to the name.



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/elftools/dynamic/hash_table.rb', line 94

def index_of(name)
  return if header.nbucket.to_i.zero?

  n = word_at(buckets + ((hash_of(name) % header.nbucket.to_i) * 4))
  # Index zero is the undefined symbol, so it ends a chain instead of
  # belonging to one.
  while n.positive? && n < num_symbols
    return n if yield(n)

    n = word_at(chain + (n * 4))
  end
end

#num_symbolsInteger

How many symbols the table is built over, which it records outright.

Returns:

  • (Integer)

    The number.



76
77
78
# File 'lib/elftools/dynamic/hash_table.rb', line 76

def num_symbols
  header.nchain.to_i
end