X86GOT.cpp revision affc150dc44fab1911775a49636d0ce85333b634
1//===- impl.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 "X86GOT.h" 10#include <mcld/LD/LDFileFormat.h> 11#include <mcld/Support/MsgHandling.h> 12#include <new> 13 14namespace { 15 const size_t X86GOTEntrySize = 4; 16} 17 18using namespace mcld; 19 20//===----------------------------------------------------------------------===// 21// X86GOT 22X86GOT::X86GOT(LDSection& pSection, llvm::MCSectionData& pSectionData) 23 : GOT(pSection, pSectionData, X86GOTEntrySize), 24 m_GOTIterator(), m_fIsVisit(false) 25{ 26} 27 28X86GOT::~X86GOT() 29{ 30} 31 32void X86GOT::reserveEntry(size_t pNum) 33{ 34 GOTEntry* Entry = 0; 35 36 for (size_t i = 0; i < pNum; i++) { 37 Entry = new (std::nothrow) GOTEntry(0, X86GOTEntrySize, 38 &m_SectionData); 39 40 if (!Entry) 41 fatal(diag::fail_allocate_memory) << "GOTEntry"; 42 43 m_Section.setSize(m_Section.size() + X86GOTEntrySize); 44 } 45} 46 47 48GOTEntry* X86GOT::getEntry(const ResolveInfo& pInfo, bool& pExist) 49{ 50 // first time visit this function, set m_GOTIterator 51 if(!m_fIsVisit) { 52 assert( !m_SectionData.getFragmentList().empty() && 53 "DynRelSection contains no entries."); 54 m_GOTIterator = m_SectionData.getFragmentList().begin(); 55 m_fIsVisit = true; 56 } 57 58 59 GOTEntry *&Entry = m_GOTMap[&pInfo]; 60 pExist = 1; 61 62 if (!Entry) { 63 pExist = 0; 64 assert(m_GOTIterator != m_SectionData.getFragmentList().end() 65 && "The number of GOT Entries and ResolveInfo doesn't match!"); 66 Entry = llvm::cast<GOTEntry>(&(*m_GOTIterator)); 67 ++m_GOTIterator; 68 } 69 return Entry; 70} 71 72X86GOT::iterator X86GOT::begin() 73{ 74 return m_SectionData.getFragmentList().begin(); 75} 76 77X86GOT::const_iterator X86GOT::begin() const 78{ 79 return m_SectionData.getFragmentList().begin(); 80} 81 82X86GOT::iterator X86GOT::end() 83{ 84 return m_SectionData.getFragmentList().end(); 85} 86 87X86GOT::const_iterator X86GOT::end() const 88{ 89 return m_SectionData.getFragmentList().end(); 90} 91 92