Dyninst::SymtabAPI::emitElf Class Reference

#include <emitElf.h>

Public Member Functions

 emitElf (Elf_X *oldElfHandle_, bool isStripped_=false, Object *obj_=NULL, void(*)(const char *)=log_msg)
 ~emitElf ()
bool createSymbolTables (Symtab *obj, vector< Symbol * > &allSymbols)
bool driver (Symtab *obj, std::string fName)

Private Member Functions

bool createElfSymbol (Symbol *symbol, unsigned strIndex, vector< Elf32_Sym * > &symbols, bool dynSymFlag=false)
void findSegmentEnds ()
void renameSection (const std::string &oldStr, const std::string &newStr, bool renameAll=true)
void fixPhdrs (unsigned &)
void createNewPhdrRegion (dyn_hash_map< std::string, unsigned > &newNameIndexMapping)
bool addSectionHeaderTable (Elf32_Shdr *shdr)
bool createNonLoadableSections (Elf32_Shdr *&shdr)
bool createLoadableSections (Symtab *obj, Elf32_Shdr *&shdr, unsigned &extraAlignSize, dyn_hash_map< std::string, unsigned > &newIndexMapping, unsigned &sectionNumber)
void createRelocationSections (Symtab *obj, std::vector< relocationEntry > &relocation_table, bool isDynRelocs, dyn_hash_map< std::string, unsigned > &dynSymNameMapping)
void updateSymbols (Elf_Data *symtabData, Elf_Data *strData, unsigned long loadSecsSize)
void updateDynamic (unsigned tag, Elf32_Addr val)
void createSymbolVersions (Symtab *obj, Elf32_Half *&symVers, char *&verneedSecData, unsigned &verneedSecSize, char *&verdefSecData, unsigned &verdefSecSize, unsigned &dynSymbolNamesLength, std::vector< std::string > &dynStrs)
void createHashSection (Symtab *obj, Elf32_Word *&hashsecData, unsigned &hashsecSize, std::vector< Symbol * > &dynSymbols)
void createDynamicSection (void *dynData, unsigned size, Elf32_Dyn *&dynsecData, unsigned &dynsecSize, unsigned &dynSymbolNamesLength, std::vector< std::string > &dynStrs)
void addDTNeeded (std::string s)
void log_elferror (void(*err_func)(const char *), const char *msg)
bool hasPHdrSectionBug ()
bool cannotRelocatePhdrs ()

Private Attributes

Elf_XoldElfHandle
Elf * newElf
Elf * oldElf
Elf32_Ehdr * newEhdr
Elf32_Ehdr * oldEhdr
Elf32_Phdr * newPhdr
Elf32_Phdr * oldPhdr
Offset phdr_offset
Elf_Data * textData
Elf_Data * symStrData
Elf_Data * dynStrData
char * olddynStrData
unsigned olddynStrSize
Elf_Data * symTabData
Elf_Data * hashData
Elf_Data * dynsymData
Elf_Data * dynData
Elf_Data * rodata
Elf_Data * dataData
Elf32_Shdr * textSh
Elf32_Shdr * rodataSh
Elf_Scn * phdrs_scn
std::vector< Region * > nonLoadableSecs
std::vector< Region * > newSecs
std::map< unsigned,
std::vector< Elf32_Dyn * > > 
dynamicSecData
std::vector< std::string > DT_NEEDEDEntries
std::vector< std::pair< long,
long > > 
new_dynamic_entries
std::vector< std::string > unversionedNeededEntries
std::map< std::string,
std::map< std::string,
unsigned > > 
verneedEntries
std::map< std::string, unsigned > verdefEntries
std::map< unsigned,
std::vector< std::string > > 
verdauxEntries
std::map< std::string, unsigned > versionNames
std::vector< Elf32_Half > versionSymTable
int curVersionNum
int verneednum
int verdefnum
Elf32_Off newSegmentStart
Elf32_Shdr * firstNewLoadSec
Elf32_Off dataSegEnd
Elf32_Off textSegEnd
Elf32_Off dynSegOff
Elf32_Off dynSegAddr
Elf32_Off phdrSegOff
Elf32_Off phdrSegAddr
unsigned dynSegSize
vector< std::string > secNames
unsigned secNameIndex
Offset currEndOffset
Address currEndAddress
char * linkedStaticData
bool BSSExpandFlag
bool movePHdrsFirst
bool createNewPhdr
bool replaceNOTE
unsigned loadSecTotalSize
bool isStripped
int library_adjust
Objectobject
void(* err_func_ )(const char *)
bool hasRewrittenTLS
bool TLSExists
Elf32_Shdr * newTLSData

Detailed Description

Definition at line 42 of file emitElf.h.


Constructor & Destructor Documentation

