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