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