emitElf::emitElf ( Elf_X oldElfHandle_,
bool  isStripped_ = false,
Object obj_ = NULL,
void(*)(const char *)  err_func = log_msg 
)
Dyninst::SymtabAPI::emitElf::~emitElf (  )  [inline]

Definition at line 45 of file emitElf.h.

References linkedStaticData.


Member Function Documentation

void Dyninst::SymtabAPI::emitElf::addDTNeeded ( std::string  s  )  [private]

Referenced by createSymbolTables().

bool emitElf::addSectionHeaderTable ( Elf32_Shdr *  shdr  )  [private]
bool emitElf::cannotRelocatePhdrs (  )  [private]

Definition at line 139 of file emitElf.C.

Referenced by emitElf().

void emitElf::createDynamicSection ( void *  dynData,
unsigned  size,
Elf32_Dyn *&  dynsecData,
unsigned &  dynsecSize,
unsigned &  dynSymbolNamesLength,
std::vector< std::string > &  dynStrs 
) [private]

List every dynamic entry that references an address and isn't already updated here. library_adjust will be a page size if we're dealing with a library without a fixed load address. We'll be shifting the addresses of that library by a page.

Definition at line 2529 of file emitElf.C.

References DT_GNU_CONFLICT, DT_NEEDEDEntries, dynamicSecData, library_adjust, new_dynamic_entries, and olddynStrData.

Referenced by createSymbolTables().

bool emitElf::createElfSymbol ( Symbol symbol,
unsigned  strIndex,
vector< Elf32_Sym * > &  symbols,
bool  dynSymFlag = false 
) [private]
void Dyninst::SymtabAPI::emitElf::createHashSection ( Symtab obj,
Elf32_Word *&  hashsecData,
unsigned &  hashsecSize,
std::vector< Symbol * > &  dynSymbols 
) [private]

Referenced by createSymbolTables().

bool emitElf::createLoadableSections ( Symtab obj,
Elf32_Shdr *&  shdr,
unsigned &  extraAlignSize,
dyn_hash_map< std::string, unsigned > &  newIndexMapping,
unsigned &  sectionNumber 
) [private]
void emitElf::createNewPhdrRegion ( dyn_hash_map< std::string, unsigned > &  newNameIndexMapping  )  [private]
bool emitElf::createNonLoadableSections ( Elf32_Shdr *&  shdr  )  [private]
void emitElf::createRelocationSections ( Symtab obj,
std::vector< relocationEntry > &  relocation_table,
bool  isDynRelocs,
dyn_hash_map< std::string, unsigned > &  dynSymNameMapping 
) [private]
bool emitElf::createSymbolTables ( Symtab obj,
vector< Symbol * > &  allSymbols 
)

Definition at line 1814 of file emitElf.C.

References addDTNeeded(), Dyninst::SymtabAPI::Symtab::addRegion(), createDynamicSection(), createElfSymbol(), createHashSection(), createRelocationSections(), createSymbolVersions(), Dyninst::SymtabAPI::Object::deps_, Dyninst::SymtabAPI::Emit_Error, err_func_, errMsg, Dyninst::SymtabAPI::Symtab::findRegion(), Dyninst::SymtabAPI::Symtab::getAddressWidth(), Dyninst::SymtabAPI::Symtab::getAllNewRegions(), Dyninst::SymtabAPI::Region::getDiskSize(), Dyninst::SymtabAPI::Object::getDynRelocs(), Dyninst::SymtabAPI::Symtab::getObject(), Dyninst::SymtabAPI::Object::getPLTRelocs(), Dyninst::SymtabAPI::Region::getPtrToRawData(), Dyninst::SymtabAPI::Object::getRelPLTAddr(), Dyninst::SymtabAPI::Object::getRelType(), Dyninst::SymtabAPI::Object::getTagRegionMapping(), Dyninst::SymtabAPI::Object::hasReldyn(), hasRewrittenTLS, Dyninst::SymtabAPI::Symtab::isStaticBinary(), isStripped, linkedStaticData, log_elferror(), Dyninst::SymtabAPI::Symbol::magicEmitElfSymbol(), Dyninst::SymtabAPI::Object::new_dynamic_entries, new_dynamic_entries, newSecs, olddynStrData, olddynStrSize, Dyninst::SymtabAPI::Object::prereq_libs, Dyninst::SymtabAPI::emitElfStatic::printStaticLinkError(), Dyninst::SymtabAPI::Region::RT_DYNAMIC, Dyninst::SymtabAPI::Region::RT_HASH, Dyninst::SymtabAPI::Region::RT_REL, Dyninst::SymtabAPI::Region::RT_RELA, Dyninst::SymtabAPI::Region::RT_STRTAB, Dyninst::SymtabAPI::Region::RT_SYMTAB, Dyninst::SymtabAPI::Region::RT_SYMVERDEF, Dyninst::SymtabAPI::Region::RT_SYMVERNEEDED, Dyninst::SymtabAPI::Region::RT_SYMVERSIONS, Dyninst::SymtabAPI::Region::setPtrToRawData(), setSymtabError(), symtab_log_perror(), Dyninst::SymtabAPI::emitElfUtils::updateHeapVariables(), and versionSymTable.

