X86GOTPLT.cpp revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
1//===- X86GOTPLT.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 "X86GOTPLT.h" 10#include "X86PLT.h" 11 12#include <new> 13 14#include <llvm/Support/Casting.h> 15 16#include <mcld/LD/LDSection.h> 17#include <mcld/LD/LDFileFormat.h> 18#include <mcld/Support/MsgHandling.h> 19 20namespace { 21 const uint64_t X86GOTPLTEntrySize = 4; 22} 23 24namespace mcld { 25 26//===----------------------------------------------------------------------===// 27// X86GOTPLT 28//===----------------------------------------------------------------------===// 29X86GOTPLT::X86GOTPLT(LDSection& pSection) 30 : GOT(pSection, X86GOTPLTEntrySize) 31{ 32 // Create GOT0 entries 33 reserve(X86GOTPLT0Num); 34 35 // Skip GOT0 entries 36 for (size_t i = 0; i < X86GOTPLT0Num; ++i) { 37 consume(); 38 } 39} 40 41X86GOTPLT::~X86GOTPLT() 42{ 43} 44 45bool X86GOTPLT::hasGOT1() const 46{ 47 return (m_SectionData->size() > X86GOTPLT0Num); 48} 49 50void X86GOTPLT::applyGOT0(uint64_t pAddress) 51{ 52 llvm::cast<Entry> 53 (*(m_SectionData->getFragmentList().begin())).setContent(pAddress); 54} 55 56void X86GOTPLT::applyAllGOTPLT(const X86PLT& pPLT) 57{ 58 iterator it = begin(); 59 // skip GOT0 60 for (size_t i = 0; i < X86GOTPLT0Num; ++i) 61 ++it; 62 // address of corresponding plt entry 63 uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size(); 64 for (; it != end() ; ++it) { 65 llvm::cast<Entry>(*it).setContent(plt_addr + 6); 66 plt_addr += pPLT.getPLT1Size(); 67 } 68} 69 70} //end mcld namespace 71