Home | History | Annotate | Download | only in Core
      1 //===- Module.cpp ---------------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #include <mcld/Module.h>
     10 #include <mcld/Fragment/FragmentRef.h>
     11 #include <mcld/LD/LDSection.h>
     12 #include <mcld/LD/LDSymbol.h>
     13 #include <mcld/LD/NamePool.h>
     14 #include <mcld/LD/ResolveInfo.h>
     15 #include <mcld/LD/SectionData.h>
     16 #include <mcld/LD/EhFrame.h>
     17 #include <mcld/LD/StaticResolver.h>
     18 
     19 using namespace mcld;
     20 
     21 static GCFactory<Module::AliasList, MCLD_SECTIONS_PER_INPUT> gc_aliaslist_factory;
     22 
     23 //===----------------------------------------------------------------------===//
     24 // Module
     25 //===----------------------------------------------------------------------===//
     26 Module::Module(LinkerScript& pScript)
     27   : m_Script(pScript), m_NamePool(1024) {
     28 }
     29 
     30 Module::Module(const std::string& pName, LinkerScript& pScript)
     31   : m_Name(pName), m_Script(pScript), m_NamePool(1024) {
     32 }
     33 
     34 Module::~Module()
     35 {
     36 }
     37 
     38 // Following two functions will be obsolette when we have new section merger.
     39 LDSection* Module::getSection(const std::string& pName)
     40 {
     41   iterator sect, sectEnd = end();
     42   for (sect = begin(); sect != sectEnd; ++sect) {
     43     if ((*sect)->name() == pName)
     44       return *sect;
     45   }
     46   return NULL;
     47 }
     48 
     49 const LDSection* Module::getSection(const std::string& pName) const
     50 {
     51   const_iterator sect, sectEnd = end();
     52   for (sect = begin(); sect != sectEnd; ++sect) {
     53     if ((*sect)->name() == pName)
     54       return *sect;
     55   }
     56   return NULL;
     57 }
     58 
     59 void Module::CreateAliasList(const ResolveInfo& pSym)
     60 {
     61   AliasList* result = gc_aliaslist_factory.allocate();
     62   new (result) AliasList();
     63   m_AliasLists.push_back(result);
     64   result->push_back(&pSym);
     65 }
     66 
     67 void Module::addAlias(const ResolveInfo& pAlias)
     68 {
     69   assert(0!=m_AliasLists.size());
     70   uint32_t last_pos = m_AliasLists.size()-1;
     71   m_AliasLists[last_pos]->push_back(&pAlias);
     72 }
     73 
     74 Module::AliasList* Module::getAliasList(const ResolveInfo& pSym)
     75 {
     76   std::vector<AliasList*>::iterator list_it, list_it_e=m_AliasLists.end();
     77   for (list_it=m_AliasLists.begin(); list_it!=list_it_e; ++list_it) {
     78     AliasList& list = **list_it;
     79     alias_iterator alias_it, alias_it_e=list.end();
     80     for (alias_it=list.begin(); alias_it!=alias_it_e; ++alias_it) {
     81       if ( 0==strcmp((*alias_it)->name(), pSym.name()) ) {
     82         return &list;
     83       }
     84     }
     85   }
     86   return NULL;
     87 }
     88 
     89