Class: Elf::SymbolTable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mithril/elf.rb

Instance Method Summary collapse

Constructor Details

#initializeSymbolTable

Returns a new instance of SymbolTable.



136
137
138
139
140
# File 'lib/mithril/elf.rb', line 136

def initialize
  @all_symbols = []
  @named_symbols = {}
  @versioned_symbols = {}
end

Instance Method Details

#<<(symbol) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/mithril/elf.rb', line 144

def <<(symbol)
  @all_symbols << symbol
  unless symbol.hidden
    name = symbol.name
    version = symbol.gnu_version
    @versioned_symbols[version] ||= {}
    if(@versioned_symbols[version].include? name)
      #TODO: emit some form of warning!
      #raise RuntimeError.new "Symbol #{name} version #{version} not unique"
    else
      @versioned_symbols[version][name] = symbol
    end
    @named_symbols[name] ||= []
    @named_symbols[name] << symbol
  end
end

#[](name) ⇒ Object



186
187
188
# File 'lib/mithril/elf.rb', line 186

def [](name)
  lookup(name)
end

#each(&block) ⇒ Object



141
142
143
# File 'lib/mithril/elf.rb', line 141

def each(&block)
  @all_symbols.each(&block)
end

#include?(name, version = nil) ⇒ Boolean

Returns:

  • (Boolean)


179
180
181
182
183
184
185
# File 'lib/mithril/elf.rb', line 179

def include?(name,version=nil)
  if version.nil?
    @named_symbols.include? name
  else
    @versioned_symbols[version].include? name
  end
end

#lookup(name, version = nil) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/mithril/elf.rb', line 161

def lookup(name,version=nil)
  if(version.nil?)
    @named_symbols[name].andand {|x|
      if(x.length > 1)
        x = x.select{|i| i.gnu_version != :local and i.bind != STB::STB_LOCAL}
        if(x.length > 1)
          raise RuntimeError.new("Multiple definitions of symbol #{name}")
        end
      end
      x.first
    }
  else
    @versioned_symbols[version].andand{|x| x[name]}
  end
end

#lookup_all(name) ⇒ Object



176
177
178
# File 'lib/mithril/elf.rb', line 176

def lookup_all(name)
  @named_symbols[name]
end