Referenced by Dyninst::SymtabAPI::Object::emitDriver().

void Dyninst::SymtabAPI::emitElf::createSymbolVersions ( Symtab obj,
Elf32_Half *&  symVers,
char *&  verneedSecData,
unsigned &  verneedSecSize,
char *&  verdefSecData,
unsigned &  verdefSecSize,
unsigned &  dynSymbolNamesLength,
std::vector< std::string > &  dynStrs 
) [private]

Referenced by createSymbolTables().

bool Dyninst::SymtabAPI::emitElf::driver ( Symtab obj,
std::string  fName 
)
void emitElf::findSegmentEnds (  )  [private]

Definition at line 457 of file emitElf.C.

References dataSegEnd, oldEhdr, oldElf, and TLSExists.

void emitElf::fixPhdrs ( unsigned &  extraAlignSize  )  [private]
bool emitElf::hasPHdrSectionBug (  )  [private]

Definition at line 130 of file emitElf.C.

References libelfso1Flag, libelfso1version_major, libelfso1version_minor, and movePHdrsFirst.

Referenced by fixPhdrs().

void emitElf::log_elferror ( void(*)(const char *)  err_func,
const char *  msg 
) [private]
void emitElf::renameSection ( const std::string &  oldStr,
const std::string &  newStr,
bool  renameAll = true 
) [private]

Definition at line 479 of file emitElf.C.

References secNames.

void emitElf::updateDynamic ( unsigned  tag,
Elf32_Addr  val 
) [private]

Definition at line 1176 of file emitElf.C.

References DT_GNU_HASH, dynamicSecData, FILE__, rewrite_printf(), verdefnum, and verneednum.

Referenced by createLoadableSections().

void emitElf::updateSymbols ( Elf_Data *  symtabData,
Elf_Data *  strData,
unsigned long  loadSecsSize 
) [private]

Definition at line 1213 of file emitElf.C.

References newSegmentStart.


Field Documentation

Definition at line 118 of file emitElf.h.

Referenced by emitElf(), and fixPhdrs().

Definition at line 120 of file emitElf.h.

Referenced by createLoadableSections(), createNewPhdrRegion(), emitElf(), and fixPhdrs().

Definition at line 110 of file emitElf.h.

Referenced by createLoadableSections(), createNewPhdrRegion(), and fixPhdrs().

Definition at line 95 of file emitElf.h.

Referenced by createElfSymbol(), and emitElf().

Definition at line 75 of file emitElf.h.

Definition at line 102 of file emitElf.h.

Referenced by findSegmentEnds().

std::vector<std::string> Dyninst::SymtabAPI::emitElf::DT_NEEDEDEntries [private]

Definition at line 85 of file emitElf.h.

Referenced by createDynamicSection().

std::map<unsigned, std::vector<Elf32_Dyn *> > Dyninst::SymtabAPI::emitElf::dynamicSecData [private]

Definition at line 84 of file emitElf.h.

Referenced by createDynamicSection(), and updateDynamic().

Definition at line 73 of file emitElf.h.

Definition at line 103 of file emitElf.h.

Referenced by createLoadableSections(), and fixPhdrs().

Definition at line 103 of file emitElf.h.

Referenced by createLoadableSections(), and fixPhdrs().

Definition at line 104 of file emitElf.h.

Referenced by createLoadableSections(), and fixPhdrs().

Definition at line 67 of file emitElf.h.

Referenced by createLoadableSections(), and emitElf().

Definition at line 72 of file emitElf.h.

Referenced by createLoadableSections(), and emitElf().

void(* Dyninst::SymtabAPI::emitElf::err_func_)(const char *) [private]

Definition at line 99 of file emitElf.h.

Referenced by createLoadableSections(), emitElf(), and fixPhdrs().

Definition at line 71 of file emitElf.h.

Referenced by emitElf().

Definition at line 145 of file emitElf.h.

Referenced by createSymbolTables(), emitElf(), and fixPhdrs().

Definition at line 124 of file emitElf.h.

Referenced by createSymbolTables().

Definition at line 114 of file emitElf.h.

Referenced by createSymbolTables(), emitElf(), and ~emitElf().

Definition at line 122 of file emitElf.h.

Referenced by createLoadableSections(), createNewPhdrRegion(), and fixPhdrs().

Definition at line 119 of file emitElf.h.

