The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SymbolTable Class Reference

#include <SymbolTable.h>

+ Collaboration diagram for SymbolTable:

Classes

class  Symbol
 

Public Types

enum  Binding { Local, Global, Weak }
 
enum  Policy { LocalFirst, NotOriginatingElf }
 

Public Member Functions

 SymbolTable (Elf *pElf)
 
 ~SymbolTable ()
 
 SymbolTable (const SymbolTable &symtab)
 
void copyTable (Elf *pNewElf, const SymbolTable &newSymtab)
 
void insert (const String &name, Binding binding, Elf *pParent, uintptr_t value)
 
void insertMultiple (SymbolTable *pOther, const String &name, Binding binding, Elf *pParent, uintptr_t value)
 
void preallocate (size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
 
void preallocateAdditional (size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
 
void eraseByElf (Elf *pParent)
 
uintptr_t EXPORTED_PUBLIC lookup (const HashedStringView &name, Elf *pElf, Policy policy=LocalFirst, Binding *pBinding=0)
 

Private Types

typedef HashTable< String, SharedPointer< Symbol >, HashedStringViewsymbolTree_t
 
typedef Tree< Elf *, SharedPointer< symbolTree_t > > parentedSymbolTree_t
 

Private Member Functions

SymbolTableoperator= (const SymbolTable &)
 
SharedPointer< SymboldoInsert (const String &name, Binding binding, Elf *pParent, uintptr_t value)
 
void insertShared (const String &name, SharedPointer< Symbol > &symbol)
 
symbolTree_tgetOrInsertTree (Elf *, Binding table=Local)
 

Private Attributes

parentedSymbolTree_t m_LocalSymbols
 
parentedSymbolTree_t m_GlobalSymbols
 
parentedSymbolTree_t m_WeakSymbols
 
Elfm_pOriginatingElf
 
Mutex m_Lock
 

Detailed Description

This class allows quick access to symbol information held within ELF files. The lookup operation allows multiple policies to retrieve the wanted symbol.

Note
Deletion is not implemented - the normal use case for this class is insertion and lookup. Deletion would almost never occur, and so the class is optimised solely for the first two operations.

Definition at line 43 of file SymbolTable.h.

Member Enumeration Documentation

Binding types, to define how symbols interact.

Definition at line 47 of file SymbolTable.h.

Lookup policies - given multiple definitions of a symbol, how do we determine the best response?

Enumerator
LocalFirst 

Default policy - searches for local definitions of a symbol first.

NotOriginatingElf 

Does not search the ELF given as pElf. This is used during lookups for R_COPY relocations, where one symbol must be linked to another.

Definition at line 56 of file SymbolTable.h.

Constructor & Destructor Documentation

SymbolTable::SymbolTable ( Elf pElf)

Class constructor - creates an empty table.

Definition at line 30 of file SymbolTable.cc.

SymbolTable::~SymbolTable ( )

Destructor - destroys all information.

Definition at line 36 of file SymbolTable.cc.

SymbolTable::SymbolTable ( const SymbolTable symtab)

Copy constructor.

Member Function Documentation

void SymbolTable::copyTable ( Elf pNewElf,
const SymbolTable newSymtab 
)

Copies the symbol table

Definition at line 40 of file SymbolTable.cc.

Referenced by Elf::Elf().

+ Here is the caller graph for this function:

SharedPointer< SymbolTable::Symbol > SymbolTable::doInsert ( const String name,
Binding  binding,
Elf pParent,
uintptr_t  value 
)
private

Insert doer.

Definition at line 99 of file SymbolTable.cc.

References insertShared().

Referenced by insert(), and insertMultiple().

+ Here is the caller graph for this function:

SymbolTable::symbolTree_t * SymbolTable::getOrInsertTree ( Elf p,
Binding  table = Local 
)
private

Get or insert a Symbol tree.

Definition at line 188 of file SymbolTable.cc.

References SharedPointer< T >::allocate(), Tree< K, E >::insert(), and Tree< K, E >::lookupRef().

Referenced by insertShared(), preallocate(), and preallocateAdditional().

+ Here is the caller graph for this function:

void SymbolTable::insert ( const String name,
Binding  binding,
Elf pParent,
uintptr_t  value 
)

Insert a symbol into the table.

Definition at line 51 of file SymbolTable.cc.

References doInsert().

Referenced by Elf::allocate(), KernelElf::initialise(), Elf::loadModule(), and Elf::populateSymbolTable().

+ Here is the caller graph for this function:

void SymbolTable::insertMultiple ( SymbolTable pOther,
const String name,
Binding  binding,
Elf pParent,
uintptr_t  value 
)

Insert a symbol into two SymbolTables, using the memory once.

Definition at line 59 of file SymbolTable.cc.

References doInsert(), and insertShared().

Referenced by Elf::allocate().

+ Here is the caller graph for this function:

void SymbolTable::insertShared ( const String name,
SharedPointer< Symbol > &  symbol 
)
private

Insert the given shared symbol.

Definition at line 109 of file SymbolTable.cc.

References getOrInsertTree(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::insert(), and Tree< K, E >::remove().

Referenced by doInsert(), and insertMultiple().

+ Here is the caller graph for this function:

uintptr_t SymbolTable::lookup ( const HashedStringView name,
Elf pElf,
Policy  policy = LocalFirst,
Binding pBinding = 0 
)

Looks up a symbol in the table, optionally outputting the binding value.

If the policy is set as "LocalFirst" (the default), then Local and Global definitions from pElf are given priority.

If the policy is set as "NotOriginatingElf", no symbols in pElf will ever be matched, preferring those from other ELFs. This is used for R_COPY relocations.

Returns
The value of the found symbol.

Definition at line 126 of file SymbolTable.cc.

References Tree< K, E >::begin(), Tree< K, E >::end(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), Tree< K, E >::lookupRef(), and NotOriginatingElf.

Referenced by Elf::applyRelocation(), KernelElf::globalLookupSymbol(), Elf::lookupDynamicSymbolAddress(), Elf::lookupSymbol(), and DynamicLinker::resolve().

+ Here is the caller graph for this function:

SymbolTable& SymbolTable::operator= ( const SymbolTable )
private

Copy constructor.

Note
NOT implemented.
void SymbolTable::preallocate ( size_t  numGlobal,
size_t  numWeak,
Elf localElf,
size_t  numLocal 
)

Preallocate at least the minimum space for the given symbol tables.

Definition at line 73 of file SymbolTable.cc.

References getOrInsertTree().

Referenced by KernelElf::initialise(), and Elf::preallocateSymbols().

+ Here is the caller graph for this function:

void SymbolTable::preallocateAdditional ( size_t  numGlobal,
size_t  numWeak,
Elf localElf,
size_t  numLocal 
)

Preallocate additional symbols to the existing count.

Definition at line 86 of file SymbolTable.cc.

References getOrInsertTree().

Referenced by Elf::preallocateSymbols().

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: