1 //===- LDSection.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/LDSection.h"
10 
11 #include "mcld/Support/GCFactory.h"
12 
13 #include <llvm/Support/ManagedStatic.h>
14 
15 namespace mcld {
16 
17 typedef GCFactory<LDSection, MCLD_SECTIONS_PER_INPUT> SectionFactory;
18 
19 static llvm::ManagedStatic<SectionFactory> g_SectFactory;
20 
21 //===----------------------------------------------------------------------===//
22 // LDSection
23 //===----------------------------------------------------------------------===//
LDSection()24 LDSection::LDSection()
25     : m_Name(),
26       m_Kind(LDFileFormat::Ignore),
27       m_Type(0x0),
28       m_Flag(0x0),
29       m_Size(0),
30       m_Offset(~uint64_t(0)),
31       m_Addr(0x0),
32       m_Align(0),
33       m_Info(0),
34       m_pLink(NULL),
35       m_Index(0) {
36   m_Data.sect_data = NULL;
37 }
38 
LDSection(const std::string & pName,LDFileFormat::Kind pKind,uint32_t pType,uint32_t pFlag,uint64_t pSize,uint64_t pAddr)39 LDSection::LDSection(const std::string& pName,
40                      LDFileFormat::Kind pKind,
41                      uint32_t pType,
42                      uint32_t pFlag,
43                      uint64_t pSize,
44                      uint64_t pAddr)
45     : m_Name(pName),
46       m_Kind(pKind),
47       m_Type(pType),
48       m_Flag(pFlag),
49       m_Size(pSize),
50       m_Offset(~uint64_t(0)),
51       m_Addr(pAddr),
52       m_Align(0),
53       m_Info(0),
54       m_pLink(NULL),
55       m_Index(0) {
56   m_Data.sect_data = NULL;
57 }
58 
~LDSection()59 LDSection::~LDSection() {
60 }
61 
hasOffset() const62 bool LDSection::hasOffset() const {
63   return (m_Offset != ~uint64_t(0));
64 }
65 
Create(const std::string & pName,LDFileFormat::Kind pKind,uint32_t pType,uint32_t pFlag,uint64_t pSize,uint64_t pAddr)66 LDSection* LDSection::Create(const std::string& pName,
67                              LDFileFormat::Kind pKind,
68                              uint32_t pType,
69                              uint32_t pFlag,
70                              uint64_t pSize,
71                              uint64_t pAddr) {
72   LDSection* result = g_SectFactory->allocate();
73   new (result) LDSection(pName, pKind, pType, pFlag, pSize, pAddr);
74   return result;
75 }
76 
Destroy(LDSection * & pSection)77 void LDSection::Destroy(LDSection*& pSection) {
78   g_SectFactory->destroy(pSection);
79   g_SectFactory->deallocate(pSection);
80   pSection = NULL;
81 }
82 
Clear()83 void LDSection::Clear() {
84   g_SectFactory->clear();
85 }
86 
hasSectionData() const87 bool LDSection::hasSectionData() const {
88   assert(LDFileFormat::Relocation != kind() && LDFileFormat::EhFrame != kind());
89   return (m_Data.sect_data != NULL);
90 }
91 
hasRelocData() const92 bool LDSection::hasRelocData() const {
93   assert(LDFileFormat::Relocation == kind());
94   return (m_Data.reloc_data != NULL);
95 }
96 
hasEhFrame() const97 bool LDSection::hasEhFrame() const {
98   assert(LDFileFormat::EhFrame == kind());
99   return (m_Data.eh_frame != NULL);
100 }
101 
hasDebugString() const102 bool LDSection::hasDebugString() const {
103   assert(LDFileFormat::DebugString == kind());
104   return (NULL != m_Data.debug_string);
105 }
106 
107 }  // namespace mcld
108