staticRewrite.C

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 #include <stdio.h>
00032 #include <stdlib.h>
00033 
00034 #include "Symtab.h"
00035 #include "Archive.h"
00036 
00037 using namespace Dyninst;
00038 using namespace Dyninst::SymtabAPI;
00039 
00040 
00041 /* findDotOs - finds the list of .o files from archive 'arf' which
00042  * when added satisfy all the symbol references.
00043  *
00044  * We start with two different sets of symbols defined, undefined set
00045  * of symbols and a set of .o's that we need. Initially all the symbols
00046  * defined in the static executable fall under defined set and undefined fall
00047  * under the undefined set. We iterate over all the undefined symbols and try to find
00048  * the member in the archive which has the definition and add it to the list of .o's.
00049  * All the undefined symbols in this .o are added to undefined set and defined symbols
00050  * are added to the defined set. This process goes on until we do not have any undefined symbols.
00051  * Otherwise we return an error
00052  */
00053 bool findDotOs(Symtab *obj, std::vector<Archive *>arfs, vector<Symtab *>&members){
00054     vector<Symbol *> undefSyms;
00055 
00056     //Initialize undefSyms with all the undefined members in the static executable
00057     obj->getAllUndefinedSymbols(undefSyms);
00058 
00059     while(undefSyms.size() != 0){
00060         //get the first undefined symbol
00061         Symbol *sym = undefSyms[0];
00062         undefSyms.erase(undefSyms.begin());
00063         Symtab *tab; // Symtab object for member that contains the definition
00064         vector<Symbol *> foundsyms;
00065         //first check if the symbol is already defined in the static executable
00066         if(obj->findSymbolByType(foundsyms, sym->getName(), Symbol::ST_UNKNOWN, true))
00067             continue;
00068         //check all archives starting from the beginning
00069         for(unsigned i=0;i<arfs.size();i++){
00070             if(arfs[i]->findMemberWithDefinition(tab, sym->getName())){
00071                 members.push_back(tab);
00072                 vector<Symbol *>undefs;
00073                 if(tab->getAllUndefinedSymbols(undefs))
00074                     undefSyms.insert(undefSyms.end(), undefs.begin(), undefs.end());
00075                 continue;
00076             }
00077         }
00078         //reached if there are undefined symbols that are not defined in any of the archives
00079         return false;
00080     }
00081     return true;
00082 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1