Home | History | Annotate | Download | only in LD
      1 //===- RelocData.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/LD/RelocData.h>
     10 #include <mcld/Support/GCFactory.h>
     11 
     12 #include <llvm/Support/ManagedStatic.h>
     13 
     14 using namespace mcld;
     15 
     16 typedef GCFactory<RelocData, MCLD_SECTIONS_PER_INPUT> RelocDataFactory;
     17 
     18 static llvm::ManagedStatic<RelocDataFactory> g_RelocDataFactory;
     19 
     20 //===----------------------------------------------------------------------===//
     21 // RelocData
     22 //===----------------------------------------------------------------------===//
     23 RelocData::RelocData()
     24   : m_pSection(NULL) {
     25 }
     26 
     27 RelocData::RelocData(LDSection &pSection)
     28   : m_pSection(&pSection) {
     29 }
     30 
     31 RelocData* RelocData::Create(LDSection& pSection)
     32 {
     33   RelocData* result = g_RelocDataFactory->allocate();
     34   new (result) RelocData(pSection);
     35   return result;
     36 }
     37 
     38 void RelocData::Destroy(RelocData*& pSection)
     39 {
     40   pSection->~RelocData();
     41   g_RelocDataFactory->deallocate(pSection);
     42   pSection = NULL;
     43 }
     44 
     45 void RelocData::Clear()
     46 {
     47   g_RelocDataFactory->clear();
     48 }
     49 
     50 RelocData& RelocData::append(Relocation& pRelocation)
     51 {
     52   m_Relocations.push_back(&pRelocation);
     53   return *this;
     54 }
     55 
     56 Relocation& RelocData::remove(Relocation& pRelocation)
     57 {
     58   iterator iter(pRelocation);
     59   Relocation* rel = m_Relocations.remove(iter);
     60   return *rel;
     61 }
     62