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)
 
bool hasPreallocated () const
 
void eraseByElf (Elf *pParent)
 
uintptr_t EXPORTED_PUBLIC lookup (const HashedStringView &name, Elf *pElf, Policy policy=LocalFirst, Binding *pBinding=0)
 
uintptr_t lookupOwned (const HashedStringView &name, Elf *owner)
 

Private Types

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

Private Member Functions

SymbolTable & operator= (const SymbolTable &)
 
SharedPointer< Symbol > doInsert (const String &name, Binding binding, Elf *pParent, uintptr_t value)
 
void insertShared (const String &name, SharedPointer< Symbol > &symbol)
 
symbolTree_t * getOrInsertTree (Elf *, Binding table=Local)
 

Private Attributes

parentedSymbolTree_t m_LocalSymbols
 
parentedSymbolTree_t m_GlobalSymbols
 
parentedSymbolTree_t m_WeakSymbols
 
Elf * m_pOriginatingElf
 
Mutex m_Lock
 
bool m_bPreallocated
 

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 Typedef Documentation

◆ parentedSymbolTree_t

Definition at line 140 of file SymbolTable.h.

◆ symbolTree_t

Definition at line 139 of file SymbolTable.h.

Member Enumeration Documentation

◆ Binding

Binding types, to define how symbols interact.

Definition at line 46 of file SymbolTable.h.

◆ Policy

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 50 of file SymbolTable.h.

Constructor & Destructor Documentation

◆ SymbolTable() [1/2]

SymbolTable::SymbolTable ( Elf *  pElf)

Class constructor - creates an empty table.

Definition at line 26 of file SymbolTable.cc.

◆ ~SymbolTable()

SymbolTable::~SymbolTable ( )

Destructor - destroys all information.

Definition at line 33 of file SymbolTable.cc.

◆ SymbolTable() [2/2]

SymbolTable::SymbolTable ( const SymbolTable &  symtab)

Copy constructor.

Member Function Documentation

◆ copyTable()

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

Copies the symbol table

Definition at line 35 of file SymbolTable.cc.

Referenced by Elf::Elf().

+ Here is the caller graph for this function:

◆ doInsert()

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

Insert doer.

Definition at line 97 of file SymbolTable.cc.

References insertShared().

Referenced by insert(), and insertMultiple().

+ Here is the caller graph for this function:

◆ eraseByElf()

void SymbolTable::eraseByElf ( Elf *  pParent)

Definition at line 111 of file SymbolTable.cc.

◆ getOrInsertTree()

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

Get or insert a Symbol tree.

Definition at line 186 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:

◆ hasPreallocated()

bool SymbolTable::hasPreallocated ( ) const

Has a preallocation already taken place on this SymbolTable?

Definition at line 92 of file SymbolTable.cc.

Referenced by Elf::preallocateSymbols().

+ Here is the caller graph for this function:

◆ insert()

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

Insert a symbol into the table.

Definition at line 45 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:

◆ insertMultiple()

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 51 of file SymbolTable.cc.

References doInsert(), and insertShared().

Referenced by Elf::allocate().

+ Here is the caller graph for this function:

◆ insertShared()

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

Insert the given shared symbol.

Definition at line 106 of file SymbolTable.cc.

References getOrInsertTree().

Referenced by doInsert(), and insertMultiple().

+ Here is the caller graph for this function:

◆ lookup()

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 120 of file SymbolTable.cc.

References Tree< K, E >::begin(), Tree< K, E >::end(), 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:

◆ lookupOwned()

uintptr_t SymbolTable::lookupOwned ( const HashedStringView &  name,
Elf *  owner 
)

Looks up only exports owned by the specified ELF, without allocating.

Definition at line 170 of file SymbolTable.cc.

Referenced by KernelElf::resolveRuntimeImport().

+ Here is the caller graph for this function:

◆ operator=()

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

Copy constructor.

Note
NOT implemented.

◆ preallocate()

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 61 of file SymbolTable.cc.

References getOrInsertTree().

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

+ Here is the caller graph for this function:

◆ preallocateAdditional()

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

Preallocate additional symbols to the existing count.

Definition at line 76 of file SymbolTable.cc.

References getOrInsertTree().

Referenced by Elf::preallocateSymbols().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_bPreallocated

bool SymbolTable::m_bPreallocated
private

Definition at line 153 of file SymbolTable.h.

◆ m_GlobalSymbols

parentedSymbolTree_t SymbolTable::m_GlobalSymbols
private

Definition at line 146 of file SymbolTable.h.

◆ m_LocalSymbols

parentedSymbolTree_t SymbolTable::m_LocalSymbols
private

Definition at line 145 of file SymbolTable.h.

◆ m_Lock

Mutex SymbolTable::m_Lock
mutableprivate

Definition at line 151 of file SymbolTable.h.

◆ m_pOriginatingElf

Elf* SymbolTable::m_pOriginatingElf
private

Definition at line 149 of file SymbolTable.h.

◆ m_WeakSymbols

parentedSymbolTree_t SymbolTable::m_WeakSymbols
private

Definition at line 147 of file SymbolTable.h.


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