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 using 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 //===----------------------------------------------------------------------===// 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 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 59 LDSection::~LDSection() 60 { 61 } 62 63 bool LDSection::hasOffset() const 64 { 65 return (m_Offset != ~uint64_t(0)); 66 } 67 68 LDSection* LDSection::Create(const std::string& pName, 69 LDFileFormat::Kind pKind, 70 uint32_t pType, 71 uint32_t pFlag, 72 uint64_t pSize, 73 uint64_t pAddr) 74 { 75 LDSection* result = g_SectFactory->allocate(); 76 new (result) LDSection(pName, pKind, pType, pFlag, pSize, pAddr); 77 return result; 78 } 79 80 void LDSection::Destroy(LDSection*& pSection) 81 { 82 g_SectFactory->destroy(pSection); 83 g_SectFactory->deallocate(pSection); 84 pSection = NULL; 85 } 86 87 void LDSection::Clear() 88 { 89 g_SectFactory->clear(); 90 } 91 92 bool LDSection::hasSectionData() const 93 { 94 assert(LDFileFormat::Relocation != kind() && LDFileFormat::EhFrame != kind()); 95 return (NULL != m_Data.sect_data); 96 } 97 98 bool LDSection::hasRelocData() const 99 { 100 assert(LDFileFormat::Relocation == kind()); 101 return (NULL != m_Data.reloc_data); 102 } 103 104 bool LDSection::hasEhFrame() const 105 { 106 assert(LDFileFormat::EhFrame == kind()); 107 return (NULL != m_Data.eh_frame); 108 } 109 110