LinkMap.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(_Link_Map_h_)
00032 #define _Link_Map_h_
00033 
00034 #include "Symtab.h"
00035 #include "Region.h"
00036 #include "Symbol.h"
00037 #include "Function.h"
00038 
00039 #include <deque>
00040 #include <map>
00041 #include <vector>
00042 using namespace std;
00043 
00044 namespace Dyninst{
00045 namespace SymtabAPI{
00046 
00047 /*
00048  * A data structure that holds all the information necessary to perform a
00049  * static link once all the relocatable files have been copied into a new data
00050  * block
00051  */
00052 class LinkMap {
00053     public:
00054         LinkMap();
00055         ~LinkMap();
00056 
00057         // A pair representing an allocation for a Region
00058         // The first Offset is the amount of padding before the Region
00059         // The second Offset is the offset of the location in the allocatedData
00060         typedef pair<Offset, Offset> AllocPair;
00061 
00062         // prints the LinkMap (really for debugging purposes)
00063         // uses globalOffset as the location of allocatedData in the target
00064         void print(Offset globalOffset);
00065         void printAll(ostream &os, Offset globalOffset);
00066         void printBySymtab(ostream &os, vector<Symtab *> &symtabs, Offset globalOffset);
00067         void printRegions(ostream &os, deque<Region *> &regions, Offset globalOffset);
00068         void printRegion(ostream &os, Region *region, Offset globalOffset);
00069         void printRegionFromInfo(ostream &os, Region *region, Offset regionOffset, Offset padding);
00070         
00071         friend ostream & operator<<(ostream &os, LinkMap &lm);
00072 
00073         // Data Members
00074         // all other members describe this block of data
00075         char *allocatedData; 
00076         Offset allocatedSize;
00077 
00078         // map of Regions placed in allocatedData
00079         map<Region *, AllocPair> regionAllocs;
00080 
00081         // Keep track of the dynamically allocated COMMON symbol Region
00082         Region *commonStorage;
00083 
00084         // new Region info
00085         // Offset -> offset in allocatedData
00086         // Size -> size of Region
00087         // Regions -> existing Regions which make up this Region
00088 
00089         // new bss Region info
00090         Offset bssRegionOffset;
00091         Offset bssSize;
00092         Offset bssRegionAlign;
00093         deque<Region *> bssRegions;
00094 
00095         // new data Region info
00096         Offset dataRegionOffset;
00097         Offset dataSize;
00098         Offset dataRegionAlign;
00099         deque<Region *> dataRegions;
00100         
00101     // Stub code region
00102     Offset stubRegionOffset;
00103     Offset stubSize;
00104     std::map<Symbol *, Offset> stubMap;
00105 
00106         // new code Region info
00107         Offset codeRegionOffset;
00108         Offset codeSize;
00109         Offset codeRegionAlign;
00110         deque<Region *> codeRegions;
00111         
00112         // new TLS Region info
00113         Offset tlsRegionOffset;
00114         Offset tlsSize;
00115         Offset tlsRegionAlign;
00116         deque<Region *> tlsRegions;
00117         vector<Symbol *> tlsSymbols;
00118 
00119         // new GOT Region info
00120         Offset gotRegionOffset;
00121         Offset gotSize;
00122         Offset gotRegionAlign;
00123          vector<pair<Symbol *, Offset> >gotSymbolTable;
00124         map <Symbol *, Offset> gotSymbols;
00125         deque<Region *> gotRegions;
00126 
00127         Symtab *ctorDtorHandler;
00128 
00129         // new constructor Region info
00130         Offset ctorRegionOffset;
00131         Offset ctorSize;
00132         Offset ctorRegionAlign;
00133         Region *originalCtorRegion;
00134         vector<Region *> newCtorRegions;
00135 
00136         // new destructor Region info
00137         Offset dtorRegionOffset;
00138         Offset dtorSize;
00139         Offset dtorRegionAlign;
00140         Region *originalDtorRegion;
00141         vector<Region *> newDtorRegions;
00142 
00143         // Keep track of changes made to symbols and relocations
00144         vector< pair<Symbol *, Offset> > origSymbols;
00145         vector< pair<relocationEntry *, Symbol *> > origRels;
00146 
00147     // GNU extension: indirect functions and IRELATIV relocations
00148     // We basically create mini-PLT entries for load-time 
00149     // decisions of which function to call
00150     Offset pltRegionOffset;
00151     Offset pltSize;
00152     Offset pltRegionAlign;
00153     // First Offset: offset of the PLT stub. 
00154     // Second Offset: offset of the GOT entry referenced by the stub. 
00155     std::map<Symbol *, std::pair<Offset, Offset> > pltEntries;
00156     std::map<Symbol *, Offset> pltEntriesInGOT;
00157 
00158     // GNU extension: create a new rel section
00159     Offset relRegionOffset;
00160     Offset relSize;
00161     Offset relRegionAlign;
00162     // With a GOT-equivalent
00163     Offset relGotRegionOffset;
00164     Offset relGotSize;
00165     Offset relGotRegionAlign;
00166 };
00167 
00168 } // SymtabAPI
00169 } // Dyninst
00170 
00171 #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