1 //===- ELFSegmentFactory.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/ELFSegmentFactory.h> 10 11 using namespace mcld; 12 13 //========================== 14 // ELFSegmentFactory 15 16 ELFSegmentFactory::ELFSegmentFactory(size_t pNum) 17 : GCFactory<ELFSegment, 0>(pNum) 18 { 19 } 20 21 ELFSegmentFactory::~ELFSegmentFactory() 22 { 23 } 24 25 /// produce - produce an empty ELF segment information. 26 /// this function will create an ELF segment 27 /// @param pType - p_type in ELF program header 28 ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag) 29 { 30 ELFSegment* segment = allocate(); 31 new (segment) ELFSegment(pType, pFlag); 32 return segment; 33 } 34 35 ELFSegment* 36 ELFSegmentFactory::find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear) 37 { 38 iterator segment, segEnd = end(); 39 for (segment = begin(); segment != segEnd; ++segment) { 40 if ((*segment).type() == pType && 41 ((*segment).flag() & pFlagSet) == pFlagSet && 42 ((*segment).flag() & pFlagClear) == 0x0) { 43 return &(*segment); 44 } 45 } 46 return NULL; 47 } 48 49 const ELFSegment* 50 ELFSegmentFactory::find(uint32_t pType, 51 uint32_t pFlagSet, 52 uint32_t pFlagClear) const 53 { 54 const_iterator segment, segEnd = end(); 55 for (segment = begin(); segment != segEnd; ++segment) { 56 if ((*segment).type() == pType && 57 ((*segment).flag() & pFlagSet) == pFlagSet && 58 ((*segment).flag() & pFlagClear) == 0x0) { 59 return &(*segment); 60 } 61 } 62 return NULL; 63 } 64 65