Referenced by createNewPhdrRegion(), emitElf(), fixPhdrs(), and hasPHdrSectionBug().

std::vector<std::pair<long, long> > Dyninst::SymtabAPI::emitElf::new_dynamic_entries [private]

Definition at line 86 of file emitElf.h.

Referenced by createDynamicSection(), and createSymbolTables().

Elf32_Ehdr* Dyninst::SymtabAPI::emitElf::newEhdr [private]

Definition at line 56 of file emitElf.h.

Referenced by createNewPhdrRegion(), and fixPhdrs().

Elf32_Phdr* Dyninst::SymtabAPI::emitElf::newPhdr [private]

Definition at line 59 of file emitElf.h.

Referenced by fixPhdrs().

std::vector<Region *> Dyninst::SymtabAPI::emitElf::newSecs [private]

Definition at line 83 of file emitElf.h.

Referenced by createLoadableSections(), createRelocationSections(), and createSymbolTables().

Definition at line 98 of file emitElf.h.

Referenced by createLoadableSections(), fixPhdrs(), and updateSymbols().

Definition at line 147 of file emitElf.h.

Referenced by createLoadableSections(), emitElf(), and fixPhdrs().

Definition at line 82 of file emitElf.h.

Referenced by createLoadableSections(), and createNonLoadableSections().

Definition at line 126 of file emitElf.h.

Definition at line 68 of file emitElf.h.

Referenced by createDynamicSection(), and createSymbolTables().

Definition at line 69 of file emitElf.h.

Referenced by createSymbolTables().

Elf32_Ehdr* Dyninst::SymtabAPI::emitElf::oldEhdr [private]

Definition at line 57 of file emitElf.h.

Referenced by createNewPhdrRegion(), findSegmentEnds(), and fixPhdrs().

Definition at line 53 of file emitElf.h.

Referenced by emitElf(), and findSegmentEnds().

Definition at line 51 of file emitElf.h.

Referenced by emitElf().

Elf32_Phdr* Dyninst::SymtabAPI::emitElf::oldPhdr [private]

Definition at line 60 of file emitElf.h.

Referenced by fixPhdrs().

Definition at line 61 of file emitElf.h.

Referenced by createNewPhdrRegion().

Definition at line 80 of file emitElf.h.

Referenced by createNewPhdrRegion(), and fixPhdrs().

Definition at line 103 of file emitElf.h.

Referenced by createNewPhdrRegion(), and fixPhdrs().

Definition at line 103 of file emitElf.h.

Referenced by createNewPhdrRegion().

Definition at line 121 of file emitElf.h.

Referenced by createLoadableSections(), emitElf(), and fixPhdrs().

Definition at line 74 of file emitElf.h.

Referenced by emitElf().

Definition at line 78 of file emitElf.h.

vector<std::string> Dyninst::SymtabAPI::emitElf::secNames [private]

Definition at line 66 of file emitElf.h.

Referenced by emitElf().

Definition at line 70 of file emitElf.h.

Referenced by emitElf().

Definition at line 65 of file emitElf.h.

Referenced by emitElf().

Definition at line 102 of file emitElf.h.

Elf32_Shdr* Dyninst::SymtabAPI::emitElf::textSh [private]

Definition at line 77 of file emitElf.h.

Definition at line 146 of file emitElf.h.

Referenced by emitElf(), findSegmentEnds(), and fixPhdrs().

std::vector<std::string> Dyninst::SymtabAPI::emitElf::unversionedNeededEntries [private]

Definition at line 87 of file emitElf.h.

Referenced by createElfSymbol().

std::map<unsigned, std::vector<std::string> > Dyninst::SymtabAPI::emitElf::verdauxEntries [private]

Definition at line 92 of file emitElf.h.

Referenced by createElfSymbol().

std::map<std::string, unsigned> Dyninst::SymtabAPI::emitElf::verdefEntries [private]

Definition at line 91 of file emitElf.h.

Referenced by createElfSymbol().

Definition at line 95 of file emitElf.h.

Referenced by createLoadableSections(), and updateDynamic().

std::map<std::string, std::map<std::string, unsigned> > Dyninst::SymtabAPI::emitElf::verneedEntries [private]

Definition at line 90 of file emitElf.h.

Referenced by createElfSymbol().

Definition at line 95 of file emitElf.h.

Referenced by createLoadableSections(), and updateDynamic().

std::map<std::string, unsigned> Dyninst::SymtabAPI::emitElf::versionNames [private]

Definition at line 93 of file emitElf.h.

Referenced by createElfSymbol().

std::vector<Elf32_Half> Dyninst::SymtabAPI::emitElf::versionSymTable [private]

Definition at line 94 of file emitElf.h.

Referenced by createElfSymbol(), and createSymbolTables().


The documentation for this class was generated from the following files:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1