emitElf-64.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #if !defined(_emit_Elf_64_h_)
00032 #define _emit_Elf_64_h_
00033 
00034 #include "Object.h"
00035 #include <vector>
00036 using namespace std;
00037 
00038 namespace Dyninst{
00039 namespace SymtabAPI{
00040 
00041 class emitElf64{
00042   public:
00043     emitElf64(Elf_X *oldElfHandle_, bool isStripped_ = false, Object *obj_ = NULL, void (*)(const char *) = log_msg);
00044     ~emitElf64() {
00045         if( linkedStaticData ) delete linkedStaticData;
00046     }
00047     bool createSymbolTables(Symtab *obj, vector<Symbol *>&allSymbols);
00048     bool driver(Symtab *obj, std::string fName);
00049  
00050   private:
00051     Elf_X *oldElfHandle;
00052     Elf *newElf;
00053     Elf *oldElf;
00054     
00055     //New Section & Program Headers
00056     Elf64_Ehdr *newEhdr;
00057     Elf64_Ehdr *oldEhdr;
00058     
00059     Elf64_Phdr *newPhdr;
00060     Elf64_Phdr *oldPhdr;
00061     Offset phdr_offset;
00062 
00063     //important data sections in the
00064     //new Elf that need updated
00065     Elf_Data *textData;
00066     Elf_Data *symStrData;
00067     Elf_Data *dynStrData;
00068     char *olddynStrData;
00069     unsigned olddynStrSize;
00070     Elf_Data *symTabData;
00071     Elf_Data *hashData;
00072     Elf_Data *dynsymData;
00073     Elf_Data *dynData;
00074     Elf_Data *rodata;
00075     Elf_Data *dataData;
00076     
00077     Elf64_Shdr *textSh;
00078     Elf64_Shdr *rodataSh;
00079     
00080     Elf_Scn *phdrs_scn;
00081 
00082     std::vector<Region *>nonLoadableSecs;
00083     std::vector<Region *> newSecs;
00084     std::map<unsigned, std::vector<Elf64_Dyn *> > dynamicSecData;
00085     std::vector<std::string> DT_NEEDEDEntries;
00086     std::vector<std::pair<long, long> > new_dynamic_entries;    
00087     std::vector<std::string> unversionedNeededEntries;
00088 
00089     // Symbol version table data
00090     std::map<std::string, std::map<std::string, unsigned> >verneedEntries;    //verneed entries
00091     std::map<std::string, unsigned> verdefEntries;                            //verdef entries
00092     std::map<unsigned, std::vector<std::string> > verdauxEntries;
00093     std::map<std::string, unsigned> versionNames;
00094     std::vector<Elf64_Half> versionSymTable;
00095     int curVersionNum, verneednum, verdefnum;
00096 
00097     // Needed when adding a new segment
00098     Elf64_Off newSegmentStart;
00099     Elf64_Shdr *firstNewLoadSec;// initialize to NULL
00100  
00101     //text & data segment ends
00102     Elf64_Off dataSegEnd, textSegEnd;
00103      Elf64_Off dynSegOff, dynSegAddr, phdrSegOff, phdrSegAddr;
00104     unsigned dynSegSize;
00105 
00106     //Section Names for all sections
00107     vector<std::string> secNames;
00108     unsigned secNameIndex;
00109     Offset currEndOffset;
00110     Address currEndAddress;
00111 
00112     // Pointer to all relocatable code and data allocated during a static link,
00113     // to be deleted after written out
00114     char *linkedStaticData;
00115 
00116     //flags
00117     // Expand NOBITS sections within the object file to their size
00118     bool BSSExpandFlag;
00119     bool movePHdrsFirst;
00120     bool createNewPhdr;
00121     bool replaceNOTE;
00122     unsigned loadSecTotalSize; 
00123 
00124     bool isStripped;
00125     int library_adjust;
00126     Object *object;
00127 
00128     void (*err_func_)(const char*);
00129 
00130     bool createElfSymbol(Symbol *symbol, unsigned strIndex, vector<Elf64_Sym *> &symbols, bool dynSymFlag = false);
00131     void findSegmentEnds();
00132     void renameSection(const std::string &oldStr, const std::string &newStr, bool renameAll=true);
00133     void fixPhdrs(unsigned &);
00134     void createNewPhdrRegion(dyn_hash_map<std::string, unsigned> &newNameIndexMapping);
00135     bool addSectionHeaderTable(Elf64_Shdr *shdr);
00136     bool createNonLoadableSections(Elf64_Shdr *& shdr);
00137     bool createLoadableSections( Symtab * obj,
00138              Elf64_Shdr* &shdr, unsigned &extraAlignSize,
00139                        dyn_hash_map<std::string, unsigned>& newIndexMapping, 
00140                        unsigned &sectionNumber);
00141     void createRelocationSections(Symtab *obj, std::vector<relocationEntry> &relocation_table, bool isDynRelocs, dyn_hash_map<std::string, unsigned long> &dynSymNameMapping);
00142 
00143     void updateSymbols(Elf_Data* symtabData,Elf_Data* strData, unsigned long loadSecsSize);
00144 
00145     bool hasRewrittenTLS;
00146     bool TLSExists;
00147     Elf64_Shdr *newTLSData;
00148 
00149     void updateDynamic(unsigned tag, Elf64_Addr val);
00150     void createSymbolVersions(Symtab *obj, Elf64_Half *&symVers, char*&verneedSecData, unsigned &verneedSecSize, char
00151 *&verdefSecData, unsigned &verdefSecSize, unsigned &dynSymbolNamesLength, std::vector<std::string> &dynStrs);
00152     void createHashSection(Symtab *obj, Elf64_Word *&hashsecData, unsigned &hashsecSize, std::vector<Symbol *>&dynSymbols);
00153     void createDynamicSection(void *dynData, unsigned size, Elf64_Dyn *&dynsecData, unsigned &dynsecSize, unsigned &dynSymbolNamesLength, std::vector<std::string> &dynStrs);
00154 
00155     void addDTNeeded(std::string s);
00156 
00157     void log_elferror(void (*err_func)(const char *), const char* msg);
00158     bool hasPHdrSectionBug();
00159     bool cannotRelocatePhdrs();
00160 };
00161 
00162 } // namespace SymtabAPI
00163 } // namespace Dyninst
00164 
00165 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1